############################################################################### # File: TOOLSET/AVR32_GNU.rul[e] # Contents: AVR32_GNU rules # ############################################################################### ############################################################################### #.. Remove "undef" warnings # cc_includes += cc_defines += cxx_includes += cxx_defines += as_includes += as_defines += GCC_MACHINE = $(shell $(GCC_CC) -dumpmachine) GCC_VERSION = $(shell $(GCC_CC) -dumpversion) ############################################################################### #.. Toolset defaults # mkdepend is a lot faster that gcc # USE_GCCDEPEND = 0 ############################################################################### #.. Parse user options # Global options already parsed # These options extend the global options # ifdef OPTIONS ifneq "$(findstring metrics,$(OPTIONS))" "" # Build source metrixs USE_METRICS = 1 endif ifneq "$(findstring profile,$(OPTIONS))" "" USE_PROFILE = 1 endif ifneq "$(findstring ccdepend,$(OPTIONS))" "" # Build depends using gcc USE_GCCDEPEND = 1 endif ifneq "$(findstring gccdepend,$(OPTIONS))" "" USE_GCCDEPEND = 1 endif ifneq "$(findstring mkdepend,$(OPTIONS))" "" USE_GCCDEPEND = 0 endif ifneq "$(findstring wall,$(OPTIONS))" "" # Enable all warnings USE_WALL = 1 endif endif #OPTIONS ############################################################################### #.. C and C++ Compiler warning filter # cc_filter_name := warnings.avr32 cc_filter := "$(notdir $(wildcard $(GBE_ROOT)/$(cc_filter_name)))" ifeq ($(strip $(cc_filter)),"$(cc_filter_name)") cc_filter := $(GBE_ROOT)/$(cc_filter_name) else cc_filter := endif ifdef cc_filter cc_redirect_stderr = 1 cc_error_filter = $(awk) -f $(cc_filter) endif ############################################################################### #.. C Compiler definition # # Standard defines # #.. ifdef GCC_DEFINES gcc_defines += $(GCC_DEFINES) endif ifeq "$(DEBUG)" "1" gcc_defines += -DDEBUG else gcc_defines += endif gcc_defines += -D__SOURCE__=\"$(notdir $<)\" gcc_conly_flags = # # Target specific flags # gcc_flags += -ffunction-sections gcc_flags += -masm-addr-pseudos gcc_flags += -mno-cond-exec-before-reload gcc_flags += -mrelax gcc_conly_flags += -std=gnu99 gcc_flags += -mpart=$(AVR32_PART) # Standard flags # # -Wall implies: # -Wimplicit, -Wreturn-type, -Wunused, -Wswitch # -Wformat, -Wchar-subscripts, -Wparentheses # -Wmissing-braces #.. gcc_flags += -c gcc_flags += -Wall gcc_conly_flags += -Werror-implicit-function-declaration gcc_conly_flags += -Wmissing-prototypes gcc_flags += -Wpointer-arith gcc_conly_flags += -Wstrict-prototypes ifdef USE_WALL #gcc_flags += -Wuninitialized # only makes sense with `-O' gcc_flags += -Wwrite-strings gcc_flags += -Wcast-qual gcc_flags += -Wbad-function-cast gcc_flags += -Wmissing-declarations gcc_flags += -Wnested-externs gcc_flags += -Wtraditional gcc_flags += -Wconversion gcc_flags += -Wcomment gcc_flags += -Wcast-align #gcc_flags += -Winline gcc_flags += -Wshadow gcc_flags += -Wredundant-decls #gcc_flags += -Wid-clash-31 endif ifdef GCC_CFLAGS gcc_flags += $(GCC_CFLAGS) endif ifdef FORCE_C_COMPILE endif ifdef FORCE_CC_COMPILE endif ifdef USE_OPTIMISE # default for production gcc_flags += -O1 else endif ifdef USE_DEBUGINFO # default for debug gcc_flags += -g3 -ggdb else gcc_flags += -g3 -ggdb endif ifeq "$(DEBUG)" "1" # debug/prod specific ifdef GCC_CFLAGSD gcc_flags += $(GCC_CFLAGSD) endif else ifdef GCC_CFLAGSP gcc_flags += $(GCC_CFLAGSP) endif endif ifdef USE_STRICT_ANSI # default NO gcc_flags += -ansi endif ifdef USE_PROFILE # default NO gcc_flags += -pg endif ifdef LEAVETMP # default NO gcc_flags += -save-temps endif ifdef WARNINGS_AS_ERRORS gcc_flags += -Werror endif # Standard includes # #.. gcc_includes += ifdef GCC_INCLUDES gcc_includes += $(GCC_INCLUDES) endif # Command # #.. cc = $(CC_PRE) $(GCC_CC) cc_init = cc_o_switch = -o $@ cc_source = $< cc_flags = \ $(patsubst %,%,$(CFLAGS)) \ $(patsubst %,%,$(gcc_flags)$(gcc_conly_flags)) \ $(patsubst %,%,$(gcc_defines)) \ $(patsubst %,-D%,$(cc_defines)) \ $(patsubst %,-I %,$(INCDIRS)) \ $(patsubst %,-I %,$(cc_includes)) \ $(patsubst %,-I %,$(gcc_includes)) cc_term = define cc_pre @echo '[$<] compiling..' endef ifdef USE_METRICS define cc_post $(cc) -E $(cc_flags) $(cc_source) | mcstrip | cyclo -c > $(basename $@).met endef else define cc_post endef endif ############################################################################### #.. C/C++ dependencies # # Additional defines # #.. gcc_depend += ifeq ($(USE_GCCDEPEND),0) # Build GCC predefs and default include paths #.. gcc_depend += -D__GNUC__=$(word 1,$(subst .,$(space),$(GCC_VERSION))) gcc_depend += -D__GNUC_MINOR__=$(word 2,$(subst .,$(space),$(GCC_VERSION))) gcc_depend += -D__STDC__ -D__STDC_HOSTED__ # Definitions set by the GCC compiler # See them with the command: /opt/avr32-gnu-toolchain-linux_x86/bin/avr32-gcc -dM -E - < /dev/null | sort # gcc_depend += -D__avr32__ -D__AVR32__ -D__ELF__ gcc_depend += -Y $(GBE_AVR32_GNU)/lib/gcc/$(GCC_MACHINE)/$(GCC_VERSION)/include gcc_depend += -Y $(GBE_AVR32_GNU)/$(GCC_MACHINE)/include gcc_depend += -Y $(GBE_AVR32_GNU)/include endif ifdef GCC_DEPEND gcc_depend += $(GCC_DEPEND) endif # Command # #.. ifeq ($(USE_GCCDEPEND),0) ccdep = $(XX_PRE) $(GBE_BIN)/mkdepend ccdep_init = ccdep_o_switch = -f - ccdep_flags = -MM -b -We -p '$$(OBJDIR)/' -o ".$(o)" ccdep_source = $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err else ccdep = -$(XX_PRE) $(GCC_CC) ccdep_init = ccdep_o_switch = ccdep_flags = -E -MM -MG ccdep_source = $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err endif ccdep_flags += \ $(patsubst %,%,$(CFLAGS)) \ $(patsubst %,%,$(gcc_depend)) \ $(patsubst %,%,$(gcc_defines)) \ $(patsubst %,-D%,$(cc_defines)) \ $(patsubst %,-I %,$(INCDIRS)) \ $(patsubst %,-I %,$(cc_includes)) ifeq ($(USE_GCCDEPEND),0) ccdep_flags += \ $(patsubst %,-Y %,$(gcc_includes)) endif # # Parse the depend output: # # s/^.*/\(.*\.${o}\:\)/$(OBJDIR)/\1/g # replace all object rules which contain / seperated # subdirs with a stripped prefixed object name. # # eg. subdir/dir/object.o: $(OBJDIR)/object.o # # s/^\([^/].*\.${o}\:\)/$(OBJDIR)/\1/g # prefix all object rules without subdirs. # # eg. object.o: $(OBJDIR)/object.o #.. ccdep_pre = ccdep_sed = \ -sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \ -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \ $(subst /,/,$@).tmp > $@ 2> $(OBJDIR)/depend.err; ifdef SHNAMES ccdep_sedsh = \ sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \ -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \ $(subst /,/,$@).tmp >> $@ 2>> $(OBJDIR)/depend.err; ccdep_sed += \ $(foreach shname,$(SHNAMES),$(ccdep_sedsh)) endif ifndef LEAVETMP define ccdep_post @$(ccdep_sed) @rm $(subst /,/,$@).tmp endef else define ccdep_post @$(ccdep_sed) endef endif #.. C++ Compiler definition # ifdef USE_CHECKER cxx = @checkergcc else cxx = $(CC_PRE) $(GCC_CC) endif cxx_init = cxx_o_switch = -o $@ cxx_source = $< cxx_flags = \ $(patsubst %,%,$(CXXFLAGS)) \ $(patsubst %,%,$(gcc_flags)) \ $(patsubst %,%,$(gcc_defines)) \ $(patsubst %,-d%,$(cxx_defines)) \ $(patsubst %,-I %,$(INCDIRS)) \ $(patsubst %,-I %,$(cxx_includes)) \ $(patsubst %,-I %,$(gcc_includes)) define cxx_pre @echo '[$<] compiling..' endef define cxx_post endef ############################################################################### #.. Archiver definition # #.. Archiver # ar = $(XX_PRE) $(GCC_AR) ar_o_switch = ar_flags = -scr $@ \ $(patsubst %,%,$^) define ar_pre @echo '[$@] Create archive..' endef define ar_post endef #.. Archive Merge # armerge = $(XX_PRE) $(GBE_TOOLS)/armerge armerge_init = armerge_flags = -d $(MLIBDIR) -t unix -a $(GCC_AR) armerge_o_switch= $@ $^ armerge_pre = -$(rm) -f $@ armerge_post = ############################################################################### #.. Linker definition # #.. Linker # ld = $(CC_PRE) $(GCC_CC) ld_init = ld_o_switch = -o $@ ld_flags += -Xlinker -Map '$(basename $@).map' ifeq "$(DEBUG)" "1" ld_flags += -g endif ifdef USE_PROFILE ld_flags += -pg endif ld_flags += \ $(patsubst %,%,$(LDFLAGS)) \ $(patsubst %,%,$(GCC_LDFLAGS)) \ $(patsubst %,-L%,$(wildcard $(LIBDIRS))) \ $(patsubst %,-Xlinker -rpath-link %,$(wildcard $(LIBDIRS))) \ $($(notdir $(basename $@))_ld) define ld_pre @echo '[$@] Linking..'; \ $(touch) $(basename $@).map endef define ld_post endef define LDDEPEND $(AA_PRE)export GCC_LIB; \ GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \ $(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))" endef ############################################################################### # ELF2BIN # $1 - Full name of the output # $2 - Full name of elf file define ELF2BIN $(echo) "[$1] Elf to Binary Conversion.." $(GCC_OBJCOPY) -O binary $2 $1 || rm -f $1 $2 endef