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 = \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 40 | -Wold-style-definition -Wstrict-aliasing=2 \ |
| 41 | -Wundef -pedantic \ |
| 42 | -Wdeclaration-after-statement |
| 43 | |
| 44 | comp-cflags-warns-1:= $(comp-cflags-warns-high) |
| 45 | comp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium) |
| 46 | comp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low) |
| 47 | |
| 48 | WARNS ?= 3 |
| 49 | |
| 50 | comp-cflags$(sm) += $(comp-cflags-warns-$(WARNS)) |
| 51 | |
| 52 | .PHONY: FORCE |
| 53 | FORCE: |
| 54 | |
| 55 | define process_srcs |
| 56 | objs += $2 |
| 57 | comp-dep-$2 := $$(dir $2).$$(notdir $2).d |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 58 | comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd |
| 59 | comp-sm-$2 := $(sm) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 60 | comp-lib-$2 := $(libname) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 61 | |
| 62 | cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2 |
| 63 | |
| 64 | ifeq ($$(filter %.c,$1),$1) |
| 65 | comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ |
| 66 | $$(cflags-remove-$2), \ |
| 67 | $$(CFLAGS) $$(CFLAGS_WARNS) \ |
| 68 | $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \ |
Jerome Forissier | 3d34e12 | 2014-10-30 17:37:42 +0100 | [diff] [blame] | 69 | $$(cflags-lib$$(comp-lib-$2)) $$(cflags-$2)) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 70 | else ifeq ($$(filter %.S,$1),$1) |
| 71 | comp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \ |
| 72 | $$(aflags-remove-$2), \ |
| 73 | $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \ |
| 74 | $$(aflags$$(comp-sm-$2)) $$(aflags-$2)) |
| 75 | else |
| 76 | $$(error "Don't know what to do with $1") |
| 77 | endif |
| 78 | |
| 79 | |
Jerome Forissier | aaac098 | 2014-08-18 19:19:36 +0200 | [diff] [blame] | 80 | comp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 81 | $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ |
| 82 | $$(cppflags-remove-$2), \ |
| 83 | $$(nostdinc) $$(CPPFLAGS) \ |
| 84 | $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \ |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 85 | $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$2))) \ |
| 86 | $$(addprefix -I,$$(incdirs-$2)) \ |
| 87 | $$(cppflags$$(comp-sm-$2)) \ |
| 88 | $$(cppflags-lib$$(comp-lib-$2)) $$(cppflags-$2)) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 89 | |
| 90 | comp-cmd-$2 = $$(CC) $$(comp-flags-$2) -c $$< -o $$@ |
| 91 | |
| 92 | -include $$(comp-cmd-file-$2) |
| 93 | -include $$(comp-dep-$2) |
| 94 | |
| 95 | |
| 96 | $2: $1 FORCE |
| 97 | # Check if any prerequisites are newer than the target and |
| 98 | # check if command line has changed |
| 99 | $$(if $$(strip $$? $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \ |
| 100 | $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \ |
| 101 | @set -e ;\ |
| 102 | mkdir -p $$(dir $2) ;\ |
Jerome Forissier | 0047cb6 | 2014-09-01 13:41:48 +0200 | [diff] [blame] | 103 | echo ' CC $$@' ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 104 | $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\ |
| 105 | $$(comp-cmd-$2) ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 106 | echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \ |
| 107 | $$(comp-cmd-file-$2) ;\ |
| 108 | ) |
| 109 | |
| 110 | endef |
| 111 | |
| 112 | $(foreach f, $(srcs), $(eval $(call \ |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 113 | process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o))) |