From: Michal Sojka Date: Wed, 8 Jul 2015 17:01:58 +0000 (+0200) Subject: Makefile: Construct -DTARGET_ automatically X-Git-Tag: eaton-0.5.5~52 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/commitdiff_plain/bcc51b05171e724172a568ca7e76093ddb117c66 Makefile: Construct -DTARGET_ automatically This will help us when compiling documentation for rpp-test-sw commands. --- diff --git a/build/Makefile.rules.arm b/build/Makefile.rules.arm index b818520..cb4d9dd 100644 --- a/build/Makefile.rules.arm +++ b/build/Makefile.rules.arm @@ -40,9 +40,15 @@ LD=$(CC) # Include definition of $(rpp_lib_INCLUDES) include $(makefile_rules_arm_dir)/../Makefile.var +# Include UPPERCASE function +include $(makefile_rules_dir)/../common.mk + # Construct target specific CFLAGS. Start from what's in Makefile.config. RPP_TARGET_CFLAGS = $(TARGET_CFLAGS) +# Add -DTARGET_ +RPP_TARGET_CFLAGS += -DTARGET_$(call UPPERCASE,$(TARGET)) + # Then add -DTARGET_HAS_xxx for each make variable named TARGET_HAS_* # having value 'y' TARGET_HAS_NAMES = $(filter TARGET_HAS_%,$(.VARIABLES)) diff --git a/build/Makefile.rules.posix b/build/Makefile.rules.posix index a5d9e76..ea9cbe3 100644 --- a/build/Makefile.rules.posix +++ b/build/Makefile.rules.posix @@ -15,7 +15,7 @@ makefile_rules_posix_dir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) -ifeq ($(TARGET_CFLAGS),) +ifeq ($(filter TARGET_CFLAGS,$(.VARIABLES)),) $(error "Makefile.config must be included before this file") endif @@ -26,7 +26,10 @@ LD=$(CC) # Include definition of $(rpp_lib_INCLUDES) include $(makefile_rules_posix_dir)/../Makefile.var -RPP_CFLAGS = $(rpp_lib_INCLUDES:%=-I$(makefile_rules_posix_dir)/../%) $(TARGET_CFLAGS) +# Include UPPERCASE function +include $(makefile_rules_dir)/../common.mk + +RPP_CFLAGS = $(rpp_lib_INCLUDES:%=-I$(makefile_rules_posix_dir)/../%) $(TARGET_CFLAGS) -DTARGET_$(call UPPERCASE,$(TARGET)) RPP_MAKE_CFLAGS = \ -MD -MF $@.dep -MP -MT $@ diff --git a/build/posix/Makefile.config b/build/posix/Makefile.config index ea4b068..2db47a5 100644 --- a/build/posix/Makefile.config +++ b/build/posix/Makefile.config @@ -1,5 +1,5 @@ rpp_lib_OS = 6.0.4_posix TARGET = posix -TARGET_CFLAGS = -DTARGET_POSIX +TARGET_CFLAGS = TARGET_HAS_DMM = n diff --git a/build/rm48_hdk/Makefile.config b/build/rm48_hdk/Makefile.config index a5e6016..f9bdf39 100644 --- a/build/rm48_hdk/Makefile.config +++ b/build/rm48_hdk/Makefile.config @@ -1,5 +1,5 @@ TARGET = rm48_hdk -TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi -me -DTARGET_RM48_HDK +TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi -me TARGET_LDCMD = RM48L952FlashLnk.cmd TARGET_LDLIBS = --library=rtsv7R4_T_le_v3D16_eabi.lib TARGET_CCXML = RM48L952-XDS100v2.ccxml diff --git a/build/tms570_hdk/Makefile.config b/build/tms570_hdk/Makefile.config index 3782b55..e68c9ee 100644 --- a/build/tms570_hdk/Makefile.config +++ b/build/tms570_hdk/Makefile.config @@ -1,5 +1,5 @@ TARGET = tms570_hdk -TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi -DTARGET_TMS570_HDK +TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi TARGET_LDCMD = TMS570LS313xFlashLnk.cmd TARGET_LDLIBS = --library="rtsv7R4_T_be_v3D16_eabi.lib" TARGET_CCXML = TMS570LS3137.ccxml diff --git a/build/tms570_hydctr/Makefile.config b/build/tms570_hydctr/Makefile.config index 77366dd..6e6a3ba 100644 --- a/build/tms570_hydctr/Makefile.config +++ b/build/tms570_hydctr/Makefile.config @@ -1,5 +1,5 @@ TARGET = tms570_hydctr -TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi -DTARGET_TMS570_HYDCTR +TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi TARGET_LDCMD = TMS570LS1227FlashLnk.cmd TARGET_LDLIBS = --library="rtsv7R4_T_be_v3D16_eabi.lib" TARGET_CCXML = TMS570LS1227.ccxml diff --git a/build/tms570_rpp/Makefile.config b/build/tms570_rpp/Makefile.config index 34f3c67..0726eae 100644 --- a/build/tms570_rpp/Makefile.config +++ b/build/tms570_rpp/Makefile.config @@ -1,5 +1,5 @@ TARGET = tms570_rpp -TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi -DTARGET_TMS570_RPP +TARGET_CFLAGS = -mv7R4 --code_state=32 --float_support=VFPv3D16 --abi=eabi TARGET_LDCMD = TMS570LS313xFlashLnk.cmd TARGET_LDLIBS = --library="rtsv7R4_T_be_v3D16_eabi.lib" TARGET_CCXML = TMS570LS3137.ccxml diff --git a/common.mk b/common.mk index 4e08abe..ef3818d 100644 --- a/common.mk +++ b/common.mk @@ -64,3 +64,37 @@ $$(RELEASE_BASENAME):: .git/info/attributes print-release-basename: @echo $$(RELEASE_BASENAME) endef + +# Case conversion macros. Taken from +# http://git.buildroot.net/buildroot/tree/package/pkg-utils.mk. This +# is inspired by the 'up' macro from gmsl (http://gmsl.sf.net). It is +# optimised very heavily because these macros are used a lot. It is +# about 5 times faster than forking a shell and tr. +# +# The caseconvert-helper creates a definition of the case conversion macro. +# After expansion by the outer $(eval ), the UPPERCASE macro is defined as: +# $(strip $(eval __tmp := $(1)) $(eval __tmp := $(subst a,A,$(__tmp))) ... ) +# In other words, every letter is substituted one by one. +# +# The caseconvert-helper allows us to create this definition out of the +# [FROM] and [TO] lists, so we don't need to write down every substition +# manually. The uses of $ and $$ quoting are chosen in order to do as +# much expansion as possible up-front. +# +# Note that it would be possible to conceive a slightly more optimal +# implementation that avoids the use of __tmp, but that would be even +# more unreadable and is not worth the effort. + +[FROM] := a b c d e f g h i j k l m n o p q r s t u v w x y z - . +[TO] := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ _ + +define caseconvert-helper +$(1) = $$(strip \ + $$(eval __tmp := $$(1))\ + $(foreach c, $(2),\ + $$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\ + $$(__tmp)) +endef + +$(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO])))) +$(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))