]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - common.mk
Add target specific pinmux for TMS570_HYDCTR
[pes-rpp/rpp-lib.git] / common.mk
1 # Common GNU Make definitions useful for multiple Makefiles
2
3 ECLIPSE=$(foreach file,\
4                   /opt/ti/ccsv5/eclipse/eclipse \
5                   C:/ti/ccsv5/eclipse/eclipsec.exe,\
6             $(if $(wildcard $(file)),$(file)))
7
8 ifeq ($(OS),Windows_NT)
9 TMP_WORKSPACE=$(TEMP)/_workspace
10 else
11 TMP_WORKSPACE:=$(shell mktemp --dry-run --tmpdir -d rpp-test-sw-workspace.XXXXXXXXXX)
12 endif
13
14
15 ifeq ($(OS),Windows_NT)
16 pathconv=$(subst /,\,$1)
17 mkdir=-mkdir $(subst /,\,$1)
18 rm=-del /Q $(call pathconv,$1)
19 rmdir=-rmdir /S /Q $(call pathconv,$1)
20 cp=copy $(subst /,\,$1) $(subst /,\,$2)
21 # Always use cmd.exe, ignore sh.exe if there is one
22 SHELL=cmd.exe
23 else
24 pathconv=$1
25 mkdir=mkdir -p $1
26 rm=rm -rf $1
27 rmdir=-rm -rf $1
28 cp=cp $1 $2
29 endif
30
31 # `make release` can ignore files without certain git attribute
32 RELEASE_IGNORE_FILES_CMD = $(strip $(if $(RELEASE_ATTR),\
33         git ls-files | git check-attr --stdin $(RELEASE_ATTR)|awk -F: '!/$(RELEASE_ATTR): set$$/ {print $$1}',\
34         $(if $(filter RELEASE_ATTR,$(.VARIABLES)),,$(error Please specify RELEASE_ATTR variable (it can be empty)))))
35
36 # Usage: $(call release_rules,<release_prefix>)
37 define release_rules
38 RELEASE_COMMIT = HEAD
39 RELEASE_PREFIX = $(1)
40 $$(if $$(RELEASE_PREFIX),,$$(error Call release_rules with prefix as an argument))
41 ifneq ($(OS),Windows_NT)
42 RELEASE_VERSION := $$(shell git describe --always $$(RELEASE_COMMIT)|sed -e "s/^[-a-zA-Z_]*//")
43 endif
44 RELEASE_BASENAME = $$(RELEASE_PREFIX)-$$(RELEASE_VERSION)
45
46 .PHONY: $$(RELEASE_BASENAME).zip .git/info/attributes
47
48 .git/info/attributes: A = $$(shell git rev-parse --git-dir)/info/attributes
49 .git/info/attributes:
50 # Ensure that attributes do not exist or are generated by us
51         test ! -e $$A || head -n 1 $$A | grep -F "Automatically generated (yoo9jei6Ee6Teiti)"
52         echo "# Automatically generated (yoo9jei6Ee6Teiti)" > $$A
53 # Write ignored files there
54         for i in `$$(RELEASE_IGNORE_FILES_CMD)`; do echo $$$$i export-ignore >> $$A; echo Not releasing $$$$i; done
55
56 $$(RELEASE_BASENAME).zip:
57         rm -rf $$@ $$(RELEASE_BASENAME)
58         $(MAKE) $$(RELEASE_BASENAME)
59         find $$(RELEASE_BASENAME) -type d -empty -print -delete
60         zip  -r $$@ $$(RELEASE_BASENAME)
61
62 $$(RELEASE_BASENAME):: .git/info/attributes
63         git archive --worktree-attributes --prefix=$$@/ $$(RELEASE_COMMIT) | tar xf -
64
65 print-release-basename:
66         @echo $$(RELEASE_BASENAME)
67 endef
68
69 # Case conversion macros. Taken from
70 # http://git.buildroot.net/buildroot/tree/package/pkg-utils.mk. This
71 # is inspired by the 'up' macro from gmsl (http://gmsl.sf.net). It is
72 # optimised very heavily because these macros are used a lot. It is
73 # about 5 times faster than forking a shell and tr.
74 #
75 # The caseconvert-helper creates a definition of the case conversion macro.
76 # After expansion by the outer $(eval ), the UPPERCASE macro is defined as:
77 # $(strip $(eval __tmp := $(1))  $(eval __tmp := $(subst a,A,$(__tmp))) ... )
78 # In other words, every letter is substituted one by one.
79 #
80 # The caseconvert-helper allows us to create this definition out of the
81 # [FROM] and [TO] lists, so we don't need to write down every substition
82 # manually. The uses of $ and $$ quoting are chosen in order to do as
83 # much expansion as possible up-front.
84 #
85 # Note that it would be possible to conceive a slightly more optimal
86 # implementation that avoids the use of __tmp, but that would be even
87 # more unreadable and is not worth the effort.
88
89 [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 - .
90 [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 _ _
91
92 define caseconvert-helper
93 $(1) = $$(strip \
94         $$(eval __tmp := $$(1))\
95         $(foreach c, $(2),\
96                 $$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\
97         $$(__tmp))
98 endef
99
100 $(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO]))))
101 $(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))