Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. bzr=`which bzr 2>/dev/null` ;\
  51. if [ $$? -eq 0 -a -d ../.bzr ]; then \
  52. build_revision=`bzr revno` ;\
  53. build_author=`bzr log -r$$build_revision | grep committer | cut -c 12-` ;\
  54. build_branch=`bzr nick` ;\
  55. build_changes=`bzr status -SV | cut -c 5- | tr \\\n " "` ;\
  56. revision="Revision $$build_revision from $$build_branch by $$build_author at $$build_path, last modification from $$build_lastmod" ;\
  57. /bin/echo -e "#define PCIDRIVER_BUILD \"$$build\"\\n#define PCIDRIVER_REVISION \"$$revision\"\\n#define PCIDRIVER_CHANGES \"$$build_changes\"\\n" > build.h ;\
  58. else \
  59. grep "#define PCILIB_RELEASE" ../pcilib/build.h &> /dev/null ;\
  60. if [ $$? -eq 0 ]; then \
  61. revision="Release \" PCILIB_RELEASE \" (r\" PCILIB_REVISION \") from \" PCILIB_REVISION_BRANCH \" by \" PCILIB_REVISION_AUTHOR \" at $$build_path, last modification from $$build_lastmod" ;\
  62. /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 ;\
  63. else \
  64. revision="Revision r\" PCILIB_REVISION \" from \" PCILIB_REVISION_BRANCH \" by \" PCILIB_REVISION_AUTHOR \" at $$build_path, last modification from $$build_lastmod" ;\
  65. /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 ;\
  66. fi ;\
  67. fi ;\
  68. $(MAKE) $(CFLAGS) -C $(KERNELDIR) M=$(PWD) CC=$$CC modules
  69. install:
  70. @mkdir -p $(INSTALLDIR)
  71. @echo "INSTALL $(INSTALLDIR)/pciDriver.ko"
  72. @install -m 755 pciDriver.ko $(INSTALLDIR)
  73. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  74. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  75. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  76. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  77. @echo "INSTALL /usr/include/linux/pcidriver.h"
  78. @mkdir -p /usr/include/linux
  79. @install -m 644 ioctl.h /usr/include/linux/pcidriver.h
  80. install_symvers:
  81. @mkdir -p $(INSTALLDIR)
  82. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  83. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  84. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  85. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  86. uninstall:
  87. @echo "UNINSTALL $(INSTALLDIR)/pciDriver.ko"
  88. @rm -f $(INSTALLDIR)/pciDriver.ko
  89. @rm -f $(MAININSTALLDIR)/pciDriver.ko
  90. @rm -f $(INSTALLDIR)/pciDriver.symvers
  91. @rm -f $(MAININSTALLDIR)/pciDriver.symvers
  92. @echo "UNINSTALL /usr/include/linux/pcidriver.h"
  93. @rm -rf /usr/include/pciDriver/
  94. @rm -rf /usr/include/linux/pcidriver.h
  95. @echo "UNINSTALL $(HEADERDIR)/linux/pcidriver.h"
  96. @rm -rf $(HEADERDIR)/linux/pcidriver.h
  97. clean:
  98. rm -rf *.o *.ko *.mod.c .*.o.cmd .*.o.tmp .*.ko.cmd .*.o *.symvers modules.order .tmp_versions