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