Makefile 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. KERNELDIR ?= /lib/modules/$(shell uname -r)/build
  5. INSTALLDIR ?= /lib/modules/$(shell uname -r)/extra
  6. MAININSTALLDIR ?= /lib/modules/$(shell uname -r)/kernel/extra
  7. HEADERDIR ?= /lib/modules/$(shell uname -r)/source/include
  8. PWD := $(shell pwd)
  9. EXTRA_CFLAGS += -I$(M)/..
  10. ifdef DUMMY_DEVICE
  11. ifneq ($(DUMMY_DEVICE), 0)
  12. EXTRA_CFLAGS += -DPCIDRIVER_DUMMY_DEVICE
  13. endif
  14. endif
  15. default:
  16. @KERNEL_GCC_VERSION=`cat /proc/version | head -n1 | cut -d " " -f 7` ;\
  17. GCC_VERSION=`$(CC) --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9]" | tail -n 1` ;\
  18. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION ]; then \
  19. echo "Kernel is compiled with gcc $$KERNEL_GCC_VERSION, but you are now using $$GCC_VERSION" ;\
  20. GCC_MAJOR=`echo $$KERNEL_GCC_VERSION | cut -d "." -f 1-2` ;\
  21. newCC=gcc-$$GCC_MAJOR ;\
  22. CC=`which $$newCC 2>/dev/null` ;\
  23. if [ $$? -ne 0 ]; then \
  24. echo "No compiler of $$GCC_MAJOR series is installed" ;\
  25. exit 1 ;\
  26. fi ;\
  27. GCC_VERSION=`$$CC --version | head -n 1 | tr ' ' '\n' | grep -e "[0-9]\+\.[0-9]" | tail -n 1` ;\
  28. if [ $$KERNEL_GCC_VERSION != $$GCC_VERSION -a -z "$$RELAXED_GCC_CHECK" ]; then \
  29. echo "The $$GCC_VERSION of $$GCC_MAJOR series is installed" ;\
  30. exit 1 ;\
  31. fi ;\
  32. echo "Setting CC to $$newCC" ;\
  33. else \
  34. CC=$(CC) ;\
  35. fi ;\
  36. build_revision=`bzr revno` ;\
  37. build_author=`bzr log -r$$build_revision | grep committer | cut -c 12-` ;\
  38. build_path=`pwd` ;\
  39. build_branch=`bzr nick` ;\
  40. 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` ;\
  41. build_changes=`bzr status -SV | cut -c 5- | tr \\\n " "` ;\
  42. build_user=`whoami` ;\
  43. build_date=`date "+%Y/%m/%d %H:%M:%S"` ;\
  44. build="Built at $$build_date by $$build_user" ;\
  45. revision="Revision $$build_revision from $$build_branch by $$build_author at $$build_path, last modification from $$build_lastmod" ;\
  46. /bin/echo -e "#define PCIDRIVER_BUILD \"$$build\"\\n#define PCIDRIVER_REVISION \"$$revision\"\\n#define PCIDRIVER_CHANGES \"$$build_changes\"\\n" > build.h ;\
  47. $(MAKE) $(CFLAGS) -C $(KERNELDIR) M=$(PWD) CC=$$CC modules
  48. install:
  49. @mkdir -p $(INSTALLDIR)
  50. @echo "INSTALL $(INSTALLDIR)/pciDriver.ko"
  51. @install -m 755 pciDriver.ko $(INSTALLDIR)
  52. @echo "INSTALL $(INSTALLDIR)/pciDriver.symvers"
  53. @install -m 644 Module.symvers $(INSTALLDIR)/pciDriver.symvers
  54. @echo "INSTALL $(HEADERDIR)/linux/pcidriver.h"
  55. @install -m 644 pcidriver.h $(HEADERDIR)/linux/
  56. @echo "INSTALL /usr/include/linux/pcidriver.h"
  57. @mkdir -p /usr/include/linux
  58. @install -m 644 ioctl.h /usr/include/linux/pcidriver.h
  59. uninstall:
  60. @echo "UNINSTALL $(INSTALLDIR)/pciDriver.ko"
  61. @rm -f $(INSTALLDIR)/pciDriver.ko
  62. @rm -f $(MAININSTALLDIR)/pciDriver.ko
  63. @rm -f $(INSTALLDIR)/pciDriver.symvers
  64. @rm -f $(MAININSTALLDIR)/pciDriver.symvers
  65. @echo "UNINSTALL /usr/include/linux/pcidriver.h"
  66. @rm -rf /usr/include/pciDriver/
  67. @rm -rf /usr/include/linux/pcidriver.h
  68. @echo "UNINSTALL $(HEADERDIR)/linux/pcidriver.h"
  69. @rm -rf $(HEADERDIR)/linux/pcidriver.h
  70. clean:
  71. rm -rf *.o *.ko *.mod.c .*.o.cmd .*.o.tmp .*.ko.cmd .*.o *.symvers modules.order .tmp_versions