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