Commit a7947759 authored by Ben Avison's avatar Ben Avison Committed by ROOL
Browse files

Support application and module targets with differing compiler flags

Typically useful for libraries where you have both types of target, and you
want the application build to contain function names (for meaningful
backtraces) but the module build not to (to save ROM space). This is
achieved as follows:

* CAPPFLAGS and CMODFLAGS contain additional flags to be passed to application
  and module builds, respectively

* C_FNAMES is initialised to a compiler-agnostic build switch to enable
  function names in the binary

Therefore a master makefile will often use the line
CAPPFLAGS = ${C_FNAMES}
although CAPPFLAGS and CMODFLAGS are not limited to this usage.
parent 51f761a1
......@@ -18,10 +18,10 @@ endif
# C source files -> object files
.c.od:
${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} -o $@ $<
${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${CAPPFLAGS} -o $@ $<
$(call make-depend,$<,$@,$(subst .od,.dd,$@))
.c.odz:
${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${C_MODULE} -o $@ $<
${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${CMODFLAGS} ${C_MODULE} -o $@ $<
$(call make-depend,$<,$@,$(subst .odz,.ddz,$@))
.c.i:
${CPREPRO} ${CFLAGS} -C $< > $@
......
......@@ -2,9 +2,9 @@
INCLUDED_STDRULES = YES
# $(call make-depend,source,object,depend)
# $(call make-depend,source,object,depend,flags)
define make-depend
@${CC} ${CFLAGS} -M $1 > $3 2> /dev/null
@${CC} ${CFLAGS} $4 -M $1 > $3 2> /dev/null
@${SED} -i -e 's,$(basename $2).o *:,$2:,' $3
endef
......@@ -23,11 +23,11 @@ endif
# C source files -> object files
.c.o:
${CC} ${CFLAGS} -o $@ $<
$(call make-depend,$<,$@,$(subst .o,.d,$@))
${CC} ${CFLAGS} ${CAPPFLAGS} -o $@ $<
$(call make-depend,$<,$@,$(subst .o,.d,$@),${CAPPFLAGS})
.c.oz:
${CC} ${CFLAGS} ${C_MODULE} -o $@ $<
$(call make-depend,$<,$@,$(subst .oz,.dz,$@))
${CC} ${CFLAGS} ${CMODFLAGS} ${C_MODULE} -o $@ $<
$(call make-depend,$<,$@,$(subst .oz,.dz,$@),${CMODFLAGS})
# C++ source files -> object files
.c++.o:
......
......@@ -172,6 +172,7 @@ else
C_NO_STKCHK := -mno-apcs-stack-check
C_STKCHK := -mapcs-stack-check
C_NO_FNAMES := -mno-poke-function-name
C_FNAMES := -mpoke-function-name
C_MODULE := -mmodule
CFLAGS += -mlibscl
C++FLAGS += -mlibscl
......@@ -194,6 +195,7 @@ C_NO_ZI := -zz100000
C_NO_STKCHK := -zps1
C_STKCHK := -zps0
C_NO_FNAMES := -ff
C_FNAMES := -fn
C_MODULE := -zM
C_NOWARN_ASSIGNMENT_AS_CONDITION := -Wa
C_NOWARN_NON_ANSI_INCLUDES := -Wp
......
......@@ -29,8 +29,8 @@ LDDFLAGS += -d
.SUFFIXES: .i .od .odz .s .c .h .c++ .cpp
# C source files -> object files
.c.od:; ${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} -o $@ $<
.c.odz:; ${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${C_MODULE} -o $@ $<
.c.od:; ${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${CAPPFLAGS} -o $@ $<
.c.odz:; ${CC} $(filter-out ${C_NO_FNAMES},${CFLAGS}) ${CDFLAGS} ${CMODFLAGS} ${C_MODULE} -o $@ $<
.c.i:; ${CPREPRO} ${CFLAGS} -C $< > $@
# C++ source files -> object files
......
......@@ -24,8 +24,8 @@ INCLUDED_STDRULES = YES
.SUFFIXES: .o .oz .s .c .h .c++ .cpp
# C source files -> object files
.c.o:; ${CC} ${CFLAGS} -o $@ $<
.c.oz:; ${CC} ${CFLAGS} ${C_MODULE} -o $@ $<
.c.o:; ${CC} ${CFLAGS} ${CAPPFLAGS} -o $@ $<
.c.oz:; ${CC} ${CFLAGS} ${CMODFLAGS} ${C_MODULE} -o $@ $<
# C++ source files -> object files
.c++.o:; ${C++} ${C++FLAGS} -o $@ $<
......
......@@ -122,6 +122,7 @@ C_NO_ZI := -zz100000
C_NO_STKCHK := -zps1
C_STKCHK := -zps0
C_NO_FNAMES := -ff
C_FNAMES := -fn
C_MODULE := -zM
C_NOWARN_ASSIGNMENT_AS_CONDITION := -Wa
C_NOWARN_NON_ANSI_INCLUDES := -Wp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment