9 MAKEFLAGS += --no-print-directory
12 # Makefiles suck: This macro sets a default value of $(2) for the
13 # variable named by $(1), unless the variable has been set by
14 # environment or command line. This is necessary for CC and AR
15 # because make sets default values, so the simpler ?= approach
16 # won't work as expected.
18 $(if $(or $(findstring environment,$(origin $(1))),\
19 $(findstring command line,$(origin $(1)))),,\
23 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
24 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
25 $(call allow-override,AR,$(CROSS_COMPILE)ar)
29 # Use DESTDIR for installing into a different root directory.
30 # This is useful for building a package. The program will be
31 # installed in this directory as if it was the root directory.
32 # Then the build tool can move it later.
34 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
38 libdir = $(prefix)/$(libdir_relative)
40 bindir = $(prefix)/$(bindir_relative)
42 export DESTDIR DESTDIR_SQ INSTALL
44 # copy a bit from Linux kbuild
46 ifeq ("$(origin V)", "command line")
53 ifeq ("$(origin O)", "command line")
58 ifneq ($(BUILD_OUTPUT),)
61 $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \
62 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
65 saved-output := $(BUILD_OUTPUT)
66 BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
67 $(if $(BUILD_OUTPUT),, \
68 $(error output directory "$(saved-output)" does not exist))
73 $(call build_output, all_cmd)
75 $(filter-out gui,$(MAKECMDGOALS)): sub-make
78 $(call build_output, $(MAKECMDGOALS))
81 # Leave processing to above invocation of make
87 # We process the rest of the Makefile if this is the final invocation of make
88 ifeq ($(skip-makefile),)
90 srctree := $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
91 objtree := $(realpath $(CURDIR))
95 export prefix libdir bindir src obj
98 libdir_SQ = $(subst ','\'',$(libdir))
99 bindir_SQ = $(subst ','\'',$(bindir))
101 LIB_FILE = liblockdep.a liblockdep.so
113 LIBLOCKDEP_VERSION = $(LL_VERSION).$(LL_PATCHLEVEL).$(LL_EXTRAVERSION)
115 INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include $(CONFIG_INCLUDES)
117 # Set compile option CFLAGS if not set elsewhere
118 CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
120 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
127 print_shared_lib_compile =
131 print_compile = echo ' CC '$(OBJ);
132 print_app_build = echo ' BUILD '$(OBJ);
133 print_fpic_compile = echo ' CC FPIC '$(OBJ);
134 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
135 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
136 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
140 ($(print_fpic_compile) \
141 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
144 ($(print_app_build) \
145 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
147 do_compile_shared_library = \
148 ($(print_shared_lib_compile) \
149 $(CC) --shared $^ -o $@ -lpthread -ldl)
151 do_build_static_lib = \
152 ($(print_static_lib_build) \
153 $(RM) $@; $(AR) rcs $@ $^)
158 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
161 $(obj)/%.o: $(src)/%.c
162 $(Q)$(call do_compile)
165 $(Q)$(call do_compile)
167 PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
169 ALL_OBJS = $(PEVENT_LIB_OBJS)
171 CMD_TARGETS = $(LIB_FILE)
173 TARGETS = $(CMD_TARGETS)
178 all_cmd: $(CMD_TARGETS)
180 liblockdep.so: $(PEVENT_LIB_OBJS)
181 $(Q)$(do_compile_shared_library)
183 liblockdep.a: $(PEVENT_LIB_OBJS)
184 $(Q)$(do_build_static_lib)
186 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c
187 $(Q)$(do_fpic_compile)
191 all_objs := $(sort $(ALL_OBJS))
192 all_deps := $(all_objs:%.o=.%.d)
194 # let .d file also depends on the source and header files
197 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
198 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
202 $(all_deps): .%.d: $(src)/%.c
203 $(Q)$(call check_deps)
205 $(all_objs) : %.o : .%.d
207 dep_includes := $(wildcard $(all_deps))
209 ifneq ($(dep_includes),)
210 include $(dep_includes)
213 ### Detect environment changes
214 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
218 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
219 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
223 find . -name '*.[ch]' | xargs etags \
224 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
228 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
229 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
231 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
235 $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
236 $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
241 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
244 endif # skip-makefile
249 # Declare the contents of the .PHONY variable as phony. We keep that
250 # information in a variable so we can use it in if_changed and friends.