Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # file format version
  2. FILE_VERSION = 1
  3. LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
  4. # Makefiles suck: This macro sets a default value of $(2) for the
  5. # variable named by $(1), unless the variable has been set by
  6. # environment or command line. This is necessary for CC and AR
  7. # because make sets default values, so the simpler ?= approach
  8. # won't work as expected.
  9. define allow-override
  10. $(if $(or $(findstring environment,$(origin $(1))),\
  11. $(findstring command line,$(origin $(1)))),,\
  12. $(eval $(1) = $(2)))
  13. endef
  14. # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
  15. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  16. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  17. INSTALL = install
  18. # Use DESTDIR for installing into a different root directory.
  19. # This is useful for building a package. The program will be
  20. # installed in this directory as if it was the root directory.
  21. # Then the build tool can move it later.
  22. DESTDIR ?=
  23. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  24. prefix ?= /usr/local
  25. libdir_relative = lib
  26. libdir = $(prefix)/$(libdir_relative)
  27. bindir_relative = bin
  28. bindir = $(prefix)/$(bindir_relative)
  29. export DESTDIR DESTDIR_SQ INSTALL
  30. MAKEFLAGS += --no-print-directory
  31. include ../../scripts/Makefile.include
  32. # copy a bit from Linux kbuild
  33. ifeq ("$(origin V)", "command line")
  34. VERBOSE = $(V)
  35. endif
  36. ifndef VERBOSE
  37. VERBOSE = 0
  38. endif
  39. ifeq ($(srctree),)
  40. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  41. srctree := $(patsubst %/,%,$(dir $(srctree)))
  42. srctree := $(patsubst %/,%,$(dir $(srctree)))
  43. #$(info Determined 'srctree' to be $(srctree))
  44. endif
  45. # Shell quotes
  46. libdir_SQ = $(subst ','\'',$(libdir))
  47. bindir_SQ = $(subst ','\'',$(bindir))
  48. LIB_IN := $(OUTPUT)liblockdep-in.o
  49. BIN_FILE = lockdep
  50. LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
  51. CONFIG_INCLUDES =
  52. CONFIG_LIBS =
  53. CONFIG_FLAGS =
  54. OBJ = $@
  55. N =
  56. export Q VERBOSE
  57. INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
  58. # Set compile option CFLAGS if not set elsewhere
  59. CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
  60. CFLAGS += -fPIC
  61. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  62. ifeq ($(VERBOSE),1)
  63. Q =
  64. print_shared_lib_compile =
  65. print_install =
  66. else
  67. Q = @
  68. print_shared_lib_compile = echo ' LD '$(OBJ);
  69. print_static_lib_build = echo ' LD '$(OBJ);
  70. print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
  71. endif
  72. export srctree OUTPUT CC LD CFLAGS V
  73. build := -f $(srctree)/tools/build/Makefile.build dir=. obj
  74. do_compile_shared_library = \
  75. ($(print_shared_lib_compile) \
  76. $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so))
  77. do_build_static_lib = \
  78. ($(print_static_lib_build) \
  79. $(RM) $@; $(AR) rcs $@ $^)
  80. CMD_TARGETS = $(LIB_FILE)
  81. TARGETS = $(CMD_TARGETS)
  82. all: all_cmd
  83. all_cmd: $(CMD_TARGETS)
  84. $(LIB_IN): force
  85. $(Q)$(MAKE) $(build)=liblockdep
  86. liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
  87. $(Q)$(do_compile_shared_library)
  88. liblockdep.a: $(LIB_IN)
  89. $(Q)$(do_build_static_lib)
  90. tags: force
  91. $(RM) tags
  92. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  93. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  94. TAGS: force
  95. $(RM) TAGS
  96. find . -name '*.[ch]' | xargs etags \
  97. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  98. define do_install
  99. $(print_install) \
  100. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  101. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  102. fi; \
  103. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  104. endef
  105. install_lib: all_cmd
  106. $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
  107. $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
  108. install: install_lib
  109. clean:
  110. $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d
  111. $(RM) tags TAGS
  112. PHONY += force
  113. force:
  114. # Declare the contents of the .PHONY variable as phony. We keep that
  115. # information in a variable so we can use it in if_changed and friends.
  116. .PHONY: $(PHONY)