Makefile.in 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ifneq ("$(wildcard /lib/modules/$(KERNELVER)/build/include/linux)","")
  9. HEADERDIR ?= /lib/modules/$(KERNELVER)/build/include
  10. else ifneq ("$(wildcard /lib/modules/$(KERNELVER)/source/include/linux)","")
  11. HEADERDIR ?= /lib/modules/$(KERNELVER)/source/include
  12. else
  13. HEADERDIR ?= ""
  14. endif
  15. PWD := $(shell pwd)
  16. EXTRA_CFLAGS += -I$(M)/.. ${PCILIB_DYNAMIC_HEADERS_INC}
  17. ifdef DUMMY_DEVICE
  18. ifneq ($(DUMMY_DEVICE), 0)
  19. EXTRA_CFLAGS += -DPCIDRIVER_DUMMY_DEVICE
  20. endif
  21. endif
  22. # Grepping in '../pcilib/build.h' is correct as we will always have this file in the releases...
  23. default:
  24. @KERNEL_GCC_STRING=`cat /proc/version | head -n 1 | cut -d " " -f 7 | tr '-' '\n' | head -n 1` ;\
  25. KERNEL_GCC_VERSION=`echo $$KERNEL_GCC_STRING | grep -oe "[0-9]\+\.[0-9.]\+" | tail -n 1` ; \
  26. echo "Detected Kernel build GCC Version: $$KERNEL_GCC_VERSION" ;\
  27. GCC_VERSION=`$(CC) --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9.]\+" | tail -n 1` ;\
  28. echo "Detected installed GCC Version: $$GCC_VERSION" ;\
  29. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION ]; then \
  30. echo "Kernel is compiled with gcc $$KERNEL_GCC_VERSION, but you are now using $$GCC_VERSION" ;\
  31. GCC_MAJOR=`echo $$KERNEL_GCC_VERSION | cut -d "." -f 1-2` ;\
  32. newCC=gcc-$$KERNEL_GCC_VERSION ;\
  33. CC=`which $$newCC 2>/dev/null` ;\
  34. if [ $$? -ne 0 ]; then \
  35. newCC=gcc-$$GCC_MAJOR ;\
  36. CC=`which $$newCC 2>/dev/null` ;\
  37. if [ $$? -ne 0 ]; then \
  38. newCC=`compgen -ac | grep -E ^gcc-4.6 | head -n 1` ;\
  39. CC=`which $$newCC 2>/dev/null` ;\
  40. if [ $$? -ne 0 ]; then \
  41. echo "No compiler of $$GCC_MAJOR series is installed" ;\
  42. exit 1 ;\
  43. fi ; \
  44. fi ;\
  45. fi ;\
  46. GCC_VERSION=`$$CC --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9]" | tail -n 1` ;\
  47. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION -a -z "$$RELAXED_GCC_CHECK" ]; then \
  48. echo "The $$GCC_VERSION of $$GCC_MAJOR series is installed" ;\
  49. exit 1 ;\
  50. fi ;\
  51. echo "Setting CC to $$newCC" ;\
  52. else \
  53. CC=$(CC) ;\
  54. fi ;\
  55. build_path=`pwd` ;\
  56. 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` ;\
  57. build_user=`whoami` ;\
  58. build_date=`date "+%Y/%m/%d %H:%M:%S"` ;\
  59. build="Built at $$build_date by $$build_user" ;\
  60. bzr=`which bzr 2>/dev/null` ;\
  61. if [ $$? -eq 0 -a -d ../.bzr ]; then \
  62. build_revision=`bzr revno` ;\
  63. build_author=`bzr log -r$$build_revision | grep committer | cut -c 12-` ;\
  64. build_branch=`bzr nick` ;\
  65. build_changes=`bzr status -SV | cut -c 5- | tr \\\n " "` ;\
  66. revision="Revision $$build_revision from $$build_branch by $$build_author at $$build_path, last modification from $$build_lastmod" ;\
  67. /bin/echo -e "#define PCIDRIVER_BUILD \"$$build\"\\n#define PCIDRIVER_REVISION \"$$revision\"\\n#define PCIDRIVER_CHANGES \"$$build_changes\"\\n" > build.h ;\
  68. else \
  69. if [ -f ../pcilib/build.h ]; then \
  70. grep "#define PCILIB_RELEASE" ../pcilib/build.h &> /dev/null ;\
  71. res=$$? ;\
  72. else \
  73. res=-1 ;\
  74. fi ;\
  75. if [ $$res -eq 0 ]; then \
  76. revision="Release \" PCILIB_RELEASE \" (r\" PCILIB_REVISION \") from \" PCILIB_REVISION_BRANCH \" by \" PCILIB_REVISION_AUTHOR \" at $$build_path, last modification from $$build_lastmod" ;\
  77. /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 ;\
  78. else \
  79. revision="Revision r\" PCILIB_REVISION \" from \" PCILIB_REVISION_BRANCH \" by \" PCILIB_REVISION_AUTHOR \" at $$build_path, last modification from $$build_lastmod" ;\
  80. /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 ;\
  81. fi ;\
  82. fi ;\
  83. $(MAKE) $(CFLAGS) -C $(KERNELDIR) M=$(PWD) CC=$$CC modules
  84. install:
  85. @mkdir -p $(INSTALLDIR)
  86. @echo "INSTALL $(INSTALLDIR)/pciDriver.ko"
  87. @install -m 755 pciDriver.ko $(INSTALLDIR)
  88. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  89. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  90. @if [ "$(HEADERDIR)" != "" ]; then \
  91. echo "INSTALL $(HEADERDIR)/linux/pcidriver.h" ;\
  92. install -m 644 pcidriver.h $(HEADERDIR)/linux/ ;\
  93. fi
  94. @echo "INSTALL /usr/include/linux/pcidriver.h"
  95. @mkdir -p /usr/include/linux
  96. @install -m 644 ioctl.h /usr/include/linux/pcidriver.h
  97. install_symvers:
  98. @mkdir -p $(INSTALLDIR)
  99. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  100. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  101. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  102. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  103. uninstall:
  104. @if [ -f $(INSTALLDIR)/pciDriver.ko ]; then \
  105. echo "UNINSTALL $(INSTALLDIR)/pciDriver.ko" ;\
  106. rm -f $(INSTALLDIR)/pciDriver.ko ;\
  107. fi
  108. @if [ -f $(MAININSTALLDIR)/pciDriver.ko ]; then \
  109. echo "UNINSTALL $(MAININSTALLDIR)/pciDriver.ko" ;\
  110. rm -f $(MAININSTALLDIR)/pciDriver.ko ;\
  111. fi
  112. @if [ -f $(INSTALLDIR)/pciDriver.symvers ]; then \
  113. echo "UNINSTALL $(INSTALLDIR)/pciDriver.symvers" ;\
  114. rm -f $(INSTALLDIR)/pciDriver.symvers ;\
  115. fi
  116. @if [ -f $(MAININSTALLDIR)/pciDriver.symvers ]; then \
  117. echo "UNINSTALL $(MAININSTALLDIR)/pciDriver.symvers" ;\
  118. rm -f $(MAININSTALLDIR)/pciDriver.symvers ;\
  119. fi
  120. @if [ -f /usr/include/linux/pcidriver.h ]; then \
  121. echo "UNINSTALL /usr/include/linux/pcidriver.h" ;\
  122. rm -rf /usr/include/linux/pcidriver.h ;\
  123. fi
  124. @if [ -d /usr/include/pciDriver/ ]; then \
  125. echo "UNINSTALL /usr/include/pciDriver/" ;\
  126. rm -rf /usr/include/pciDriver/ ;\
  127. fi
  128. @if [ "$(HEADERDIR)" != "" -a -f $(HEADERDIR)/linux/pcidriver.h ]; then \
  129. echo "UNINSTALL $(HEADERDIR)/linux/pcidriver.h" ;\
  130. rm -rf $(HEADERDIR)/linux/pcidriver.h ;\
  131. fi
  132. clean:
  133. rm -rf *.o *.ko *.mod.c .*.o.cmd .*.o.tmp .*.ko.cmd .*.o *.symvers modules.order .tmp_versions