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 |
Jerome Forissier | fe52b1f | 2014-11-06 17:54:51 +0100 | [diff] [blame] | 5 | # conf-file [optional] if set, all objects will depend on $(conf-file) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 6 | # |
| 7 | # Output |
| 8 | # |
| 9 | # set objs |
| 10 | # update cleanfiles |
| 11 | # |
| 12 | # Generates explicit rules for all objs |
| 13 | |
| 14 | objs := |
| 15 | |
| 16 | # Disable all builtin rules |
| 17 | .SUFFIXES: |
| 18 | |
| 19 | comp-cflags$(sm) = -std=gnu99 |
| 20 | comp-aflags$(sm) = |
| 21 | comp-cppflags$(sm) = |
| 22 | |
| 23 | ifndef NOWERROR |
| 24 | comp-cflags$(sm) += -Werror |
| 25 | endif |
| 26 | comp-cflags$(sm) += -fdiagnostics-show-option |
| 27 | |
| 28 | comp-cflags-warns-high = \ |
| 29 | -Wall -Wcast-align \ |
| 30 | -Werror-implicit-function-declaration -Wextra -Wfloat-equal \ |
| 31 | -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \ |
| 32 | -Wmissing-declarations -Wmissing-format-attribute \ |
| 33 | -Wmissing-include-dirs -Wmissing-noreturn \ |
| 34 | -Wmissing-prototypes -Wnested-externs -Wpointer-arith \ |
| 35 | -Wshadow -Wstrict-prototypes -Wswitch-default \ |
| 36 | -Wwrite-strings \ |
| 37 | -Wno-missing-field-initializers -Wno-format-zero-length |
| 38 | comp-cflags-warns-medium = \ |
| 39 | -Waggregate-return -Wredundant-decls |
| 40 | comp-cflags-warns-low = \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 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 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 53 | CHECK ?= sparse |
| 54 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 55 | .PHONY: FORCE |
| 56 | FORCE: |
| 57 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 58 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 59 | define process_srcs |
| 60 | objs += $2 |
| 61 | comp-dep-$2 := $$(dir $2).$$(notdir $2).d |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 62 | comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd |
| 63 | comp-sm-$2 := $(sm) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 64 | comp-lib-$2 := $(libname) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 65 | |
| 66 | cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2 |
| 67 | |
| 68 | ifeq ($$(filter %.c,$1),$1) |
Jerome Forissier | 76f5987 | 2014-11-03 17:03:28 +0100 | [diff] [blame] | 69 | comp-q-$2 := CC |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 70 | comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ |
| 71 | $$(cflags-remove-$2), \ |
| 72 | $$(CFLAGS) $$(CFLAGS_WARNS) \ |
| 73 | $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \ |
Jerome Forissier | 3d34e12 | 2014-10-30 17:37:42 +0100 | [diff] [blame] | 74 | $$(cflags-lib$$(comp-lib-$2)) $$(cflags-$2)) |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 75 | ifeq ($C,1) |
| 76 | check-cmd-$2 = $(CHECK) $$(comp-cppflags-$2) $$< |
| 77 | echo-check-$2 := $(cmd-echo-silent) |
| 78 | echo-check-cmd-$2 = $(cmd-echo) $$(subst \",\\\",$$(check-cmd-$2)) |
| 79 | endif |
| 80 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 81 | else ifeq ($$(filter %.S,$1),$1) |
Jerome Forissier | 76f5987 | 2014-11-03 17:03:28 +0100 | [diff] [blame] | 82 | comp-q-$2 := AS |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 83 | comp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \ |
| 84 | $$(aflags-remove-$2), \ |
| 85 | $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \ |
| 86 | $$(aflags$$(comp-sm-$2)) $$(aflags-$2)) |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 87 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 88 | else |
| 89 | $$(error "Don't know what to do with $1") |
| 90 | endif |
| 91 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 92 | comp-cppflags-$2 = $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 93 | $$(cppflags-remove-$2), \ |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 94 | $$(nostdinc$$(comp-sm-$2)) $$(CPPFLAGS) \ |
| 95 | $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \ |
| 96 | $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$2))) \ |
| 97 | $$(addprefix -I,$$(incdirs-$2)) \ |
| 98 | $$(cppflags$$(comp-sm-$2)) \ |
| 99 | $$(cppflags-lib$$(comp-lib-$2)) $$(cppflags-$2)) |
| 100 | |
| 101 | comp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ |
| 102 | comp-flags-$2 += $$(comp-cppflags-$2) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 103 | |
Jens Wiklander | 1b4eb4f | 2015-02-02 09:19:18 +0100 | [diff] [blame] | 104 | comp-cmd-$2 = $$(CC$(sm)) $$(comp-flags-$2) -c $$< -o $$@ |
| 105 | comp-objcpy-cmd-$2 = $$(OBJCOPY$(sm)) \ |
Jens Wiklander | 6d6ea54 | 2014-12-02 11:06:01 +0100 | [diff] [blame] | 106 | --rename-section .rodata=.rodata.$1 \ |
| 107 | --rename-section .rodata.str1.1=.rodata.str1.1.$1 \ |
| 108 | $2 |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 109 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 110 | # Assign defaults if unassigned |
| 111 | echo-check-$2 ?= true |
| 112 | echo-check-cmd-$2 ?= true |
| 113 | check-cmd-$2 ?= true |
| 114 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 115 | -include $$(comp-cmd-file-$2) |
| 116 | -include $$(comp-dep-$2) |
| 117 | |
| 118 | |
| 119 | $2: $1 FORCE |
| 120 | # Check if any prerequisites are newer than the target and |
| 121 | # check if command line has changed |
Jerome Forissier | 313ead4 | 2015-01-22 18:17:54 +0100 | [diff] [blame] | 122 | $$(if $$(strip $$(filter-out FORCE, $$?) \ |
| 123 | $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 124 | $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \ |
| 125 | @set -e ;\ |
| 126 | mkdir -p $$(dir $2) ;\ |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 127 | $$(echo-check-$2) ' CHECK $$<' ;\ |
| 128 | $$(echo-check-cmd-$2) ;\ |
| 129 | $$(check-cmd-$2) ;\ |
Jens Wiklander | 6242863 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 130 | $(cmd-echo-silent) ' $$(comp-q-$2) $$@' ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 131 | $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\ |
| 132 | $$(comp-cmd-$2) ;\ |
Jens Wiklander | 6d6ea54 | 2014-12-02 11:06:01 +0100 | [diff] [blame] | 133 | $(cmd-echo) $$(comp-objcpy-cmd-$2) ;\ |
| 134 | $$(comp-objcpy-cmd-$2) ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 135 | echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \ |
| 136 | $$(comp-cmd-file-$2) ;\ |
| 137 | ) |
| 138 | |
| 139 | endef |
| 140 | |
| 141 | $(foreach f, $(srcs), $(eval $(call \ |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 142 | process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o))) |
Jerome Forissier | fe52b1f | 2014-11-06 17:54:51 +0100 | [diff] [blame] | 143 | |
Jens Wiklander | bc42074 | 2015-05-05 14:59:15 +0200 | [diff] [blame^] | 144 | # Handle generated source files, that is, files that are compiled from out-dir |
| 145 | $(foreach f, $(gen-srcs), $(eval $(call \ |
| 146 | process_srcs,$(out-dir)/$(f),$(out-dir)/$(base-prefix)$$(basename $f).o))) |
| 147 | |
Jerome Forissier | fe52b1f | 2014-11-06 17:54:51 +0100 | [diff] [blame] | 148 | $(objs): $(conf-file) |