0
votes

yesterday I wrote a Makefile to build a Programm which works fine. Now, I try to build different build configurations.

What is the recommended way to build different configurations which differ in the list of source files and output paths?

I tried to use target specific variables...

Executables of the compiler toolchain.

COMPILER := ccrl LINKER := rlink ASSEMBLER := asrl

DEVICE_FILE := DR5F100LL.DVF

Compiler flags used to generate *.d files.

DFLAGS := \ -MM \ -MP \ -cpu=S2 \ -dev="$(DEVICE_FILE)" \ -no_warning_num=11179,11180 \ -g \ -Onothing

Compiler flags used to generate *.obj files from c source files.

CFLAGS := \ -cpu=S2 \ -c \ -dev="$(DEVICE_FILE)" \ -no_warning_num=11179,11180 \ -g \ -Onothing

Compiler flags used to generate *.obj files from assembler files.

ASMFLAGS := $(CFLAGS)

Linker flags

LDFLAGS := \ -library="${COMPILER_PATH}/lib/rl78cm4s.lib" \ -library="${COMPILER_PATH}/lib/rl78cm4r.lib" \ -library="./FFT_Library/libfft_rl78g13.lib" \ -nooptimize \ -entry=_start \ -security_id=00000000000000000000 \ -ocdbg=04 \ -user_opt_byte=EEFFE9 \ -debug \ -nocompress \ -memory=high \ -vectn=2=ffff \ -rom=.data=.dataR \ -rom=.sdata=.sdataR \ -nomessage \ -device="$(DEVICE_FILE)" \ -nologo \

-start=.const,.text,.RLIB,.SLIB,.textf,.constf,.data,.sdata/03000,.dataR,.bss/0F7F00,.sdataR,.sbss/0FFE20

Include directories

C_INCS := \ -I${COMPILER_PATH}/inc \ ...

C source files used build the program.

C_SRCS_FFT_TEST := \ CodeGenerator/r_cg_cgc.c \ ...

C_SRCS_HISTORY_TEST := \ CodeGenerator/r_cg_cgc.c \ ...

C_SRCS_IOLINK_TEST := \ CodeGenerator/r_cg_cgc.c \ ...

Assembler files used to build the program.

ASM_SRCS := \ ...

Root directories of the build results.

OUT_ROOT_DIR := build PUBLISH_ROOT_DIR := publish

.SECONDEXPANSION:

Name of the build configuration.

BUILD_CONFIG = Unknown

OUT_DIR =$(OUT_ROOT_DIR)/$(BUILD_CONFIG) PUB_DIR =$(PUBLISH_ROOT_DIR)/$(BUILD_CONFIG)

Determine file paths of generated files.

OBJS = $(patsubst %.c,$(OUT_DIR)/%.obj,$(C_SRCS)) OBJS += $(patsubst %.asm,$(OUT_DIR)/%.obj,$(ASM_SRCS)) DEPS = $(OBJS:.obj=.d)

Filenames of the output files.

OUT_FILE = $(PUB_DIR)/MyFile.abs MAP_FILE = $(OUT_DIR)/MyFile.map

.PHONY: build-definitions build-definitions: fft-test history-test iolink-test

fft-test: BUILD_CONFIG=FFT_Test fft-test: C_SRCS=$(C_SRCS_FFT_TEST) .PHONY: fft-test fft-test: $$(OUT_FILE)

history-test: BUILD_CONFIG=History_Test history-test: C_SRCS=$(C_SRCS_HISTORY_TEST) .PHONY: history-test history-test: @echo -e "Building $(BUILD_CONFIG)."

iolink-test: BUILD_CONFIG=IOLink_Test iolink-test: C_SRCS=$(C_SRCS_IOLINK_TEST) .PHONY: iolink-test iolink-test: @echo -e "Building $(BUILD_CONFIG)."

.PHONY: all all: pre-build $(OUT_FILE) post-build

.PHONY: pre-build pre-build: @echo -e "Run pre-build target."

.PHONE: post-build post-build: @echo -e "Run post-build target."

.PHONY: clean clean: @echo -e "Run clean target."
@rm -f -v $(OUT_DIR)/LinkerSubCommand.tmp @rm -f -v $(OBJS) @rm -f -v $(DEPS) @rm -f -v $(OUT_FILE) @rm -f -v $(MAP_FILE)

How to build the dependency file from a c source file.

$(OUT_DIR)/%.d : %.c @echo 'Building d file: $<' @mkdir -p "$(dir $@)" $(COMPILER) $(DFLAGS) $(C_INCS) -o "$(@:%.obj=%.d)" -MT="$@" -MT="$(@:%.obj=%.d)" "$<"

How to build the dependency file from an asm file.

$(OUT_DIR)/%.d : %.asm @echo 'Building d file: $<' @mkdir -p "$(dir $@)" $(COMPILER) $(DFLAGS) $(C_INCS) -o "$(@:%.obj=%.d)" -MT="$@" -MT="$(@:%.obj=%.d)" "$<"

How to build the object file from a c source file.

$(OUT_DIR)/%.obj : %.c @echo 'Building obj file: $<' @mkdir -p "$(dir $@)" $(COMPILER) $(CFLAGS) $(C_INCS) -o "$@" "$<" @echo -e $(@:%=-input=\"%\") >> $(OUT_DIR)/LinkerSubCommand.tmp

How to build the object file from an asm file.

$(OUT_DIR)/%.obj : %.asm @echo 'Building asm file: $<' @mkdir -p "$(dir $@)" $(COMPILER) $(CFLAGS) $(C_INCS) -o "$@" "$<" @echo -e $(@:%=-input=\"%\") >> $$(OUT_DIR)/LinkerSubCommand.tmp

# $(OBJ): %.obj: %.c $(DEPS)

How to build the output file from all object files.

%.abs : $(OBJS) @echo -e "Building $(BUILD_CONFIG)." @echo -e "The output directory is $(OUT_DIR)." @echo -e "The publish directory is $(PUB_DIR)." @echo -e "The source files are $(C_SRCS)." @echo -e "The assembler files are $(ASM_SRCS)." @echo -e "The generated object files are $(OBJS)." @echo -e "Building output file is $@."
@mkdir -p "$(PUB_DIR)" @mkdir -p "$(OUT_DIR)" $(LINKER) $(LDFLAGS) -subcommand="$(OUT_DIR)/LinkerSubCommand.tmp" -list="$(MAP_FILE)" -output="$(OUT_FILE)"

I know that I should use private as scope of the target specific variables but than I have to download/compile a newer make Version...

I would like to know the recommended way to build such configurations. Maybe someone can provide a simple (and complete) example?

Thanks a lot! Michael

1

1 Answers

0
votes

Makefile:

ifeq ($(config), debug)
    CFLAGS := -DDEBUG -g
    OUT_PATH := ./build/debug/
else ifeq ($(config), light_debug)
    CFLAGS := -g
    OUT_PATH := ./build/light_debug/
else #release config by default
    OUT_PATH := ./build/release
endif

#...

Then make invokation is like this:

make confg=debug

or

make config=light_debug

or

make config=release