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 13objs := 14 15# Disable all builtin rules 16.SUFFIXES: 17 18comp-cflags$(sm) = -std=gnu99 19comp-aflags$(sm) = 20comp-cppflags$(sm) = 21 22ifndef NOWERROR 23comp-cflags$(sm) += -Werror 24endif 25comp-cflags$(sm) += -fdiagnostics-show-option 26 27comp-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 37comp-cflags-warns-medium = \ 38 -Waggregate-return -Wredundant-decls 39comp-cflags-warns-low = \ 40 -Wold-style-definition -Wstrict-aliasing=2 \ 41 -Wundef -pedantic \ 42 -Wdeclaration-after-statement 43 44comp-cflags-warns-1:= $(comp-cflags-warns-high) 45comp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium) 46comp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low) 47 48WARNS ?= 3 49 50comp-cflags$(sm) += $(comp-cflags-warns-$(WARNS)) 51 52.PHONY: FORCE 53FORCE: 54 55define process_srcs 56objs += $2 57comp-dep-$2 := $$(dir $2).$$(notdir $2).d 58comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd 59comp-sm-$2 := $(sm) 60 61cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2 62 63ifeq ($$(filter %.c,$1),$1) 64comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ 65 $$(cflags-remove-$2), \ 66 $$(CFLAGS) $$(CFLAGS_WARNS) \ 67 $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \ 68 $$(cflags-$2)) 69else ifeq ($$(filter %.S,$1),$1) 70comp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \ 71 $$(aflags-remove-$2), \ 72 $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \ 73 $$(aflags$$(comp-sm-$2)) $$(aflags-$2)) 74else 75$$(error "Don't know what to do with $1") 76endif 77 78 79comp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ \ 80 $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ 81 $$(cppflags-remove-$2), \ 82 $$(nostdinc) $$(CPPFLAGS) \ 83 $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \ 84 $$(cppflags$$(comp-sm-$2)) $$(cppflags-$2)) 85 86comp-cmd-$2 = $$(CC) $$(comp-flags-$2) -c $$< -o $$@ 87 88-include $$(comp-cmd-file-$2) 89-include $$(comp-dep-$2) 90 91 92$2: $1 FORCE 93# Check if any prerequisites are newer than the target and 94# check if command line has changed 95 $$(if $$(strip $$? $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \ 96 $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \ 97 @set -e ;\ 98 mkdir -p $$(dir $2) ;\ 99 echo ' CC $$@' ;\ 100 $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\ 101 $$(comp-cmd-$2) ;\ 102 echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \ 103 $$(comp-cmd-file-$2) ;\ 104 ) 105 106endef 107 108$(foreach f, $(srcs), $(eval $(call \ 109 process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o))) 110