diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-06-07 11:44:38 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-06-07 11:44:38 -0400 |
commit | b37ee8ec5cd65daac932a70b6f507e51353e9d56 (patch) | |
tree | ddb01bea072a93cdadc6bd142b3fae54b90bc88a /Makefile | |
parent | eb754e501c91cdcb29e01e50f065f73f308d3574 (diff) |
Makefile: pull program names into $(CAPS) variables. Fix issues as found.
- set TAR=bsdtar instead of TAR=tar; GNU tar won't extract .zip files
- build/download/svn: ensure subdirectory existence
- build/extract/git: ensure subdirectory existence
- build/extract/git: emit an error after $(RM)ing because of an error
- build/extract/tar: emit an error after $(RM)ing because of an error
- build/workdir: remove extra flags from $(PATCH)
- deps2classpath: use $(SED)'s 'y' command instead of $(TR)
- .tokens: don't unnecessarily shove both commands into the same line
- set .DELETE_ON_ERROR:
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 107 |
1 files changed, 64 insertions, 43 deletions
@@ -1,14 +1,31 @@ top := $(shell pwd) +CAT = cat +CP = cp +ECHO = echo +EXISTS = test -e +FAIL = exit 1 +FIND = find +GIT = git +LNDIR = lndir -silent +MKDIRS = mkdir -p +PATCH = patch +RM = rm -f +SED = sed +SVN = svn +TAR = bsdtar +TOUCH = touch +WGET = wget + all: package # configuration ################################################################ -packages := $(filter-out _%,$(shell sed "s/[\# ].*//" conf/sources.mk)) +packages := $(filter-out _%,$(shell $(SED) "s/[\# ].*//" conf/sources.mk)) include conf/sources.mk include conf/dependencies.mk -export MAVEN_LOCAL_REPO := $(shell cat conf/maven.local.repo.txt) -export JAR_DIR := $(shell cat conf/jardir.txt) +export MAVEN_LOCAL_REPO := $(shell $(CAT) conf/maven.local.repo.txt) +export JAR_DIR := $(shell $(CAT) conf/jardir.txt) # download ##################################################################### @@ -16,29 +33,30 @@ download: PHONY $(foreach package,$(packages),build/download/$(shell utils/spec2 build/download/git/%: .tokens/network if [ -d '$@' ]; then \ - cd '$@' && git fetch --all -p; \ + cd '$@' && $(GIT) fetch --all -p; \ else \ - mkdir -p '$(@D)' && git clone --mirror '$(shell utils/file2url 'git/$*')' '$@'; \ + $(MKDIRS) '$(@D)' && $(GIT) clone --mirror '$(shell utils/file2url 'git/$*')' '$@'; \ fi - touch '$@' + $(TOUCH) '$@' build/download/svn/%: .tokens/network if ! [ -d '$(shell utils/file2base 'svn/$*')' ]; then \ - rm -rf '$@' && \ - mkdir -p build/download/svn && \ - svn checkout --depth=empty \ + $(RM) -r '$@' && \ + $(MKDIRS) build/download/svn && \ + $(SVN) checkout --depth=empty \ '$(shell utils/file2url 'svn/$*')' \ build/download/'$(shell utils/file2base 'svn/$*')' && \ cd build/download/'$(shell utils/file2base 'svn/$*')'; \ else \ cd build/download/'$(shell utils/file2base 'svn/$*')' && \ - svn update; \ + $(SVN) update; \ fi && \ - svn update --parents '$(shell utils/file2extra 'svn/$*')' - touch '$@' + $(SVN) update --parents '$(shell utils/file2extra 'svn/$*')' + $(EXISTS) '$@' + $(TOUCH) '$@' build/download/tar/%: .tokens/network - mkdir -p '$(@D)' - wget -c -O '$@' '$(shell utils/file2url 'tar/$*')' - touch '$@' + $(MKDIRS) '$(@D)' + $(WGET) -c -O '$@' '$(shell utils/file2url 'tar/$*')' + $(TOUCH) '$@' # extract ###################################################################### @@ -54,27 +72,28 @@ extract: PHONY $(foreach package,$(packages),build/extract/$(shell utils/spec2fi build/extract/git/%: # magic foreach loop gitref='$(shell utils/file2extra 'git/$*'|cut -d/ -f1)' && \ gitdir=build/extract/'$(shell utils/file2base 'git/$*')'/$${gitref} && \ - rm -rf "$$gitdir" && \ + $(RM) -r "$$gitdir" && \ { \ - mkdir -p "$$(dirname "$$gitdir")" && \ - git clone build/download/'$(shell utils/file2base 'git/$*')' "$$gitdir" && \ - ( cd "$$gitdir" && git checkout "$$gitref" ); \ - } || rm -rf "$$gitdir" - touch '$@' + $(MKDIRS) "$$(dirname "$$gitdir")" && \ + $(GIT) clone build/download/'$(shell utils/file2base 'git/$*')' "$$gitdir" && \ + ( cd "$$gitdir" && $(GIT) checkout "$$gitref" ) && \ + $(EXISTS) '$@'; \ + } || { $(RM) -r "$$gitdir"; $(FAIL); } + $(TOUCH) '$@' build/extract/svn/%: build/download/svn/% - rm -rf '$@' - mkdir -p '$(@D)' - cp -a '$<' '$@' - touch '$@' + $(RM) -r '$@' + $(MKDIRS) '$(@D)' + $(CP) -a '$<' '$@' + $(TOUCH) '$@' build/extract/tar/%: # magic foreach loop basedir='build/extract/$(shell utils/file2base 'tar/$*')' && \ - rm -rf "$$basedir" && \ + $(RM) -r "$$basedir" && \ { \ - mkdir -p "$$basedir" && \ - ( cd "$$basedir" && tar -m --strip-components 1 -xf '$(top)/$<' ); \ - } || rm -rf "$$basedir" + $(MKDIRS) "$$basedir" && \ + ( cd "$$basedir" && $(TAR) -m --strip-components 1 -xf '$(top)/$<' ); \ + } || { $(RM) -r "$$basedir"; $(FAIL); } $(foreach package,$(packages),$(if $(filter-out svn|%,$($(package))),$(eval \ build/extract/$(shell utils/spec2file '$($(package))'): \ @@ -87,24 +106,24 @@ place: PHONY $(addprefix build/workdir/,$(packages)) $(addprefix build/workdir/,$(packages)): \ build/workdir/%: - rm -rf '$@' - mkdir -p '$(@D)' - cp -a '$<' '$@' + $(RM) -r '$@' + $(MKDIRS) '$(@D)' + $(CP) -a '$<' '$@' cd '$@' && \ for patch in $(sort $(wildcard $(top)/rules/$*/*.patch)); do \ - patch -f -Np1 -i $$patch || { rm -rf '$@'; exit 1; }; \ + $(PATCH) -p1 < $$patch || { $(RM) -r '$@'; $(FAIL); }; \ done && \ if [ -f '$(top)/rules/$*/delete.list' ]; then \ - rm -rf -- $$(< '$(top)/rules/$*/delete.list'); \ + $(RM) -r -- $$(< '$(top)/rules/$*/delete.list'); \ fi - touch '$@' + $(TOUCH) '$@' # Loop over our source configuration and set up the dependencies # beteen `build/compile` and `build/extract`. $(foreach package,$(packages),$(eval \ build/workdir/$(package): \ build/extract/$(shell utils/spec2file '$($(package))') \ - $(shell find rules/$(package) 2>/dev/null) \ + $(shell $(FIND) rules/$(package) 2>/dev/null) \ )) # package ###################################################################### @@ -114,29 +133,31 @@ package: PHONY $(addprefix build/packages/,$(packages)) package_specific=$(filter $(patsubst rules/%/Makefile,%,$(wildcard rules/*/Makefile)),$(packages)) package_generic =$(filter-out $(patsubst rules/%/Makefile,%,$(wildcard rules/*/Makefile)),$(packages)) -dirs2jars = $(if $1,$(shell find $1 -name '*.jar')) +dirs2jars = $(if $1,$(shell $(FIND) $1 -name '*.jar')) deps2jars = $(filter %.jar,$1) $(call dirs2jars,$(filter build/packages/%,$1)) -deps2classpath = $(shell echo $(abspath $(call deps2jars,$1)) | tr ' ' :) +deps2classpath = $(shell $(ECHO) $(abspath $(call deps2jars,$1)) | $(SED) 'y/ /:/') $(addprefix build/packages/,$(package_specific)): \ build/packages/%: RECURSIVE build/workdir/% rules/%/Makefile CLASSPATH='$(call deps2classpath,$^)' extra_makefiles='$(abspath $(wildcard rules/$*/*.mk))' \ $(MAKE) -C build/workdir/$* -f '$(top)/rules/$*/Makefile' install DESTDIR='$(top)/$@' - mkdir -p build/packages/all && lndir -silent '$(top)/$@' build/packages/all + $(MKDIRS) build/packages/all && $(LNDIR) '$(top)/$@' build/packages/all $(addprefix build/packages/,$(package_generic)): \ build/packages/%: RECURSIVE build/workdir/% rules/generic/Makefile CLASSPATH='$(call deps2classpath,$^)' extra_makefiles='$(abspath $(wildcard rules/$*/*.mk))' \ $(MAKE) -C build/workdir/$* -f '$(top)/rules/generic/Makefile' install DESTDIR='$(top)/$@' - mkdir -p build/packages/all && lndir -silent '$(top)/$@' build/packages/all + $(MKDIRS) build/packages/all && $(LNDIR) '$(top)/$@' build/packages/all # boilerplate ################################################################## clean: PHONY - rm -rf build/compile build/packages + $(RM) -r build/compile build/packages distclean: PHONY - rm -rf .tokens build + $(RM) -r .tokens build .tokens/%: - mkdir -p '$(@D)' && touch '$@' + $(MKDIRS) '$(@D)' + $(TOUCH) '$@' .PHONY: RECURSIVE PHONY +.DELETE_ON_ERROR: |