forked from alperakcan/libmakefile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.lib4c
691 lines (556 loc) · 26 KB
/
Makefile.lib4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#
# Makefile.lib4c
#
# version : 3.2.4
# copyright : 2002 - 2020 by Alper Akcan
# email : [email protected]
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# Changelog :
#
# 20190125 - stripped down version of Makefile.lib for C
# 20190701 - do not override depends-y
# 20190702 - fix depends-y for subdirs
# 20190806 - fix parallel compilation of ${target}_depends-y
# 20200130 - dist and install support
# 20200203 - add 'distclean' target and add uniq to all foreach
# 20200204 - fix depends .d generation with subdir dependencies
#
# Example
# -------
#
# target-y = target1
# target-y += target2
#
# target1_files-y = target_file_shared.c \
# target1_file_2.c \
# target1_file_3.c
# target1_includes-y = ./ \
# /opt/include
# target1_libraries-y = ./ \
# /opt/lib
# target1_cflags-y = -DUSER_DEFINED \
# -O2
# target1_ldflags-y = -luserdefined
#
# target2_files-y = target_file_shared.c \
# target2_file_2.c \
# target2_file_3.c
# target2_includes-y = ./ \
# /opt/include
# target2_libraries-y = ./ \
# /opt/lib
# target2_cflags-y = -DUSER_DEFINED \
# -O2
# target2_ldflags-y = -luserdefined
#
# dist.dir = dist
#
# dist.base = base
#
# dist.bin = target1
#
# include Makefile.lib
#
#
# Overview
# --------
#
# you can have more than one target, just add targets as you wish. you can
# share files among targets, files will be compiled for each target with
# approtiate flags.
#
# in addition targets may depend each other, so if your target depends on
# target.so just add target.so to target's depend list with;
#
# ${target}_depends-y = target.so
#
# targets may also depend to the subdirectories, so target commands will
# not be executed until subdirs commands get executed.
#
# some usefull files are created in make process, for debugging and for speedup
#
# .target/*.d : includes depend information for the file
# .target/*.d.cmd : the command used for generating .d file
# .target/*.o : object for the file
# .target/*.o.cmd : the command used for creating the object
# .target/target[a,so,o] : the target
# .target/target[a,so,o].cmd : the command used for creating the target
# target : the target
#
#
# Available Targets
# -----------------
#
# target-[y,n, ] : a binary target.
# target will be created with $(CC) -o
# target.o-[y,n, ] : an object target.
# target.o will be created with $(LD) -r -o
# target.a-[y,n, ] : a static library target.
# target.a will be created with $(AR)
# target.so-[y,n, ] : a shared library target.
# target.so will be created with $(CC) -o -shared
#
# target.host-[y,n, ] : a binary target.
# target will be created with $(HOSTCC) -o
# target.o.host-[y,n, ] : an object target.
# target.o will be created with $(HOSTLD) -r -o
# target.a.host-[y,n, ] : a static library target.
# target.a will be created with $(HOSTAR)
# target.so.host-[y,n, ] : a shared library target.
# target.so will be created with $(HOSTCC) -o -shared
#
# subdir-[y,n, ] : subdirectory targets are executed with
# $(subdir-y)_makeflags-y $(MAKE) -C $(subdir-y)
#
#
# Available Target Flags
# ----------------------
#
# $(target)_makeflags-[y,n, ] : makeflags for target will be passed to make
# command only for corresponding target.
# $(target)_files-[y,n, ] : files must match *.[cho] pattern. *.[ch] files
# will be exemined with $(CC) -M command to
# generate dependency files (*.d) files. *.[o]
# files will be used only in linking stage. all
# files generated with make command will be
# removed with $(RM) command.
# $(target)_cflags-[y,n, ] : cflags will be added to global $(CFLAGS) for
# corresponding target only.
# $(target)_${file}_cflags-[y,n, ] : cflags will be added to global $(CFLAGS) for
# corresponding target file only.
# $(target)_includes-[y,n, ] : a '-I' will be added to all words in includes
# flag, and will be used only for corresponding
# target.
# $(target)_libraries-[y,n, ] : a '-L' will be added to all words in libraries
# flag, and will be used only for corresponding
# target.
# $(target)_ldflags-[y,n, ] : ldflags will be added to gloabal $(LDFLAGS) for
# corresponding target only.
# $(target)_depends-[y,n, ] : all words in depends flag will be added to
# prerequisite's list.
#
#
# Distribution Commands
# ---------------------
#
# dist.dir : distribution folder
# dist.base : base folder to be used in $(dist.dir)/{obj,share,include,src}/
#
# dist.src-[y,n ] : files to be copied under $(dist.dir)/src directory
# dist.obj-[y,n ] : files to be copied under $(dist.dir)/obj directory
# dist.lib-[y,n ] : files to be copied under $(dist.dir)/lib directory
# dist.bin-[y,n ] : files to be copied under $(dist.dir)/bin directory
# dist.include-[y,n ] : files to be copied under $(dist.dir)/include directory
#
TOPDIR ?= $(CURDIR)
CC := $(CROSS_COMPILE_PREFIX)gcc $(SYSROOT)
LD := $(CROSS_COMPILE_PREFIX)ld
AR := $(CROSS_COMPILE_PREFIX)ar
RANLIB := $(CROSS_COMPILE_PREFIX)ranlib
STRIP := $(CROSS_COMPILE_PREFIX)strip -sx
OBJCOPY := $(CROSS_COMPILE_PREFIX)objcopy
HOSTCC := $(HOST_COMPILE_PREFIX)gcc
HOSTLD := $(HOST_COMPILE_PREFIX)ld
HOSTAR := $(HOST_COMPILE_PREFIX)ar
HOSTRANLIB := $(HOST_COMPILE_PREFIX)ranlib
HOSTSTRIP := $(HOST_COMPILE_PREFIX)strip
HOSTOBJCOPY:= $(HOST_COMPILE_PREFIX)objcpy
SED := sed
CD := cd
CP := cp -rf
MV := mv
RM := rm -rf
MKDIR := mkdir -p
__CFLAGS := -Wall -Wextra -Werror -pipe -g3 -O2 -fsigned-char -fno-strict-aliasing -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $(CFLAGS) $(EXTRA_CFLAGS)
#__CFLAGS += -Wswitch-enum -Wshadow
#__CFLAGS += -fvisibility=hidden
__LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
MAKE := CFLAGS="$(CFLAGS)" EXTRA_CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS="$(LDFLAGS)" EXTRA_LDFLAGS="$(EXTRA_LDFLAGS)" TOPDIR='$(TOPDIR)' $(MAKE)
all:
ifneq ($(V)$(VERBOSE),)
verbose := ver
Q =
else
verbose := pur
Q = @
MAKE += --no-print-directory
endif
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
pur_objects := $$(subst __UPDIR__/,../,$$@)
pur_objects := $$(if $$(patsubst /%,,$(pur_objects)),$(CURDIR)/$(pur_objects),$(pur_objects))
#
# PUR
#
pur_disp_depend.c = echo " DEP $(pur_objects)"
pur_disp_compile.c = echo " CC $(pur_objects)"
pur_disp_link.c = echo " LINK $(pur_objects)"
pur_disp_link_so.c = echo " LINKSO $(pur_objects)"
pur_disp_depend.c.host = echo " HOSTDEP $(pur_objects)"
pur_disp_compile.c.host = echo " HOSTCC $(pur_objects)"
pur_disp_link.c.host = echo " HOSTLINK $(pur_objects)"
pur_disp_link_so.c.host = echo " HOSTLINKSO $(pur_objects)"
pur_disp_ar = echo " AR $(pur_objects)"
pur_disp_ranlib = echo " RANLIB $(pur_objects)"
pur_disp_ld = echo " LD $(pur_objects)"
pur_disp_ld.host = echo " HOSTLD $(pur_objects)"
pur_disp_cp = echo " CP $(pur_objects)"
pur_disp_mkdir = echo " MKDIR $(CURDIR)/$@"
pur_disp_clean = echo " CLEAN $$(subst _clean,,$(pur_objects))"
pur_disp_dist = echo " DIST $(pur_objects)"
pur_disp_distclean = echo " DISTCLEAN $$(subst _distclean,,$(pur_objects))"
pur_disp_print_deps =
#
# VER
#
ver_disp_depend.c = echo "$(subst ",\",$(_cmd_depend.c))"
ver_disp_compile.c = echo "$(subst ",\",$(_cmd_compile.c))"
ver_disp_link.c = echo "$(subst ",\",$(_cmd_link.c))"
ver_disp_link_so.c = echo "$(subst ",\",$(_cmd_link_so.c))"
ver_disp_depend.c.host = echo "$(subst ",\",$(_cmd_depend.c.host))"
ver_disp_compile.c.host = echo "$(subst ",\",$(_cmd_compile.c.host))"
ver_disp_link.c.host = echo "$(subst ",\",$(_cmd_link.c.host))"
ver_disp_link_so.c.host = echo "$(subst ",\",$(_cmd_link_so.c.host))"
ver_disp_ar = echo "$(subst ",\",$(_cmd_ar))"
ver_disp_ranlib = echo "$(subst ",\",$(_cmd_ranlib))"
ver_disp_ld = echo "$(subst ",\",$(_cmd_ld))"
ver_disp_ld.host = echo "$(subst ",\",$(_cmd_ld.host))"
ver_disp_cp = echo "$(subst ",\",$(_cmd_cp))"
ver_disp_mkdir = echo "$(subst ",\",$(_cmd_mkdir))"
ver_disp_clean = echo "$(subst ",\",$(_cmd_clean) $1 .$1 [email protected])"
ver_disp_dist = echo "$(subst ",\",$(_cmd_dist))"
ver_disp_distclean = echo "$(subst ",\",$(_cmd_distclean) $1 .$1 [email protected])"
ver_disp_print_deps = echo "Target $$@ depends on prerequisites '$$^'"
#
# DISP
#
disp_depend.c = $($(verbose)_disp_depend.c)
disp_compile.c = $($(verbose)_disp_compile.c)
disp_link.c = $($(verbose)_disp_link.c)
disp_link_so.c = $($(verbose)_disp_link_so.c)
disp_depend.c.host = $($(verbose)_disp_depend.c.host)
disp_compile.c.host = $($(verbose)_disp_compile.c.host)
disp_link.c.host = $($(verbose)_disp_link.c.host)
disp_link_so.c.host = $($(verbose)_disp_link_so.c.host)
disp_ar = $($(verbose)_disp_ar)
disp_ranlib = $($(verbose)_disp_ranlib)
disp_ld = $($(verbose)_disp_ld)
disp_ld.host = $($(verbose)_disp_ld.host)
disp_cp = $($(verbose)_disp_cp)
disp_mkdir = $($(verbose)_disp_mkdir)
disp_clean = $($(verbose)_disp_clean)
disp_dist = $($(verbose)_disp_dist)
disp_distclean = $($(verbose)_disp_distclean)
disp_print_deps = $($(verbose)_disp_print_deps)
#
# _CMD
#
_cmd_depend.c = $(CC) $(__CFLAGS) $($1_cflags) \
$$($1_$$<_cflags-y) $($1_includes) -M $$< | $(SED) 's,\($$(basename $$(basename $$(notdir $$@)))\.o\) *:,$$(dir $$@)\1 $$@: ,' > $$@; \
$(CP) $$@ [email protected]; \
$(SED) -e 's/\#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$$$//' -e '/^$$$$/ d' -e 's/$$$$/ :/' < $$@ >> [email protected]; \
$(MV) [email protected] $$@
_cmd_compile.c = $(CC) $(__CFLAGS) $($1_cflags) \
$$($1_$$<_cflags-y) $($1_includes) -c -o $$@ $$<
_cmd_link.c = $(CC) $(__CFLAGS) $($1_libraries) -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^) \
$($1_ldflags) $(__LDFLAGS)
_cmd_link_so.c = $(CC) $(__CFLAGS) $($1_libraries) -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^) \
$($1_ldflags) $$(filter-out -static,$(__LDFLAGS)) -shared $$(if $($1_soname-y),-Wl$$(comma)-soname$$(comma)$($1_soname-y),-Wl$$(comma)-soname$$(comma)$$(notdir $$@))
_cmd_depend.c.host = $(HOSTCC) $(__CFLAGS) $($1_cflags) \
$$($1_$$<_cflags-y) $($1_includes) -M $$< | $(SED) 's,\($$(basename $$(basename $$(notdir $$@)))\.o\) *:,$$(dir $$@)\1 $$@: ,' > $$@; \
$(CP) $$@ [email protected]; \
$(SED) -e 's/\#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$$$//' -e '/^$$$$/ d' -e 's/$$$$/ :/' < $$@ >> [email protected]; \
$(MV) [email protected] $$@
_cmd_compile.c.host = $(HOSTCC) $(__CFLAGS) $($1_cflags) \
$$($1_$$<_cflags-y) $($1_includes) -c -o $$@ $$<
_cmd_link.c.host = $(HOSTCC) $(__CFLAGS) $($1_libraries) -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^) \
$($1_ldflags) $(__LDFLAGS)
_cmd_link_so.c.host = $(HOSTCC) $(__CFLAGS) $($1_libraries) -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^) \
$($1_ldflags) $$(filter-out -static,$(__LDFLAGS)) -shared $$(if $($1_soname-y),-Wl$$(comma)-soname$$(comma)$($1_soname-y),-Wl$$(comma)-soname$$(comma)$$(notdir $$@))
_cmd_ar = $(AR) rcs $$@ $$(filter-out __FORCE $($1_depends_y),$$^)
_cmd_ranlib = $(RANLIB) $$@
_cmd_ld = $(LD) $(LDOPTS) -r -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^)
_cmd_ld.host = $(HOSTLD) $(LDOPTS) -r -o $$@ $$(filter-out __FORCE $($1_depends_y),$$^)
_cmd_cp = $(CP) $$< $$@
_cmd_mkdir = $(MKDIR) $@
_cmd_clean = $(RM)
_cmd_dist = $(CP) $$< $$@
_cmd_distclean = $(RM)
#
# CMD
#
cmd_depend.c = echo "$(subst ",\",$(_cmd_depend.c))" > [email protected] ; $(_cmd_depend.c)
cmd_compile.c = echo "$(subst ",\",$(_cmd_compile.c))" > [email protected] ; $(_cmd_compile.c)
cmd_link.c = echo "$(subst ",\",$(_cmd_link.c))" > [email protected] ; $(_cmd_link.c)
cmd_link_so.c = echo "$(subst ",\",$(_cmd_link_so.c))" > [email protected] ; $(_cmd_link_so.c)
cmd_depend.c.host = echo "$(subst ",\",$(_cmd_depend.c.host))" > [email protected] ; $(_cmd_depend.c.host)
cmd_compile.c.host = echo "$(subst ",\",$(_cmd_compile.c.host))" > [email protected] ; $(_cmd_compile.c.host)
cmd_link.c.host = echo "$(subst ",\",$(_cmd_link.c.host))" > [email protected] ; $(_cmd_link.c.host)
cmd_link_so.c.host = echo "$(subst ",\",$(_cmd_link_so.c.host))" > [email protected] ; $(_cmd_link_so.c.host)
cmd_ar = echo "$(subst ",\",$(_cmd_ar))" > [email protected] ; $(_cmd_ar)
cmd_ranlib = echo "$(subst ",\",$(_cmd_ranlib))" >> [email protected] ; $(_cmd_ranlib)
cmd_ld = echo "$(subst ",\",$(_cmd_ld))" > [email protected] ; $(_cmd_ld)
cmd_ld.host = echo "$(subst ",\",$(_cmd_ld.host))" > [email protected] ; $(_cmd_ld.host)
cmd_cp = $(_cmd_cp)
cmd_mkdir = $(_cmd_mkdir)
cmd_clean = $(_cmd_clean)
cmd_dist = $(_cmd_dist)
cmd_distclean = $(_cmd_distclean)
#
# DO
#
do_depend.c = @$(disp_depend.c) ; $(MKDIR) $$(dir $$@); $(cmd_depend.c)
do_compile.c = @$(disp_compile.c) ; $(MKDIR) $$(dir $$@); $(cmd_compile.c)
do_link.c = @$(disp_link.c) ; $(MKDIR) $$(dir $$@); $(cmd_link.c)
do_link_so.c = @$(disp_link_so.c) ; $(MKDIR) $$(dir $$@); $(cmd_link_so.c)
do_depend.c.host = @$(disp_depend.c.host) ; $(MKDIR) $$(dir $$@); $(cmd_depend.c.host)
do_compile.c.host = @$(disp_compile.c.host) ; $(MKDIR) $$(dir $$@); $(cmd_compile.c.host)
do_link.c.host = @$(disp_link.c.host) ; $(MKDIR) $$(dir $$@); $(cmd_link.c.host)
do_link_so.c.host = @$(disp_link_so.c.host) ; $(MKDIR) $$(dir $$@); $(cmd_link_so.c.host)
do_ar = @$(disp_ar) ; $(MKDIR) $$(dir $$@); $(cmd_ar)
do_ranlib = @$(disp_ranlib) ; $(MKDIR) $$(dir $$@); $(cmd_ranlib)
do_ld = @$(disp_ld) ; $(MKDIR) $$(dir $$@); $(cmd_ld)
do_ld.host = @$(disp_ld.host) ; $(MKDIR) $$(dir $$@); $(cmd_ld.host)
do_cp = @$(disp_cp) ; $(MKDIR) $$(dir $$@); $(cmd_cp)
do_mkdir = @$(disp_mkdir) ; $(cmd_mkdir)
do_clean = @$(disp_clean) ; $(cmd_clean)
do_dist = @$(disp_dist) ; $(MKDIR) $$(dir $$@); $(cmd_dist)
do_distclean = @$(disp_distclean) ; $(cmd_distclean)
do_print_deps = @$(disp_print_deps)
#
# Functions
#
define target-defaults_base
$(eval comma = ,)
$(eval $1_sources_c = $(filter %.c,$2))
$(eval $1_headers_c = $(filter %.h,$2))
$(eval $1_objects_c = $(addprefix .$1/, $(subst .c,.c.o,$($1_sources_c))))
$(eval $1_objects_e = $(subst ",,$(filter %.o,$2)))
$(eval $1_objects_e += $(subst ",,$(filter %.a,$2)))
$(eval $1_objects_e += $(subst ",,$(filter %.lib,$2)))
$(eval $1_depends_c = $(addprefix .$1/, $(subst .c,.c.d,$($1_sources_c))))
$(eval $1_cflags = $($1_cflags-y))
$(eval $1_includes = $(addprefix -I, $($1_includes-y)))
$(eval $1_libraries = $(addprefix -L, ./ $($1_libraries-y)))
$(eval $1_ldflags = $($1_ldflags-y))
$(eval $1_depends_c = $(subst ../,__UPDIR__/,$($1_depends_c)))
$(eval $1_objects_c = $(subst ../,__UPDIR__/,$($1_objects_c)))
$(eval $1_objects = $($1_objects_c))
$(eval $1_directories = $(sort $(dir .$1/ $($1_objects_c))))
$(eval $1_depends = $(MAKEFILE_LIST) $($1_depends_c))
$(eval $1_depends_y = $($1_depends))
$(eval $1_depends_y += $($1_depends-y))
$(eval target-builds += $1)
$(eval target-objects += $($1_objects_c))
$(eval target-depends += $($1_depends_c))
$(eval target-cleans += $1_clean)
$($1_directories):
$(do_mkdir) $($1_directories)
$($1_depends_c): $($1_sources_c) $($1_headers_c)
$($1_objects_c): .$1/%.o: .$1/%.d $(MAKEFILE_LIST)
$($1_objects_e): $(MAKEFILE_LIST)
$(target-depends): $(filter %.c, $($1_depends_y)) $(filter %.h, $($1_depends_y))
$1: .$1/$1 $(MAKEFILE_LIST)
$(do_cp)
$(do_print_deps)
.NOTPARALLEL: $($1_depends_y) $($1_objects) $($1_objects_e)
.$1/$1: $($1_depends_y) $($1_objects) $($1_objects_e)
$1_clean: __FORCE
$(do_clean) $1 .$1 [email protected] $1.dSYM
$(do_print_deps)
$1_distclean: __FORCE
endef
define target-defaults-rule
$(eval source = $(patsubst $3,$4,$(subst __UPDIR__/,../,$2)))
$2: ${source} $(MAKEFILE_LIST)
$5
$(do_print_deps)
endef
define target-defaults
$(eval $(call target-defaults_base,$1,$2))
$(eval $(foreach F,$($1_depends_c), $(eval $(call target-defaults-rule,$1,$F,.$1/%.c.d,%.c,$(do_depend.c)))))
$(eval $(foreach F,$($1_objects_c), $(eval $(call target-defaults-rule,$1,$F,.$1/%.c.o,%.c,$(do_compile.c)))))
endef
define target.host-defaults
$(eval $(call target-defaults_base,$1,$2))
$(eval $(foreach F,$($1_depends_c), $(eval $(call target-defaults-rule,$1,$F,.$1/%.c.d,%.c,$(do_depend.c.host)))))
$(eval $(foreach F,$($1_objects_c), $(eval $(call target-defaults-rule,$1,$F,.$1/%.c.o,%.c,$(do_compile.c.host)))))
endef
define target-variables
$(eval $(call target-defaults,$1,$2))
.$1/$1:
$(do_link.c)
$(do_print_deps)
endef
define target.host-variables
$(eval $(call target.host-defaults,$1,$2))
.$1/$1:
$(do_link.c.host)
$(do_print_deps)
endef
define target.so-variables
$(eval $(call target-defaults,$1,$2))
.$1/$1:
$(do_link_so.c)
$(do_print_deps)
endef
define target.so.host-variables
$(eval $(call target.host-defaults,$1,$2))
.$1/$1:
$(do_link_so.c.host)
$(do_print_deps)
endef
define target.a-variables
$(eval $(call target-defaults,$1,$2))
.$1/$1:
$(do_ar)
$(do_ranlib)
$(do_print_deps)
endef
define target.a.host-variables
$(eval $(call target.host-defaults,$1,$2))
.$1/$1:
$(do_ar.host)
$(do_ranlib.host)
$(do_print_deps)
endef
define target.o-variables
$(eval $(call target-defaults,$1,$2))
.$1/$1:
$(do_ld)
$(do_print_deps)
endef
define target.o.host-variables
$(eval $(call target.host-defaults,$1,$2))
.$1/$1:
$(do_ld.host)
$(do_print_deps)
endef
define target_empty-defaults
targets-empty += $1
$(addsuffix _clean, $1): __FORCE
$(do_clean) $1 .$1 [email protected]
$(do_print_deps)
endef
define subdir_empty-defaults
$(addsuffix _$2, $1): __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _$2,,$$@)' $2
$(do_print_deps)
endef
define subdir-defaults
subdirs += $1
$1: $1_all
$(do_print_deps)
$(addsuffix _all, $1): $($1_depends-y) __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _all,,$$@)' all
$(do_print_deps)
$(addsuffix _install, $1): __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _install,,$$@)' install
$(do_print_deps)
$(addsuffix _clean, $1): __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _clean,,$$@)' clean
endef
define dist-defaults
$(eval $1_dname = $(dir $1))
$(eval $1_names = $1)
$(eval $1_files = $(subst $($1_dname), , $($1_names)))
$(eval $1_files = $1)
$(eval target-cleans += $1_distclean)
$(eval target-dists += $(addprefix $(dist.dir)/$2/, $($1_files)))
$(dist.dir)/$2: $(dist.dir)
$(addprefix $(dist.dir)/$2/, $($1_files)): $1
$(do_dist)
$1_distclean: __FORCE
$(do_distclean) $(addprefix $(dist.dir)/$2/, $($1_files))
$(Q)if [ -e '$$(abspath $(dist.dir))' ]; then find '$$(abspath $(dist.dir))' -depth -type d -empty -exec rm -rf {} \; ; fi
endef
define dist.share-variables
$(eval $(call dist-defaults,$1,share/${dist.base}))
endef
define dist.include-variables
$(eval $(call dist-defaults,$1,include/${dist.base}))
endef
define dist.obj-variables
$(eval $(call dist-defaults,$1,obj/${dist.base}))
endef
define dist.src-variables
$(eval $(call dist-defaults,$1,src/${dist.base}))
endef
define dist.lib-variables
$(eval $(call dist-defaults,$1,lib))
endef
define dist.bin-variables
$(eval $(call dist-defaults,$1,bin))
endef
#
# Definitions
#
# generate target variables
$(eval $(foreach T,$(call uniq,$(target-y)), $(eval $(call target-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o-y)), $(eval $(call target.o-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.o-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a-y)), $(eval $(call target.a-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.a-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so-y)), $(eval $(call target.so-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.so-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.host-y)), $(eval $(call target.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.host-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o.host-y)), $(eval $(call target.o.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.o.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o.host-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so.host-y)), $(eval $(call target.so.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.so.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so.host-)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a.host-y)), $(eval $(call target.a.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.a.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a.host-)), $(eval $(call target_empty-defaults,$T))))
# generate subdir targets
$(eval $(foreach S,$(call uniq,$(subdir-y)),$(eval $(call subdir-defaults,$S))))
$(eval $(foreach S,$(call uniq,$(subdir-n)),$(eval $(call subdir_empty-defaults,$S,clean))))
$(eval $(foreach S,$(call uniq,$(subdir-)),$(eval $(call subdir_empty-defaults,$S,clean))))
# distributin tags
ifneq ($(dist.dir),)
$(eval $(foreach D,$(call uniq,$(dist.bin-y)), $(eval $(call dist.bin-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.lib-y)), $(eval $(call dist.lib-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.obj-y)), $(eval $(call dist.obj-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.src-y)), $(eval $(call dist.src-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.include-y)), $(eval $(call dist.include-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.share-y)), $(eval $(call dist.share-variables,$D))))
endif
# generic tags
all: $(addsuffix _all, $(subdirs))
all: $(target-builds)
all: $(target-dists)
all: $(target.extra-y)
all: __FORCE
$(do_print_deps)
@true
install: $(addsuffix _install, $(subdirs))
install: $(target-dists)
install: __FORCE
clean: $(addsuffix _clean, $(subdir-y) $(subdir-n) $(subdir-))
clean: $(target-cleans)
clean: $(addsuffix _clean, $(targets-empty))
clean: __FORCE
distclean: clean
distclean: __FORCE
__FORCE:
@true
ifeq ($(filter $(MAKECMDGOALS),clean distclean),)
-include $(target-depends)
endif