Rev 1685 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1681 | fabio | 1 | # Copyright (c) 2007 Fabio Checconi <fabio@gandalf.sssup.it> |
2 | pj | 2 | # |
1681 | fabio | 3 | # This is a non-recursive makefile that supports a Kbuild-like syntax |
4 | # for input/output specification. |
||
5 | |||
6 | # Handle the V=0|1 option. We use both a long and a short form. In |
||
7 | # the short one we use the $(Q) variable prepended to shell commands |
||
8 | # (e.g., $(Q)mkdir) that in quiet mode expands to @, and in verbose |
||
9 | # mode expands to nothing. In the long one we have a couple of strings |
||
10 | # per command, one named quiet_cmd, the other cmd, and we always echo |
||
11 | # $(QS)cmd, so if $(QS) expands to quiet_ the first string is printed. |
||
12 | # The first string is the quiet version of the command, the second one |
||
13 | # holds the whole command. |
||
14 | ifneq ($(V),1) |
||
15 | Q:=@ |
||
16 | QS:=quiet_ |
||
17 | endif |
||
18 | |||
19 | # Handle the make -s flag: produce no output at all... |
||
20 | ifneq ($(findstring s,$(MAKEFLAGS)),) |
||
21 | Q:=@ |
||
22 | QS:=nothing_ |
||
23 | endif |
||
24 | |||
25 | # The variables used to generate the rules to build targets. Use |
||
26 | # CROSS_COMPILE to specify the prefix to be used for the toolchain. |
||
27 | ar:= $(CROSS_COMPILE)$(AR) |
||
28 | as:= $(CROSS_COMPILE)$(CC) |
||
29 | cc:= $(CROSS_COMPILE)$(CC) |
||
30 | ld:= $(CROSS_COMPILE)$(LD) |
||
31 | rm:= $(if $(RM),$(RM),rm) |
||
32 | install:= $(if $(INSTALL),$(INSTALL),install) |
||
33 | |||
34 | # As in the rules we cannot use the variables we use in the makefile, |
||
35 | # because we reassign them for every directory we visit, we just try |
||
36 | # to recover the information from the targets being built. Another |
||
37 | # way could have been to expand the variables when generating the |
||
38 | # rules, but it would have made rule generation unreadable. |
||
39 | in-local:= $$(subst $$(srctree)/,,$$<) |
||
40 | out-local:= $$(subst install-,,$$(subst $$(objtree)/,,$$@)) |
||
41 | in-objs:= $$(filter %.o,$$^) |
||
42 | |||
43 | # The rule patterns, in quiet and in verbose form. The verbose form is |
||
44 | # used also for the actual command. |
||
1685 | fabio | 45 | quiet_ar_cmd := ' AR\\t$(out-local)' |
1681 | fabio | 46 | ar_cmd := $(ar) cr $$@ $(in-objs) |
47 | |||
48 | quiet_cc_cmd := ' CC\\t$(in-local)' |
||
1685 | fabio | 49 | cc_cmd := $(cc) $$(cflags-$$(<:.c=.o)) $$(cppflags-$$(<:.c=.o))\ |
1681 | fabio | 50 | -c $$< -o $$@ |
51 | |||
52 | quiet_as_cmd := ' AS\\t$(in-local)' |
||
53 | as_cmd := $(as) $$(aflags-$$(<:.s=.o)) -c $$< -o $$@ |
||
54 | |||
55 | quiet_dep_cmd := ' DEP\\t$(in-local)' |
||
1685 | fabio | 56 | dep_cmd := $(cc) $$(cflags-$$(<:.c=.o)) $$(cppflags-$$(<:.c=.o))\ |
1681 | fabio | 57 | -M -MT \ |
58 | "$$(subst $$(srctree),$$(objtree),$$(<:.c=.o))\ |
||
59 | $$@" $$< > $$@ 2>/dev/null |
||
60 | |||
1685 | fabio | 61 | quiet_ld-r_cmd := ' LD [R]\\t$(out-local)' |
62 | ld-r_cmd := $(ld) $$(ldflags-$$(dir $$@)) $$(ldflags-$$@)\ |
||
63 | -r $(in-objs) -o $$@ |
||
1681 | fabio | 64 | |
1685 | fabio | 65 | quiet_ld_cmd := ' LD\\t$(out-local)' |
66 | ld_cmd := $(ld) $$(ldflags-$$(dir $$@)) $$(startup-$$@) $(in-objs)\ |
||
67 | $$(ldflags-$$@) -o $$@ |
||
68 | |||
1681 | fabio | 69 | quiet_rm_cmd := ' RM\\t$$(subst clean-,,$$(subst distclean-,,$(out-local)))' |
70 | rm_cmd := -$(rm) $$(subst clean-,,$$(subst distclean-,,$$@)) |
||
71 | |||
72 | quiet_install_cmd := ' INSTALL $(out-local)' |
||
73 | install_cmd := -$(install) $$(subst install-,,$$@) $$(installdir) |
||
74 | |||
75 | # Generate the requested rule for the requested directory. First echo |
||
76 | # the command according to the requested verbosity (suppress all the |
||
77 | # output if $(QS)$(1)_cmd is not defined, i.e., in the silent make case,) |
||
78 | # and then emit the actual command. |
||
79 | define cmd |
||
80 | $(if $($(QS)$(1)_cmd),@echo -e '$($(QS)$(1)_cmd)') |
||
81 | @$($(1)_cmd) |
||
82 | endef |
||
83 | |||
84 | # Remove duplicate slashes, ../'s, trailing slashes and so on from paths. |
||
1685 | fabio | 85 | clean-path=$(dir $(abspath $(1)))$(notdir $(abspath $(1))) |
1681 | fabio | 86 | |
1685 | fabio | 87 | # Canonicalize a path, converting .. and . $(1) is the current directory, |
88 | # and $(2) are the paths to be converted. |
||
89 | to-local-path=$(subst $(1)/,,$(abspath $(addprefix $(1)/,$(2)))) |
||
90 | |||
91 | # Keep only paths in $(1) that start with ./ (i.e., that are relative to the |
||
92 | # current directory.) |
||
93 | keep-local=$(foreach p, $(1),$(if $(subst ./,,$(dir $(p))),,$(p))) |
||
94 | |||
1681 | fabio | 95 | # Adjust the paths for all the prerequisites of a target. Given a list |
96 | # of objects, with relative or absolute path, figure out the right paths |
||
97 | # in the build directory. Leave the output in $(target-objs). |
||
98 | define all-prerequisites-templ |
||
99 | target-obj-list:=$(1) |
||
100 | |||
101 | # Filter absolute paths. |
||
102 | target-objs:=$$(filter $(srctree)/%,$$(target-obj-list)) |
||
103 | target-obj-list:=$$(filter-out $$(target-objs),$$(target-obj-list)) |
||
104 | |||
105 | # Add all the other objects, and convert the path to the $(objtree) |
||
106 | # root and with a reasonable path. |
||
107 | target-objs+=$$(addprefix $$(curdir)/,$$(target-obj-list)) |
||
108 | target-objs:=$$(foreach dir,$$(subst $(srctree),$(objtree),$$(target-objs)),\ |
||
109 | $$(call clean-path,$$(dir))) |
||
110 | endef |
||
111 | |||
1685 | fabio | 112 | # Produce targets for a given library/application. |
113 | define libapp-templ |
||
114 | libapp:=$(1) |
||
115 | is-app:=$(strip $(2)) |
||
116 | libapp-target:=$$(objdir)/$$(libapp) |
||
1681 | fabio | 117 | |
1685 | fabio | 118 | # Get a list of all the prerequisites needed to build the library/application. |
1681 | fabio | 119 | $$(eval $$(call all-prerequisites-templ,\ |
1685 | fabio | 120 | $$(patsubst %/,%/obj.o,$$($$(libapp)-objs)))) |
1681 | fabio | 121 | |
1685 | fabio | 122 | $$(foreach flag,$(flags),$$(eval $$(call flags-per-target,$$(flag),$$(libapp)))) |
1681 | fabio | 123 | $$(foreach obj,$$(target-objs),\ |
1685 | fabio | 124 | $$(eval $$(call flags-per-objects,$$(obj),$$(libapp)))) |
1681 | fabio | 125 | |
126 | # Produce the real target, in $(objtree), and the user-friendly target, |
||
127 | # with a relative path to $(srctree). Note that even when the two trees |
||
128 | # are equal we define two targets; a possible optimization could be to |
||
129 | # use relative paths for the object tree in this case, but the code can |
||
130 | # become even less readable than it is now... |
||
1685 | fabio | 131 | ifeq ($$(is-app),true) |
132 | startup-$$(libapp-target):= $$($$(libapp)-startup) |
||
133 | $$(libapp-target): $$(target-objs) |
||
134 | $(call cmd,ld) |
||
135 | else |
||
136 | $$(libapp-target): $$(target-objs) |
||
1681 | fabio | 137 | $(call cmd,ar) |
1685 | fabio | 138 | endif |
139 | short-libapp-taget:=$$(subst $$(srctree)/,,$$(curdir)/$$(libapp)) |
||
140 | .PHONY: $$(short-libapp-target) |
||
141 | $$(short-libapp-target): $$(libapp-target) |
||
1681 | fabio | 142 | |
143 | # Update the $(subdirs) for $(curdir) and its target list. |
||
1685 | fabio | 144 | subdirs+=$$(filter %/,$$($$(libapp)-objs)) |
145 | curdir-targets+=$$(libapp-target) |
||
1681 | fabio | 146 | |
1685 | fabio | 147 | .PHONY: clean-$$(libapp-target) |
148 | clean-$$(libapp-target): |
||
1681 | fabio | 149 | $(call cmd,rm) |
1685 | fabio | 150 | curdir-clean-targets+= clean-$$(libapp-target) |
1681 | fabio | 151 | |
1685 | fabio | 152 | ifneq ($$(is-app),true) |
153 | .PHONY: install-$$(libapp-target) |
||
154 | install-$$(libapp-target): $$(libapp-target) |
||
1681 | fabio | 155 | $(call cmd,install) |
1685 | fabio | 156 | curdir-install-targets+= install-$$(libapp-target) |
157 | endif |
||
1681 | fabio | 158 | endef |
159 | |||
160 | # Produce the needed code for a given object. |
||
161 | define obj-templ |
||
162 | obj:=$(1) |
||
163 | obj-target:=$$(objdir)/$$(obj) |
||
164 | obj-dep:=$$(objdir)/.$$(obj:.o=.c).deps |
||
165 | |||
166 | # Handle dependencies. |
||
167 | ifeq ($(goals-have-clean),) |
||
168 | $$(obj-dep): $$(objdir-prereq) |
||
169 | -include $$(obj-dep) |
||
170 | endif |
||
171 | |||
172 | # Produce the user shortcut for the real target (that does not need to |
||
173 | # be produced, as it is handled by implicit rules.) |
||
174 | short-obj-target:= $$(subst $$(srctree)/,,$$(curdir)/$$(obj)) |
||
175 | .PHONY: $$(short-obj-target) |
||
176 | $$(short-obj-target): $$(obj-target) |
||
177 | |||
178 | curdir-targets+=$$(obj-target) |
||
179 | |||
180 | .PHONY: clean-$$(obj-target) distclean-$$(obj-dep) |
||
181 | clean-$$(obj-target): |
||
182 | $(call cmd,rm) |
||
183 | distclean-$$(obj-dep): |
||
184 | $(call cmd,rm) |
||
185 | curdir-clean-targets+= clean-$$(obj-target) |
||
186 | curdir-distclean-targets+= distclean-$$(obj-dep) |
||
187 | |||
1685 | fabio | 188 | ifneq ($$(filter $$(obj),$$(install-objs)),) |
189 | .PHONY: install-$$(obj-target) |
||
190 | install-$$(obj-target): $$(obj-target) |
||
191 | $(call cmd,install) |
||
192 | curdir-install-targets+= install-$$(obj-target) |
||
193 | endif |
||
1681 | fabio | 194 | endef |
195 | |||
196 | # Handle the flags for the current directory. for each *FLAGS variable |
||
197 | # used by the implicit rules there are two variants: |
||
198 | # o the local one, e.g., cflags:=-I. or cflags+=-I. changing the |
||
199 | # flags used only by the current directory. |
||
200 | # o The global one, e.g., exported-cflags:=-I$(srctree) changing the |
||
201 | # flags for the current directory and all its subdirs. |
||
202 | # The flag handling is split in three parts, one to be inserted before |
||
203 | # including the current directory makefile, one before recurring into |
||
204 | # subdirs, the other one after the recursion. |
||
205 | define flags-save-templ |
||
206 | flag:=$(1) |
||
207 | # Flags on input to this dir; they must be preserved for our sibling |
||
208 | # directories. |
||
209 | saved-$$(flag)-$$(curdir):= $$($$(flag)) |
||
210 | endef |
||
211 | |||
212 | define flags-pre-templ |
||
213 | flag:=$(1) |
||
214 | |||
215 | # For the current directory, use the user-specified flags (that may |
||
216 | # come from our parent directory.) Extra flags are used to specify |
||
217 | # library-specific flags. |
||
218 | $$(flag)-$$(curdir):=$$($$(flag)) $$(exported-$$(flag)) |
||
219 | |||
220 | #to-print+= [ $$(flag)-$$(curdir) = $$($$(flag)-$$(curdir)) ] RET |
||
221 | |||
222 | # Export to our children also the user exported flags. |
||
223 | $$(flag):= $$(saved-$$(flag)-$$(curdir)) $$(exported-$$(flag)) |
||
224 | exported-$$(flag):= |
||
225 | endef |
||
226 | |||
227 | define flags-post-templ |
||
228 | flag:=$(1) |
||
229 | |||
230 | # Restore the flags that our parent specified. |
||
231 | $$(flag):= $$(saved-$$(flag)-$$(curdir)) |
||
232 | endef |
||
233 | |||
234 | # Allow redefinition of flags on the basis of a single target. Each |
||
235 | # target gets its own version of the flags, based on the ones of the |
||
236 | # current directory and its own ones. |
||
237 | define flags-per-target |
||
238 | flag:=$(1) |
||
239 | target:=$(2) |
||
240 | |||
241 | $$(flag)-$$(curdir)/$$(target):=$$($$(flag)-$$(curdir)) \ |
||
1685 | fabio | 242 | $$($$(target)-$$(flag)) $$(extra-$$(flag)-$$(curdir)/$$(target)) |
1681 | fabio | 243 | |
1685 | fabio | 244 | ifneq ($$(target),install-objs) |
1681 | fabio | 245 | # Those are the flags coming from the upper directories, they are set for |
246 | # obj.o targets, we must export them to our children, so we leave them here. |
||
247 | exported-$$(flag)-$$(curdir)/$$(target):= $$($$(target)-$$(flag)) \ |
||
248 | $$(extra-$$(flag)-$$(curdir)/$$(target)) |
||
1685 | fabio | 249 | endif |
1681 | fabio | 250 | $$(target)-$$(flag):= |
251 | endef |
||
252 | |||
253 | define flags-per-object |
||
254 | # Generate flags only for objects in the current directory, as prerequisites |
||
255 | # that come from ousdide are not compiled here. |
||
256 | flag:=$(1) |
||
257 | target:=$(3) |
||
258 | ifeq ($(dir $(subst $(objtree),$(srctree),$(2))),$$(curdir)/) |
||
259 | this-obj:=$(notdir $(2)) |
||
260 | |||
261 | # The flags for a given object are the ones specified for its target |
||
262 | # plus any specific one. |
||
1685 | fabio | 263 | $$(flag)-$$(curdir)/$$(this-obj):= $$($$(flag)-$$(curdir)/$$(target))\ |
1681 | fabio | 264 | $$($$(this-obj)-$$(flag)) |
265 | $$(this-obj)-$$(flag):= |
||
266 | |||
1685 | fabio | 267 | ifeq ($(3),install-objs) |
268 | to-print+= [ $(2) $(3) ] RET |
||
1681 | fabio | 269 | endif |
1685 | fabio | 270 | endif |
1681 | fabio | 271 | # Pass the right flags to the subdirs we use to build $(target). |
272 | ifeq ($$(notdir $(2)),obj.o) |
||
273 | extra-$$(flag)-$(2):= $$(exported-$$(flag)-$$(curdir)/$$(target)) |
||
274 | endif |
||
275 | endef |
||
276 | |||
277 | # Allow the user to specify per-object flags |
||
278 | define flags-per-objects |
||
279 | $$(foreach flag,$$(flags),\ |
||
280 | $$(eval $$(call flags-per-object,$$(flags),$(1),$(2)))) |
||
281 | endef |
||
282 | |||
283 | # Helper to define per-library flags. |
||
284 | define flags-per-libs |
||
285 | $$(foreach flag,$$(flags),\ |
||
286 | $$(eval $$(call flags-per-lib,$$(flags),$(1),$(2)))) |
||
287 | endef |
||
288 | |||
289 | # Disable default implicit rules. |
||
290 | .SUFFIXES: |
||
291 | |||
292 | # The roots of our source and object trees. If an O=dir option is |
||
293 | # passed to the toplevel makefile all the output of the building |
||
294 | # process is in dir. |
||
295 | srctree:=$(call clean-path,$(CURDIR)) |
||
296 | objtree:=$(if $(O),$(call clean-path,$(O)),$(srctree)) |
||
297 | |||
298 | ifeq ($(wildcard $(objtree)),) |
||
299 | $(error Output directory $(objtree) does not exist) |
||
300 | endif |
||
301 | |||
302 | clean-targets:= |
||
303 | distclean-targets:= |
||
304 | install-targets:= |
||
305 | |||
306 | goals-have-clean:=$(strip $(filter clean distclean,$(MAKECMDGOALS))) |
||
307 | |||
308 | aflags:= $(AFLAGS) |
||
309 | cflags:= $(CFLAGS) |
||
310 | cppflags:= $(CPPFLAGS) |
||
311 | ldflags:= $(LDFLAGS) |
||
312 | flags:= aflags cflags cppflags ldflags |
||
313 | |||
314 | # XXX debug only |
||
315 | to-print:= |
||
316 | |||
317 | # The following macro is used to do a standard set of operations |
||
318 | # for every subdirectory we have to work on. It is instantiated |
||
319 | # every time we change subdirectory, and generates a set of targets |
||
320 | # specific to that directory. |
||
321 | define recurse-templ |
||
322 | |||
323 | # Remember where we are in the source and object tree. The clean-path |
||
324 | # macro is used for user output and for generating targets independently |
||
325 | # from directories being specified as dir or dir/ or with multiple slashes |
||
326 | # and so on. |
||
327 | curdir:=$$(call clean-path,$(1)) |
||
328 | objdir:=$(objtree)$$(subst $(srctree),,$$(curdir)) |
||
329 | |||
330 | # Save the flags our parent passed us. |
||
331 | $$(foreach flag,$(flags),$$(eval $$(call flags-save-templ,$$(flag)))) |
||
332 | |||
333 | # A list of all the targets defined for the current directory. It is |
||
334 | # used to produce an user-reachable target for submakes into source tree |
||
335 | # subdirectories, e.g., if src/utils is a source directory, make src/utils |
||
336 | # will build all the targets defined inside it. Start with the short path |
||
337 | # to all subdirs. |
||
338 | curdir-targets:= |
||
339 | |||
340 | curdir-clean-targets:= |
||
341 | curdir-distclean-targets:= |
||
342 | curdir-install-targets:= |
||
343 | |||
1685 | fabio | 344 | install-objs:= |
345 | |||
1681 | fabio | 346 | # If the output directory does not exist every target that actually |
347 | # needs it will have to create it. |
||
348 | ifneq ($(objtree),$(srctree)) |
||
349 | ifeq ($$(wildcard $$(objdir)),) |
||
350 | objdir-prereq:=$$(objdir)/.build |
||
351 | $$(objdir)/.build: |
||
352 | $(Q)if [ ! -d $$(dir $$@) ] ; then \ |
||
353 | mkdir -p $$(dir $$@) ; touch $$@ ; fi |
||
354 | endif |
||
355 | endif |
||
356 | |||
357 | # Include the next subdirectory. Don't include the root makefile, |
||
358 | # if we are at the first step of the recursion. |
||
359 | include $$(subst $(srctree)/Makefile,,$$(curdir)/Makefile) |
||
360 | |||
361 | # Figure out all the targets. We support three kind of targets: |
||
362 | # - subdirectories |
||
363 | # - libraries |
||
364 | # - objects |
||
2 | pj | 365 | # |
1681 | fabio | 366 | # Subdirectories are recursively processed, libraries are built using |
367 | # the objects specified in their *.a-objs target (if it contains a |
||
368 | # subdirectory the latter is processed and the resulting obj.o object |
||
369 | # is included,) and objects are compiled and incrementally linked |
||
370 | # together in a obj.o file. |
||
371 | subdirs:=$$(filter %/, $$(targets)) |
||
372 | objs:=$$(filter %.o, $$(targets)) |
||
373 | libs:=$$(filter %.a, $$(targets)) |
||
1685 | fabio | 374 | apps:=$$(filter-out $$(subdirs) $$(objs) $$(libs),$$(targets)) |
2 | pj | 375 | |
1681 | fabio | 376 | $$(eval $$(call all-prerequisites-templ, $$(subdirs))) |
377 | subdir-targets:= $$(target-objs) |
||
378 | |||
379 | # Recurse into all the subdirectories. |
||
380 | curdir-targets+=$$(subst $(objtree)/,,$$(subdir-targets)) |
||
381 | |||
382 | # Look for prerequisites to build obj.o for the current directory. |
||
383 | $$(eval $$(call all-prerequisites-templ,\ |
||
384 | $$(filter-out $$(exclude),$$(objs)))) |
||
385 | target-objs+=$$(addsuffix /obj.o,$$(subdir-targets)) |
||
386 | |||
387 | $$(foreach flag,$(flags),$$(eval $$(call flags-pre-templ,$$(flag)))) |
||
388 | |||
389 | # Produce a target for obj.o, even if not needed (it will be empty in |
||
390 | # this case.) |
||
391 | ifneq ($$(strip $$(target-objs)),) |
||
392 | $$(foreach flag,$(flags),$$(eval $$(call flags-per-target,$$(flag),obj.o))) |
||
393 | $$(foreach obj,$$(target-objs),\ |
||
394 | $$(eval $$(call flags-per-objects,$$(obj),obj.o))) |
||
395 | $$(objdir)/obj.o: $$(target-objs) |
||
396 | $(call cmd,ld-r) |
||
397 | else |
||
398 | $$(objdir)/obj.o: |
||
399 | $(Q)touch $$@ |
||
2 | pj | 400 | endif |
1681 | fabio | 401 | curdir-targets+= $$(objdir)/obj.o |
64 | pj | 402 | |
1681 | fabio | 403 | # to-print+= [ [ $$(objdir)/obj.o ] $$(target-objs) ] |
2 | pj | 404 | |
1681 | fabio | 405 | # Produce the needed targets for each library. |
406 | ifneq ($$(strip $$(libs)),) |
||
1685 | fabio | 407 | $$(foreach lib,$$(libs),$$(eval $$(call libapp-templ,$$(lib),false))) |
1681 | fabio | 408 | endif |
409 | |||
1685 | fabio | 410 | ifneq ($$(strip $$(apps)),) |
411 | $$(foreach app,$$(apps),$$(eval $$(call libapp-templ,$$(app),true))) |
||
412 | endif |
||
413 | |||
1681 | fabio | 414 | # Produce a target for each local object. Build the list of all the |
415 | # targets specified by the current subdir. It is given by all the local |
||
416 | # objects in $(targets) or in a library contained in it. Non-local |
||
417 | # objects can be specified as dependencies but must be built from the |
||
418 | # directory containing them (if needed their directory can specify that |
||
419 | # they are not to be included in the local obj.o putting them into |
||
420 | # $(exclude); this may not seem straightforward but is to support a |
||
421 | # few corner cases.) |
||
2 | pj | 422 | # |
1681 | fabio | 423 | # First build a relative path for all the .o files in the targets (the |
424 | # default one and the library ones,) taking care of not being confused |
||
425 | # by relative directory specifications. |
||
1685 | fabio | 426 | #all-local-objs-paths:=$$(subst $$(curdir)/,,\ |
427 | # $$(abspath $$(addprefix $$(curdir)/,\ |
||
428 | # $$(objs) $$(install-objs)\ |
||
429 | # $$(foreach lib,$$(libs),$$(filter %.o,$$($$(lib)-objs)))\ |
||
430 | # $$(foreach app,$$(apps),$$(filter %.o,$$($$(app)-objs)))))) |
||
431 | all-local-objs-paths:=$$(call to-local-path,$$(curdir),\ |
||
432 | $$(objs)\ |
||
433 | $$(foreach lib,$$(libs),$$(filter %.o,$$($$(lib)-objs)))\ |
||
434 | $$(foreach app,$$(apps),$$(filter %.o,$$($$(app)-objs)))) |
||
2 | pj | 435 | |
1685 | fabio | 436 | all-local-install-objs-paths:=$$(call to-local-path,$$(curdir),\ |
437 | $$(install-objs)) |
||
438 | |||
1681 | fabio | 439 | # Then keep only those with a dir equal to ./ A local object is not |
440 | # allowed to be specified with a path specifying a directory different |
||
1685 | fabio | 441 | # from the current one. Objects to be installed are only taken into |
442 | # account if they're local to the current directory. |
||
443 | #all-local-objs:=$$(foreach obj, $$(all-local-objs-paths),\ |
||
444 | # $$(if $$(subst ./,,$$(dir $$(obj))),,$$(obj))) |
||
445 | all-local-install-objs:=$$(call keep-local,$$(all-local-install-objs-paths)) |
||
446 | all-local-objs:=$$(call keep-local,$$(all-local-objs-paths))\ |
||
447 | $$(all-local-install-objs) |
||
2 | pj | 448 | |
1685 | fabio | 449 | $$(eval $$(call all-prerequisites-templ,$$(all-local-install-objs))) |
450 | $$(foreach flag,$(flags),\ |
||
451 | $$(eval $$(call flags-per-target,$$(flag),install-objs))) |
||
452 | $$(foreach obj,$$(target-objs),\ |
||
453 | $$(eval $$(call flags-per-objects,$$(obj),install-objs))) |
||
454 | |||
1681 | fabio | 455 | # Produce one target per object, and the rules to build them along with |
456 | # their dependencies. |
||
457 | ifneq ($$(strip $$(all-local-objs)),) |
||
458 | $$(foreach obj,$$(all-local-objs),$$(eval $$(call obj-templ,$$(obj)))) |
||
459 | |||
460 | $$(objdir)/%.o: $$(curdir)/%.c |
||
461 | $(call cmd,cc) |
||
462 | |||
463 | $$(objdir)/%.o: $$(curdir)/%.s |
||
464 | $(call cmd,as) |
||
465 | |||
466 | $$(objdir)/.%.c.deps: $$(curdir)/%.c |
||
467 | $(call cmd,dep) |
||
468 | |||
1037 | tullio | 469 | endif |
138 | trimarchi | 470 | |
1681 | fabio | 471 | # Produce the user-friendly target for the source dir, depending |
472 | # on its obj.o, libs and local objects (only if they can be built.) |
||
473 | curdir-target:= $$(subst $$(srctree)/,,$$(curdir)) |
||
474 | .PHONY: $$(curdir-target) |
||
475 | $$(curdir-target): $$(curdir-targets) |
||
476 | |||
477 | # Produce the clean and distclean targets for the current directory. |
||
478 | .PHONY: clean-$$(curdir-target) distclean-$$(curdir-target) |
||
479 | clean-$$(curdir-target): $$(curdir-clean-targets) |
||
480 | |||
481 | distclean-$$(curdir-target): clean-$$(curdir-target) \ |
||
482 | $$(curdir-distclean-targets) |
||
483 | |||
484 | # to-print+=[ distclean-$$(curdir-target) ] |
||
485 | |||
486 | clean-targets+= clean-$$(curdir-target) |
||
487 | distclean-targets+= distclean-$$(curdir-target) |
||
488 | |||
489 | # Produce the install target. This is very Shark specific... |
||
490 | .PHONY: install-$$(curdir-target) |
||
491 | $$(curdir-install-targets): $(installdir)/.build |
||
492 | install-$$(curdir-target): $$(curdir-install-targets) |
||
493 | install-targets+= install-$$(curdir-target) |
||
494 | |||
495 | #to-print+=[ install-$$(curdir-target) = $$(curdir-install-targets) ] |
||
496 | |||
497 | # Actually do the recursion, generating the code specified by |
||
498 | # recurse-tmpl for every subdirectory needed from the one we are |
||
499 | # leaving. |
||
500 | ifneq ($$(strip $$(subdirs)),) |
||
501 | $$(foreach dir,$$(subdirs),$$(eval $$(call recurse-templ,$(1)/$$(dir)))) |
||
502 | curdir:=$$(call clean-path,$(1)) |
||
503 | endif |
||
504 | |||
505 | $$(foreach flag,$(flags),$$(eval $$(call flags-post-templ,$$(flag)))) |
||
506 | endef |
||
507 | |||
508 | .DEFAULT_GOAL:= all |
||
509 | |||
510 | installdir:=$(objtree)/.lib |
||
511 | |||
1685 | fabio | 512 | # Include all the Shark specific configuration... |
513 | include $(if $(S),$(S)/)Rules.mk |
||
1681 | fabio | 514 | |
515 | # Let the good times roll... |
||
516 | $(eval $(call recurse-templ,$(srctree))) |
||
517 | |||
518 | all: $(srctree) |
||
519 | |||
520 | .PHONY: clean distclean |
||
521 | clean: $(clean-targets) |
||
522 | distclean: $(distclean-targets) |
||
523 | |||
524 | debug: |
||
525 | @echo $(to-print) |
||
526 | |||
527 | .PHONY: install $(install-targets) |
||
528 | $(installdir)/.build: |
||
529 | $(Q)if [ ! -d $(dir $@) ] ; then \ |
||
530 | mkdir -p $(dir $@) ; touch $@ ; fi |
||
531 | |||
532 | install: $(install-targets) |
||
533 |