summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-07-25 16:18:55 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-07-25 16:18:55 -0400
commitd90ded5641d3964e34fca8bb093a83fb64658ee2 (patch)
tree98b5b2e37be21b899acd12920a7af42c12387cd0
parent78e658c8774c5009d9ff601fb6ac9a66810790b6 (diff)
Generalize the utils to make the target an argument.
-rw-r--r--Makefile68
-rwxr-xr-xutils/file217
-rwxr-xr-xutils/file2base6
-rwxr-xr-xutils/file2extra6
-rwxr-xr-xutils/file2url12
-rwxr-xr-xutils/spec217
-rwxr-xr-xutils/spec2file13
7 files changed, 65 insertions, 74 deletions
diff --git a/Makefile b/Makefile
index e601402..fa542ab 100644
--- a/Makefile
+++ b/Makefile
@@ -20,19 +20,13 @@ all: package
# utilities ####################################################################
-# spec = type|url|extra
-# file ~= type/url/extra # but with 'url' mangled
-# base ~= type/url # but with 'url' mangled
-
-name2file = $(call spec2file,$($1))
-name2base = $(call spec2base,$($1))
-
-spec2file = $(shell utils/spec2file $(foreach a,$1,'$a') )
-spec2base = $(shell utils/file2base $$(utils/spec2file $(foreach a,$1,'$a')))
-
-file2url = $(shell utils/file2url $(foreach a,$1,'$a'))
-file2base = $(shell utils/file2base $(foreach a,$1,'$a'))
-file2extra = $(shell utils/file2extra $(foreach a,$1,'$a'))
+# murl = "mangled url"
+# spec = type|url|extra
+# file = type/murl/extra
+# base = type/murl
+name2 = $(call spec2,$1,$(foreach package,$2,$($(package))))
+spec2 = $(shell utils/spec2 $1 $(foreach a,$2,'$a'))
+file2 = $(shell utils/file2 $1 $(foreach a,$2,'$a'))
specs_for = $(strip $(foreach t,$1,$(filter $t|%,$(if $2,$2,$(specs)))))
@@ -48,45 +42,45 @@ export MAVEN_LOCAL_REPO := $(shell $(CAT) conf/maven.local.repo.txt)
export JAR_DIR := $(shell $(CAT) conf/jardir.txt)
specs := $(foreach package,$(packages),$($(package)))
-tarbombs := $(addprefix build/extract/,$(call spec2base,$(_tarbombs)))
+tarbombs := $(addprefix build/extract/,$(call spec2,base,$(_tarbombs)))
# download #####################################################################
download: PHONY \
$(addprefix build/download/, \
- $(call spec2base,$(call specs_for,git tar)) \
- $(call spec2file,$(call specs_for,svn)) )
+ $(call spec2,base,$(call specs_for,git tar)) \
+ $(call spec2,file,$(call specs_for,svn)) )
build/download/git/%: .tokens/network
if [ -d '$@' ]; then \
cd '$@' && $(GIT) fetch --all -p; \
else \
- $(MKDIRS) '$(@D)' && $(GIT) clone --mirror '$(call file2url,git/$*)' '$@'; \
+ $(MKDIRS) '$(@D)' && $(GIT) clone --mirror '$(call file2,url,git/$*)' '$@'; \
fi
$(TOUCH) '$@'
build/download/svn/%: .tokens/network
- if ! [ -d '$(call file2base,svn/$*)' ]; then \
+ if ! [ -d '$(call file2,base,svn/$*)' ]; then \
$(RM) -r '$@' && \
$(MKDIRS) build/download/svn && \
$(SVN) checkout --depth=empty \
- '$(call file2url,svn/$*)' \
- build/download/'$(call file2base,svn/$*)' && \
- cd build/download/'$(call file2base,svn/$*)'; \
+ '$(call file2,url ,svn/$*)' \
+ build/download/'$(call file2,base,svn/$*)' && \
+ cd build/download/'$(call file2,base,svn/$*)'; \
else \
- cd build/download/'$(call file2base,svn/$*)' && \
+ cd build/download/'$(call file2,base,svn/$*)' && \
$(SVN) update; \
fi && \
- $(SVN) update --parents '$(call file2extra,svn/$*)'
+ $(SVN) update --parents '$(call file2,extra,svn/$*)'
$(EXISTS) '$@'
$(TOUCH) '$@'
build/download/tar/%: .tokens/network
$(MKDIRS) '$(@D)'
- $(WGET) -c -O '$@' '$(call file2url,tar/$*)'
+ $(WGET) -c -O '$@' '$(call file2,url,tar/$*)'
$(TOUCH) '$@'
# extract ######################################################################
-extract: PHONY $(addprefix build/extract,$(call spec2file,$(specs)))
+extract: PHONY $(addprefix build/extract,$(call spec2,file,$(specs)))
# This is a little gross because to get the dependencies right for
# `git` and `tar`, we need to do a bit more complex processing of
@@ -97,12 +91,12 @@ extract: PHONY $(addprefix build/extract,$(call spec2file,$(specs)))
# git
build/extract/git/%: # magic foreach loop
- gitref='$(firstword $(subst /, ,$(call file2extra,git/$*)))' && \
- gitdir=build/extract/'$(call file2base,git/$*)'/$${gitref} && \
+ gitref='$(firstword $(subst /, ,$(call file2,extra,git/$*)))' && \
+ gitdir=build/extract/'$(call file2,base,git/$*)'/$${gitref} && \
$(RM) -r "$$gitdir" && \
{ \
$(MKDIRS) "$$(dirname "$$gitdir")" && \
- $(GIT) clone build/download/'$(call file2base,git/$*)' "$$gitdir" && \
+ $(GIT) clone build/download/'$(call file2,base,git/$*)' "$$gitdir" && \
( cd "$$gitdir" && $(GIT) checkout "$$gitref" ) && \
$(EXISTS) '$@'; \
} || { $(RM) -r "$$gitdir"; $(FAIL); }
@@ -116,7 +110,7 @@ build/extract/svn/%: build/download/svn/%
$(TOUCH) '$@'
# tar
-_tar_basedir=build/extract/$(call file2base,tar/$*)
+_tar_basedir=build/extract/$(call file2,base,tar/$*)
build/extract/tar/%: # magic foreach loop
$(RM) -r '$(_tar_basedir)' && \
{ \
@@ -125,13 +119,13 @@ build/extract/tar/%: # magic foreach loop
} || { $(RM) -r '$(_tar_basedir)'; $(FAIL); }
# magic foreach loop
-$(foreach package,$(packages), \
- $(if $(call specs_for,git tar,$($(package))), \
- $(eval \
- build/extract/$(call name2file,$(package)): \
- build/download/$(call name2base,$(package)) \
- ) \
- ) \
+$(foreach package,$(packages), \
+ $(if $(call specs_for,git tar,$($(package))), \
+ $(eval \
+ build/extract/$(call name2,file,$(package)): \
+ build/download/$(call name2,base,$(package)) \
+ ) \
+ ) \
)
# place (patch) ################################################################
@@ -156,7 +150,7 @@ build/workdir/%:
# beteen `build/compile` and `build/extract`.
$(foreach package,$(packages),$(eval \
build/workdir/$(package): \
- build/extract/$(call name2file,$(package)) \
+ build/extract/$(call name2,file,$(package)) \
$(call dep_optdir,rules/$(package)) \
))
diff --git a/utils/file2 b/utils/file2
new file mode 100755
index 0000000..3dc14de
--- /dev/null
+++ b/utils/file2
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+want=$1; shift
+for file in "$@"; do
+ IFS=/ read -r type murl extra <<<"$file"
+
+ url=$murl
+ url=${url//^2F//}
+ url=${url//^3A/:}
+ url=${url//^3D/=}
+ url=${url//^5E/^}
+
+ base=$type/$murl
+ spec="$type|$url|$extra"
+
+ printf '%s\n' "${!want}"
+done
diff --git a/utils/file2base b/utils/file2base
deleted file mode 100755
index 2fee680..0000000
--- a/utils/file2base
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/env bash
-
-for file in "$@"; do
- IFS=/ read -r type url extra <<<"$file"
- echo "${type}/${url}"
-done
diff --git a/utils/file2extra b/utils/file2extra
deleted file mode 100755
index 663e461..0000000
--- a/utils/file2extra
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/env bash
-
-for file in "$@"; do
- IFS=/ read -r type url extra <<<"$file"
- echo "${extra}"
-done
diff --git a/utils/file2url b/utils/file2url
deleted file mode 100755
index 44900b7..0000000
--- a/utils/file2url
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-
-for file in "$@"; do
- IFS=/ read -r type url extra <<<"$file"
-
- url=${url//^2F//}
- url=${url//^3A/:}
- url=${url//^3D/=}
- url=${url//^5E/^}
-
- echo "${url}"
-done
diff --git a/utils/spec2 b/utils/spec2
new file mode 100755
index 0000000..4b62f6b
--- /dev/null
+++ b/utils/spec2
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+want=$1; shift
+for spec in "$@"; do
+ IFS='|' read -r type url extra <<<"$spec"
+
+ murl=$url
+ murl=${murl//^/^5E}
+ murl=${murl//=/^3D}
+ murl=${murl//:/^3A}
+ murl=${murl//\//^2F}
+
+ base=$type/$murl
+ file=$type/$murl/$extra
+
+ printf '%s\n' "${!want}"
+done
diff --git a/utils/spec2file b/utils/spec2file
deleted file mode 100755
index b0eb72d..0000000
--- a/utils/spec2file
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-for spec in "$@"; do
- IFS='|' read -r type url extra <<<"$spec"
-
- url=${url//^/^5E}
- url=${url//=/^3D}
- url=${url//:/^3A}
- url=${url//\//^2F}
-
- ret=${type}/${url}/${extra}
- echo "${ret%/}"
-done