Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # liblockdep version
  2. LL_VERSION = 0
  3. LL_PATCHLEVEL = 0
  4. LL_EXTRAVERSION = 1
  5. # file format version
  6. FILE_VERSION = 1
  7. MAKEFLAGS += --no-print-directory
  8. # Makefiles suck: This macro sets a default value of $(2) for the
  9. # variable named by $(1), unless the variable has been set by
  10. # environment or command line. This is necessary for CC and AR
  11. # because make sets default values, so the simpler ?= approach
  12. # won't work as expected.
  13. define allow-override
  14. $(if $(or $(findstring environment,$(origin $(1))),\
  15. $(findstring command line,$(origin $(1)))),,\
  16. $(eval $(1) = $(2)))
  17. endef
  18. # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
  19. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  20. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  21. INSTALL = install
  22. # Use DESTDIR for installing into a different root directory.
  23. # This is useful for building a package. The program will be
  24. # installed in this directory as if it was the root directory.
  25. # Then the build tool can move it later.
  26. DESTDIR ?=
  27. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  28. prefix ?= /usr/local
  29. libdir_relative = lib
  30. libdir = $(prefix)/$(libdir_relative)
  31. bindir_relative = bin
  32. bindir = $(prefix)/$(bindir_relative)
  33. export DESTDIR DESTDIR_SQ INSTALL
  34. # copy a bit from Linux kbuild
  35. ifeq ("$(origin V)", "command line")
  36. VERBOSE = $(V)
  37. endif
  38. ifndef VERBOSE
  39. VERBOSE = 0
  40. endif
  41. ifeq ("$(origin O)", "command line")
  42. BUILD_OUTPUT := $(O)
  43. endif
  44. ifeq ($(BUILD_SRC),)
  45. ifneq ($(BUILD_OUTPUT),)
  46. define build_output
  47. $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \
  48. BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
  49. endef
  50. saved-output := $(BUILD_OUTPUT)
  51. BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
  52. $(if $(BUILD_OUTPUT),, \
  53. $(error output directory "$(saved-output)" does not exist))
  54. all: sub-make
  55. gui: force
  56. $(call build_output, all_cmd)
  57. $(filter-out gui,$(MAKECMDGOALS)): sub-make
  58. sub-make: force
  59. $(call build_output, $(MAKECMDGOALS))
  60. # Leave processing to above invocation of make
  61. skip-makefile := 1
  62. endif # BUILD_OUTPUT
  63. endif # BUILD_SRC
  64. # We process the rest of the Makefile if this is the final invocation of make
  65. ifeq ($(skip-makefile),)
  66. srctree := $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
  67. objtree := $(realpath $(CURDIR))
  68. src := $(srctree)
  69. obj := $(objtree)
  70. export prefix libdir bindir src obj
  71. # Shell quotes
  72. libdir_SQ = $(subst ','\'',$(libdir))
  73. bindir_SQ = $(subst ','\'',$(bindir))
  74. LIB_FILE = liblockdep.a liblockdep.so
  75. BIN_FILE = lockdep
  76. CONFIG_INCLUDES =
  77. CONFIG_LIBS =
  78. CONFIG_FLAGS =
  79. OBJ = $@
  80. N =
  81. export Q VERBOSE
  82. LIBLOCKDEP_VERSION = $(LL_VERSION).$(LL_PATCHLEVEL).$(LL_EXTRAVERSION)
  83. INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include $(CONFIG_INCLUDES)
  84. # Set compile option CFLAGS if not set elsewhere
  85. CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
  86. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  87. ifeq ($(VERBOSE),1)
  88. Q =
  89. print_compile =
  90. print_app_build =
  91. print_fpic_compile =
  92. print_shared_lib_compile =
  93. print_install =
  94. else
  95. Q = @
  96. print_compile = echo ' CC '$(OBJ);
  97. print_app_build = echo ' BUILD '$(OBJ);
  98. print_fpic_compile = echo ' CC FPIC '$(OBJ);
  99. print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
  100. print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
  101. print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
  102. endif
  103. do_fpic_compile = \
  104. ($(print_fpic_compile) \
  105. $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
  106. do_app_build = \
  107. ($(print_app_build) \
  108. $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
  109. do_compile_shared_library = \
  110. ($(print_shared_lib_compile) \
  111. $(CC) --shared $^ -o $@ -lpthread -ldl)
  112. do_build_static_lib = \
  113. ($(print_static_lib_build) \
  114. $(RM) $@; $(AR) rcs $@ $^)
  115. define do_compile
  116. $(print_compile) \
  117. $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
  118. endef
  119. $(obj)/%.o: $(src)/%.c
  120. $(Q)$(call do_compile)
  121. %.o: $(src)/%.c
  122. $(Q)$(call do_compile)
  123. PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
  124. ALL_OBJS = $(PEVENT_LIB_OBJS)
  125. CMD_TARGETS = $(LIB_FILE)
  126. TARGETS = $(CMD_TARGETS)
  127. all: all_cmd
  128. all_cmd: $(CMD_TARGETS)
  129. liblockdep.so: $(PEVENT_LIB_OBJS)
  130. $(Q)$(do_compile_shared_library)
  131. liblockdep.a: $(PEVENT_LIB_OBJS)
  132. $(Q)$(do_build_static_lib)
  133. $(PEVENT_LIB_OBJS): %.o: $(src)/%.c
  134. $(Q)$(do_fpic_compile)
  135. ## make deps
  136. all_objs := $(sort $(ALL_OBJS))
  137. all_deps := $(all_objs:%.o=.%.d)
  138. # let .d file also depends on the source and header files
  139. define check_deps
  140. @set -e; $(RM) $@; \
  141. $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
  142. sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  143. $(RM) $@.$$$$
  144. endef
  145. $(all_deps): .%.d: $(src)/%.c
  146. $(Q)$(call check_deps)
  147. $(all_objs) : %.o : .%.d
  148. dep_includes := $(wildcard $(all_deps))
  149. ifneq ($(dep_includes),)
  150. include $(dep_includes)
  151. endif
  152. ### Detect environment changes
  153. TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
  154. tags: force
  155. $(RM) tags
  156. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  157. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  158. TAGS: force
  159. $(RM) TAGS
  160. find . -name '*.[ch]' | xargs etags \
  161. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  162. define do_install
  163. $(print_install) \
  164. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  165. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  166. fi; \
  167. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  168. endef
  169. install_lib: all_cmd
  170. $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
  171. $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
  172. install: install_lib
  173. clean:
  174. $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
  175. $(RM) tags TAGS
  176. endif # skip-makefile
  177. PHONY += force
  178. force:
  179. # Declare the contents of the .PHONY variable as phony. We keep that
  180. # information in a variable so we can use it in if_changed and friends.
  181. .PHONY: $(PHONY)