Makefile.in 5.9 KB

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