Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. CONFIG_MODULE_SIG=n
  2. obj-m := pciDriver.o
  3. pciDriver-objs := base.o dev.o int.o umem.o kmem.o sysfs.o ioctl.o pcibus.o rdma.o
  4. KERNELVER ?= $(shell uname -r)
  5. KERNELDIR ?= /lib/modules/$(KERNELVER)/build
  6. INSTALLDIR ?= /lib/modules/$(KERNELVER)/extra
  7. MAININSTALLDIR ?= /lib/modules/$(KERNELVER)/kernel/extra
  8. HEADERDIR ?= /lib/modules/$(KERNELVER)/source/include
  9. PWD := $(shell pwd)
  10. EXTRA_CFLAGS += -I$(M)/..
  11. ifdef DUMMY_DEVICE
  12. ifneq ($(DUMMY_DEVICE), 0)
  13. EXTRA_CFLAGS += -DPCIDRIVER_DUMMY_DEVICE
  14. endif
  15. endif
  16. default:
  17. @KERNEL_GCC_VERSION=`cat /proc/version | head -n1 | cut -d " " -f 7` ;\
  18. GCC_VERSION=`$(CC) --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9]" | tail -n 1` ;\
  19. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION ]; then \
  20. echo "Kernel is compiled with gcc $$KERNEL_GCC_VERSION, but you are now using $$GCC_VERSION" ;\
  21. GCC_MAJOR=`echo $$KERNEL_GCC_VERSION | cut -d "." -f 1-2` ;\
  22. newCC=gcc-$$KERNEL_GCC_VERSION ;\
  23. CC=`which $$newCC 2>/dev/null` ;\
  24. if [ $$? -ne 0 ]; then \
  25. newCC=gcc-$$GCC_MAJOR ;\
  26. CC=`which $$newCC 2>/dev/null` ;\
  27. if [ $$? -ne 0 ]; then \
  28. newCC=`compgen -ac | grep -E ^gcc-4.6 | head -n 1` ;\
  29. CC=`which $$newCC 2>/dev/null` ;\
  30. if [ $$? -ne 0 ]; then \
  31. echo "No compiler of $$GCC_MAJOR series is installed" ;\
  32. exit 1 ;\
  33. fi ; \
  34. fi ;\
  35. fi ;\
  36. GCC_VERSION=`$$CC --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9]" | tail -n 1` ;\
  37. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION -a -z "$$RELAXED_GCC_CHECK" ]; then \
  38. echo "The $$GCC_VERSION of $$GCC_MAJOR series is installed" ;\
  39. exit 1 ;\
  40. fi ;\
  41. echo "Setting CC to $$newCC" ;\
  42. else \
  43. CC=$(CC) ;\
  44. fi ;\
  45. build_path=`pwd` ;\
  46. build_lastmod=`find . -type f -name '*.[ch]' -printf '%TY/%Tm/%Td %TH:%TM:%TS %p\n' | grep -E -v 'build.h|mod.c' | sort -n | tail -n 1 | cut -d ' ' -f 1-2 | cut -d '.' -f 1` ;\
  47. build_user=`whoami` ;\
  48. build_date=`date "+%Y/%m/%d %H:%M:%S"` ;\
  49. build="Built at $$build_date by $$build_user" ;\
  50. if [ -d ../.bzr ]; then \
  51. build_revision=`bzr revno` ;\
  52. build_author=`bzr log -r$$build_revision | grep committer | cut -c 12-` ;\
  53. build_branch=`bzr nick` ;\
  54. build_changes=`bzr status -SV | cut -c 5- | tr \\\n " "` ;\
  55. revision="Revision $$build_revision from $$build_branch by $$build_author at $$build_path, last modification from $$build_lastmod" ;\
  56. /bin/echo -e "#define PCIDRIVER_BUILD \"$$build\"\\n#define PCIDRIVER_REVISION \"$$revision\"\\n#define PCIDRIVER_CHANGES \"$$build_changes\"\\n" > build.h ;\
  57. else \
  58. revision="Release \" PCILIB_RELEASE \" (r\" PCILIB_REVISION \") from \" PCILIB_REVISION_BRANCH \" by \" PCILIB_REVISION_AUTHOR \" at $$build_path, last modification from $$build_lastmod" ;\
  59. /bin/echo -e "#include \"../pcilib/build.h\"\\n #define PCIDRIVER_BUILD \"$$build\"\\n#define PCIDRIVER_REVISION \"$$revision\"\\n#define PCIDRIVER_CHANGES PCILIB_REVISION_MODIFICATIONS\n" > build.h ;\
  60. fi ;\
  61. $(MAKE) $(CFLAGS) -C $(KERNELDIR) M=$(PWD) CC=$$CC modules
  62. install:
  63. @mkdir -p $(INSTALLDIR)
  64. @echo "INSTALL $(INSTALLDIR)/pciDriver.ko"
  65. @install -m 755 pciDriver.ko $(INSTALLDIR)
  66. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  67. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  68. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  69. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  70. @echo "INSTALL /usr/include/linux/pcidriver.h"
  71. @mkdir -p /usr/include/linux
  72. @install -m 644 ioctl.h /usr/include/linux/pcidriver.h
  73. install_symvers:
  74. @mkdir -p $(INSTALLDIR)
  75. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  76. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  77. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  78. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  79. uninstall:
  80. @echo "UNINSTALL $(INSTALLDIR)/pciDriver.ko"
  81. @rm -f $(INSTALLDIR)/pciDriver.ko
  82. @rm -f $(MAININSTALLDIR)/pciDriver.ko
  83. @rm -f $(INSTALLDIR)/pciDriver.symvers
  84. @rm -f $(MAININSTALLDIR)/pciDriver.symvers
  85. @echo "UNINSTALL /usr/include/linux/pcidriver.h"
  86. @rm -rf /usr/include/pciDriver/
  87. @rm -rf /usr/include/linux/pcidriver.h
  88. @echo "UNINSTALL $(HEADERDIR)/linux/pcidriver.h"
  89. @rm -rf $(HEADERDIR)/linux/pcidriver.h
  90. clean:
  91. rm -rf *.o *.ko *.mod.c .*.o.cmd .*.o.tmp .*.ko.cmd .*.o *.symvers modules.order .tmp_versions