summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-11-20 13:11:10 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-11-20 13:11:10 -0500
commitfec5a7281b3824cb952aa0bb76bbbaa41eaafdf9 (patch)
tree7599ffd25708a6713ce1d7d2b5d7726a64a65bc0 /Makefile
parent3331afbb26380088c0a6cc5b301a093a96235475 (diff)
Implement spec2 and file2 entirely in Make.
This removes the need for memoization.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile47
1 files changed, 18 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 16a5605..357b35f 100644
--- a/Makefile
+++ b/Makefile
@@ -20,21 +20,6 @@ WGET = wget
all: package
-# memoization ##################################################################
-
-# How to use: Define 2 variables (the type you would pass to $(call):
-# `_NAME_main` and `_NAME_hash`. Now, `_NAME_main` is the function getting
-# memoized, and _NAME_hash is a function that hashes the function arguments
-# into a string suitable for a variable name.
-#
-# Then, define the final function like:
-#
-# NAME = $(foreach func,NAME,$(memoized))
-
-_main = $(_$(func)_main)
-_hash = _memoized_$(_$(func)_hash)
-memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_hash)))
-
# utilities ####################################################################
# murl = "mangled url"
@@ -42,22 +27,26 @@ memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_has
# file = type/murl/extra
# base = type/murl
-_spec2_main = $(shell utils/spec2 $1 '$2')
-_file2_main = $(shell utils/file2 $1 '$2')
-
-_spec2_hash = spec2$1_$(subst =,^3D,$(subst :,^3A,$(subst ^,^5E,$2)))
-_file2_hash = file2$1_$2
-
-# There's another level of indirection, because $2 is a list, and each item
-# needs to be memoized separately
-_spec2_memo = $(foreach func,spec2,$(memoized))
-_file2_memo = $(foreach func,file2,$(memoized))
+_url2murl = $(subst %,^25,$(subst /,^2F,$(subst :,^3A,$(subst =,^3D,$(subst ^,^5E,$1)))))
+_murl2url = $(subst ^,^5E,$(subst =,^3D,$(subst :,^3A,$(subst /,^2F,$(subst %,^25,$1)))))
+
+_spec2type = $(word 1,$1)
+_spec2url = $(word 2,$1)
+_spec2extra = $(call merge,|,$(wordlist 3,$(words $1),$1))
+_spec2murl = $(call _url2murl,$(_spec2url))
+_spec2base = $(_spec2type)/$(_spec2murl)
+_spec2file = $(_spec2type)/$(_spec2murl)/$(_spec2extra)
+spec2 = $(foreach i,$2,$(call _spec2$1,$(subst |, ,$i)))
+
+_file2type = $(word 1,$1)
+_file2murl = $(word 2,$1)
+_file2extra = $(call merge,/,$(wordlist 3,$(words $1),$1))
+_file2url = $(call _murl2url,$(_file2murl))
+_file2base = $(_file2type)/$(_file2murl)
+_file2spec = $(_file2type)|$(_file2url)|$(_file2extra)
+file2 = $(foreach i,$2,$(call _file2$(1),$(subst /, ,$i)))
name2 = $(call spec2,$1,$(foreach name,$2,$($(name))))
-#spec2 = $(shell utils/spec2 $1 $(foreach a,$2,'$a'))
-#file2 = $(shell utils/file2 $1 $(foreach a,$2,'$a'))
-spec2 = $(foreach spec,$2,$(call _spec2_memo,$1,$(spec)))
-file2 = $(foreach file,$2,$(call _file2_memo,$1,$(file)))
specs_for = $(strip $(foreach t,$1,$(filter $t|%,$(if $2,$2,$(specs)))))