simplelink.mk (1697B)
1 TOP_DIR ?= . 2 SRC_DIR ?= ${TOP_DIR}/src 3 BUILD_DIR ?= ${TOP_DIR}/build 4 SCRIPTS_DIR ?= ${TOP_DIR}/scripts 5 CONF_DIR ?= ${TOP_DIR}/conf 6 7 shared_executables:=$(patsubst %,$(BUILD_DIR)/bin-shared/%,$(c_executables)) 8 static_executables:=$(patsubst %,$(BUILD_DIR)/bin-static/%,$(c_executables)) 9 .PHONY: shared_executables static_executables 10 shared_executables: $(shared_executables) 11 static_executables: $(static_executables) 12 13 define simplelink = 14 include $$(BUILD_DIR)/$(1)_main.c.deps.mk 15 $$(BUILD_DIR)/bin-shared/$(1): $$(LINKDEP_$(subst -,__,$(1))_main__c) $$(CONF_DIR)/ld.shared $$(BUILD_DIR)/$(1)_main.c.deps.mk $$(BUILD_DIR)/bin-shared/.exists 16 $$(CONF_DIR)/ld.shared -o '$$@' $$(LINKDEP_$(subst -,__,$(1))_main__c) 17 include $$(BUILD_DIR)/$(1)_main.c.deps.mk 18 $$(BUILD_DIR)/bin-static/$(1): $$(LINKDEP_$(subst -,__,$(1))_main__c) $$(CONF_DIR)/ld.static $$(BUILD_DIR)/$(1)_main.c.deps.mk $$(BUILD_DIR)/bin-static/.exists 19 $$(CONF_DIR)/ld.static -o '$$@' $$(LINKDEP_$(subst -,__,$(1))_main__c) 20 endef 21 $(foreach var,$(c_executables),$(eval $(call simplelink,$(var)))) 22 23 ## pattern rules: 24 25 # preprocess C sources 26 $(BUILD_DIR)/%.c.i: $(SRC_DIR)/%.c $(CONF_DIR)/cc $(BUILD_DIR)/.exists 27 $(CONF_DIR)/cc -E -C -o '$@' '$(SRC_DIR)/$*.c' 28 29 # compile preprocessed C sources 30 $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c.i $(CONF_DIR)/cc 31 $(CONF_DIR)/cc -fpreprocessed -c -o '$@' '$(BUILD_DIR)/$*.c.i' 32 33 # extract dependencies from preprocessed sources 34 $(BUILD_DIR)/%.c.deps.mk: $(BUILD_DIR)/%.c.i $(SCRIPTS_DIR)/codedeps.awk 35 awk -v srcname='$*.c' -v target='$(BUILD_DIR)/$*.c.i' -f $(SCRIPTS_DIR)/codedeps.awk '$(BUILD_DIR)/$*.c.i' >'$@.new' 36 mv '$@.new' '$@' 37 38 # create directory if missing 39 %/.exists: 40 mkdir -p '$*' 41 touch '$@'