4 MAKEFLAGS += --no-print-directory
5 LIBLOCKDEP_VERSION=$(shell make -sC ../../.. kernelversion)
7 # Makefiles suck: This macro sets a default value of $(2) for the
8 # variable named by $(1), unless the variable has been set by
9 # environment or command line. This is necessary for CC and AR
10 # because make sets default values, so the simpler ?= approach
11 # won't work as expected.
13 $(if $(or $(findstring environment,$(origin $(1))),\
14 $(findstring command line,$(origin $(1)))),,\
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)
24 # Use DESTDIR for installing into a different root directory.
25 # This is useful for building a package. The program will be
26 # installed in this directory as if it was the root directory.
27 # Then the build tool can move it later.
29 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
33 libdir = $(prefix)/$(libdir_relative)
35 bindir = $(prefix)/$(bindir_relative)
37 export DESTDIR DESTDIR_SQ INSTALL
39 # copy a bit from Linux kbuild
41 ifeq ("$(origin V)", "command line")
48 ifeq ("$(origin O)", "command line")
53 ifneq ($(BUILD_OUTPUT),)
56 $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \
57 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
60 saved-output := $(BUILD_OUTPUT)
61 BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
62 $(if $(BUILD_OUTPUT),, \
63 $(error output directory "$(saved-output)" does not exist))
68 $(call build_output, all_cmd)
70 $(filter-out gui,$(MAKECMDGOALS)): sub-make
73 $(call build_output, $(MAKECMDGOALS))
76 # Leave processing to above invocation of make
82 # We process the rest of the Makefile if this is the final invocation of make
83 ifeq ($(skip-makefile),)
85 srctree := $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
86 objtree := $(realpath $(CURDIR))
90 export prefix libdir bindir src obj
93 libdir_SQ = $(subst ','\'',$(libdir))
94 bindir_SQ = $(subst ','\'',$(bindir))
96 LIB_FILE = liblockdep.a liblockdep.so.$(LIBLOCKDEP_VERSION)
108 INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include $(CONFIG_INCLUDES)
110 # Set compile option CFLAGS if not set elsewhere
111 CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
113 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
120 print_shared_lib_compile =
124 print_compile = echo ' CC '$(OBJ);
125 print_app_build = echo ' BUILD '$(OBJ);
126 print_fpic_compile = echo ' CC FPIC '$(OBJ);
127 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
128 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
129 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
133 ($(print_fpic_compile) \
134 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
137 ($(print_app_build) \
138 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
140 do_compile_shared_library = \
141 ($(print_shared_lib_compile) \
142 $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so))
144 do_build_static_lib = \
145 ($(print_static_lib_build) \
146 $(RM) $@; $(AR) rcs $@ $^)
151 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
154 $(obj)/%.o: $(src)/%.c
155 $(Q)$(call do_compile)
158 $(Q)$(call do_compile)
160 PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
162 ALL_OBJS = $(PEVENT_LIB_OBJS)
164 CMD_TARGETS = $(LIB_FILE)
166 TARGETS = $(CMD_TARGETS)
171 all_cmd: $(CMD_TARGETS)
173 liblockdep.so.$(LIBLOCKDEP_VERSION): $(PEVENT_LIB_OBJS)
174 $(Q)$(do_compile_shared_library)
176 liblockdep.a: $(PEVENT_LIB_OBJS)
177 $(Q)$(do_build_static_lib)
179 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c
180 $(Q)$(do_fpic_compile)
184 all_objs := $(sort $(ALL_OBJS))
185 all_deps := $(all_objs:%.o=.%.d)
187 # let .d file also depends on the source and header files
190 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
191 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
195 $(all_deps): .%.d: $(src)/%.c
196 $(Q)$(call check_deps)
198 $(all_objs) : %.o : .%.d
200 dep_includes := $(wildcard $(all_deps))
202 ifneq ($(dep_includes),)
203 include $(dep_includes)
206 ### Detect environment changes
207 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
211 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
212 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
216 find . -name '*.[ch]' | xargs etags \
217 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
221 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
222 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
224 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
228 $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
229 $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
234 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
237 endif # skip-makefile
242 # Declare the contents of the .PHONY variable as phony. We keep that
243 # information in a variable so we can use it in if_changed and friends.