X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/94b23c75f888db90aa24edcb0c8594a5a951a71e..5cdc272011e0d887d1297641a7f9bdcc6173b12d:/common.mk diff --git a/common.mk b/common.mk index 055d302..272b1fd 100644 --- a/common.mk +++ b/common.mk @@ -1,5 +1,7 @@ # Common GNU Make definitions useful for multiple Makefiles +common_mk_dir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) + ECLIPSE=$(foreach file,\ /opt/ti/ccsv5/eclipse/eclipse \ C:/ti/ccsv5/eclipse/eclipsec.exe,\ @@ -18,6 +20,8 @@ mkdir=-mkdir $(subst /,\,$1) rm=-del /Q $(call pathconv,$1) rmdir=-rmdir /S /Q $(call pathconv,$1) cp=copy $(subst /,\,$1) $(subst /,\,$2) +# Always use cmd.exe, ignore sh.exe if there is one +SHELL=cmd.exe else pathconv=$1 mkdir=mkdir -p $1 @@ -26,17 +30,74 @@ rmdir=-rm -rf $1 cp=cp $1 $2 endif +# `make release` can ignore files without certain git attribute +RELEASE_IGNORE_FILES_CMD = $(strip $(if $(RELEASE_ATTR),\ + $(common_mk_dir)/etc/git-ls-files-attr --not $(RELEASE_ATTR),\ + $(if $(filter RELEASE_ATTR,$(.VARIABLES)),,$(error Please specify RELEASE_ATTR variable (it can be empty))))) + +# Usage: $(call release_rules,) +define release_rules RELEASE_COMMIT = HEAD -RELEASE_PREFIX ?= prefix -RELEASE_VERSION := $(shell git describe --always $(RELEASE_COMMIT)|sed -e "s/^[-a-zA-Z_]*//") -RELEASE_BASENAME = $(RELEASE_PREFIX)-$(RELEASE_VERSION) +RELEASE_PREFIX = $(1) +$$(if $$(RELEASE_PREFIX),,$$(error Call release_rules with prefix as an argument)) +ifneq ($(OS),Windows_NT) +RELEASE_VERSION := $$(shell git describe --always $$(RELEASE_COMMIT)|sed -e "s/^[-a-zA-Z_]*//") +endif +RELEASE_BASENAME = $$(RELEASE_PREFIX)-$$(RELEASE_VERSION) + +.PHONY: $$(RELEASE_BASENAME).zip .git/info/attributes + +.git/info/attributes: A = $$(shell git rev-parse --git-dir)/info/attributes +.git/info/attributes: +# Ensure that attributes do not exist or are generated by us + test ! -e $$A || head -n 1 $$A | grep -F "Automatically generated (yoo9jei6Ee6Teiti)" + echo "# Automatically generated (yoo9jei6Ee6Teiti)" > $$A +# Write ignored files there + for i in `$$(RELEASE_IGNORE_FILES_CMD)`; do echo $$$$i export-ignore >> $$A; echo Not releasing $$$$i; done + +$$(RELEASE_BASENAME).zip: + rm -rf $$@ $$(RELEASE_BASENAME) + $(MAKE) $$(RELEASE_BASENAME) + find $$(RELEASE_BASENAME) -type d -empty -print -delete + zip -r $$@ $$(RELEASE_BASENAME) + +$$(RELEASE_BASENAME):: .git/info/attributes + git archive --worktree-attributes --prefix=$$@/ $$(RELEASE_COMMIT) | tar xf - + +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. -.PHONY: $(RELEASE_BASENAME).zip +[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 _ _ -$(RELEASE_BASENAME).zip: - rm -rf $@ $(RELEASE_BASENAME) - $(MAKE) $(RELEASE_BASENAME) - zip -r $@ $(RELEASE_BASENAME) +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 -$(RELEASE_BASENAME):: - git archive --worktree-attributes --prefix=$@/ $(RELEASE_COMMIT) | tar xf - +$(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO])))) +$(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))