generic makefile to create multiple executable using different flags -


i create generic makefile builds several executables using different compiler flags each executable without using shell commands. executable file name should composed source file , unique post fixed name. should produce assembly or preprocessor file per source file if needed. target bin_bdg_files, "$<" (exercise-1.1.0.c ) first item list (exercise-1.1.0.c exercise-1.1.1.c exercise-1.2.0.c exercise-1.2.1.c) expected. tried without success modify src_files using filter-out function. intent remove first item list each target, first item corresponds correct target. not sure correct approach. comments welcome.

i.e. attempt @ using built in make constructs.

$(bin_dbg_files): $(src_files)     $(cc) $(dbg_cflags) $(iflags) $< -o $@     echo src_files := $(filter-out $<, $(src_files)) 

makefile

shell           = bash  src_files       = $(wildcard *.c) bin_files       = $(patsubst %.c,%,$(src_files)) bin_dbg_files   = $(patsubst %.c,%-dbg,$(src_files)) src_pre         = $(patsubst %.c,%-pre,$(src_files))  cc              = gcc  warnings       := -wall cflags          = -o2 -std=c99 $(warnings) dbg_cflags      = -g -o -std=c99 $(warnings) pre_flag        = -e iflags          = -i.  all: $(bin_files) $(bin_dbg_files) mk-bash  $(bin_dbg_files): $(src_files)     $(cc) $(dbg_cflags) $(iflags) $< -o $@  mk-bash::     src in $(src_files); \             echo $(cc) $(dbg_cflags) $(iflags) $$src -o $${src%.c}-dbg; \             $(cc) $(dbg_cflags) $(iflags) $$src -o $${src%.c}-dbg; \             $(cc) $(dbg_cflags) $(iflags) $$src -o $${src%.c}-dbg; \             $(cc) $(pre_flag) $$src > $${src%.c}-pre; \     done  clean:     rm -f $(bin_files) *-dbg *-pre   

this output executing make command.

this output target bin_files.

gcc -o2 -std=c99 -wall    exercise-1.1.0.c   -o exercise-1.1.0  gcc -o2 -std=c99 -wall    exercise-1.1.1.c   -o exercise-1.1.1  gcc -o2 -std=c99 -wall    exercise-1.2.0.c   -o exercise-1.2.0  gcc -o2 -std=c99 -wall    exercise-1.2.1.c   -o exercise-1.2.1 

this output target bin_dbg_files uses first source file on list build targets. should use appropriate file (exercise-1.1.1.c) build each target file (exercise-1.1.1-dbg).

gcc -g -o -std=c99 -wall -i. **exercise-1.1.0.c** -o exercise-1.1.0-dbg  gcc -g -o -std=c99 -wall -i. **exercise-1.1.0.c** -o exercise-1.1.1-dbg  gcc -g -o -std=c99 -wall -i. **exercise-1.1.0.c** -o exercise-1.2.0-dbg  gcc -g -o -std=c99 -wall -i. **exercise-1.1.0.c** -o exercise-1.2.1-dbg 

this output target mk-bash using shell commands.

for src in exercise-1.1.0.c exercise-1.1.1.c exercise-1.2.0.c exercise-1.2.1.c; \     echo gcc -g -o -std=c99 -wall -i. $src -o ${src%.c}-dbg; \     gcc -g -o -std=c99 -wall -i. $src -o ${src%.c}-dbg; \     gcc -g -o -std=c99 -wall -i. $src -o ${src%.c}-dbg; \     gcc -e $src > ${src%.c}-pre; \ done 

output:

gcc -g -o -std=c99 -wall -i. exercise-1.1.0.c -o exercise-1.1.0-dbg  gcc -g -o -std=c99 -wall -i. exercise-1.1.1.c -o exercise-1.1.1-dbg  gcc -g -o -std=c99 -wall -i. exercise-1.2.0.c -o exercise-1.2.0-dbg  gcc -g -o -std=c99 -wall -i. exercise-1.2.1.c -o exercise-1.2.1-dbg 

use pattern rule:

dbg: $(bin_dbg_files)  %-dbg: %.c     @echo $(cc) $(dbg_cflags) $(iflags) $< -o $@ 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -