Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame^] | 1 | # Input |
| 2 | # |
| 3 | # The output from mk/sub.mk |
| 4 | # base-prefix |
| 5 | # |
| 6 | # Output |
| 7 | # |
| 8 | # set objs |
| 9 | # update cleanfiles |
| 10 | # |
| 11 | # Generates explicit rules for all objs |
| 12 | |
| 13 | objs := |
| 14 | |
| 15 | # Disable all builtin rules |
| 16 | .SUFFIXES: |
| 17 | |
| 18 | comp-cflags$(sm) = -std=gnu99 |
| 19 | comp-aflags$(sm) = |
| 20 | comp-cppflags$(sm) = |
| 21 | |
| 22 | ifndef NOWERROR |
| 23 | comp-cflags$(sm) += -Werror |
| 24 | endif |
| 25 | comp-cflags$(sm) += -fdiagnostics-show-option |
| 26 | |
| 27 | comp-cflags-warns-high = \ |
| 28 | -Wall -Wcast-align \ |
| 29 | -Werror-implicit-function-declaration -Wextra -Wfloat-equal \ |
| 30 | -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \ |
| 31 | -Wmissing-declarations -Wmissing-format-attribute \ |
| 32 | -Wmissing-include-dirs -Wmissing-noreturn \ |
| 33 | -Wmissing-prototypes -Wnested-externs -Wpointer-arith \ |
| 34 | -Wshadow -Wstrict-prototypes -Wswitch-default \ |
| 35 | -Wwrite-strings \ |
| 36 | -Wno-missing-field-initializers -Wno-format-zero-length |
| 37 | comp-cflags-warns-medium = \ |
| 38 | -Waggregate-return -Wredundant-decls |
| 39 | comp-cflags-warns-low = \ |
| 40 | -Winline \ |
| 41 | -Wold-style-definition -Wstrict-aliasing=2 \ |
| 42 | -Wundef -pedantic \ |
| 43 | -Wdeclaration-after-statement |
| 44 | |
| 45 | comp-cflags-warns-1:= $(comp-cflags-warns-high) |
| 46 | comp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium) |
| 47 | comp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low) |
| 48 | |
| 49 | WARNS ?= 3 |
| 50 | |
| 51 | comp-cflags$(sm) += $(comp-cflags-warns-$(WARNS)) |
| 52 | |
| 53 | .PHONY: FORCE |
| 54 | FORCE: |
| 55 | |
| 56 | define process_srcs |
| 57 | objs += $2 |
| 58 | comp-dep-$2 := $$(dir $2).$$(notdir $2).d |
| 59 | comp-temp-dep-$2:= $$(comp-dep-$2).tmp |
| 60 | comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd |
| 61 | comp-sm-$2 := $(sm) |
| 62 | |
| 63 | cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2 |
| 64 | |
| 65 | ifeq ($$(filter %.c,$1),$1) |
| 66 | comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ |
| 67 | $$(cflags-remove-$2), \ |
| 68 | $$(CFLAGS) $$(CFLAGS_WARNS) \ |
| 69 | $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \ |
| 70 | $$(cflags-$2)) |
| 71 | else ifeq ($$(filter %.S,$1),$1) |
| 72 | comp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \ |
| 73 | $$(aflags-remove-$2), \ |
| 74 | $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \ |
| 75 | $$(aflags$$(comp-sm-$2)) $$(aflags-$2)) |
| 76 | else |
| 77 | $$(error "Don't know what to do with $1") |
| 78 | endif |
| 79 | |
| 80 | |
| 81 | comp-flags-$2 += -Wp,-MD,$$(comp-temp-dep-$2) \ |
| 82 | $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ |
| 83 | $$(cppflags-remove-$2), \ |
| 84 | $$(nostdinc) $$(CPPFLAGS) \ |
| 85 | $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \ |
| 86 | $$(cppflags$$(comp-sm-$2)) $$(cppflags-$2)) |
| 87 | |
| 88 | comp-cmd-$2 = $$(CC) $$(comp-flags-$2) -c $$< -o $$@ |
| 89 | |
| 90 | -include $$(comp-cmd-file-$2) |
| 91 | -include $$(comp-dep-$2) |
| 92 | |
| 93 | |
| 94 | $2: $1 FORCE |
| 95 | # Check if any prerequisites are newer than the target and |
| 96 | # check if command line has changed |
| 97 | $$(if $$(strip $$? $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \ |
| 98 | $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \ |
| 99 | @set -e ;\ |
| 100 | mkdir -p $$(dir $2) ;\ |
| 101 | echo [$$(comp-sm-$2)] CC $1 ;\ |
| 102 | $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\ |
| 103 | $$(comp-cmd-$2) ;\ |
| 104 | $(cmd-fixdep) $$(dir $2) < $$(comp-temp-dep-$2) > \ |
| 105 | $$(comp-dep-$2) ;\ |
| 106 | rm -f $$(comp-temp-dep-$2) ;\ |
| 107 | echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \ |
| 108 | $$(comp-cmd-file-$2) ;\ |
| 109 | ) |
| 110 | |
| 111 | endef |
| 112 | |
| 113 | $(foreach f, $(srcs), $(eval $(call \ |
| 114 | process_srcs,$(f),$(out-dir)$(base-prefix)$$(basename $f).o))) |