aboutsummaryrefslogtreecommitdiff
path: root/make/util.mk
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
committerJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
commit3169070063b2cb877200117ebb384269d73bcb93 (patch)
tree23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /make/util.mk
downloadmal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz
mal-3169070063b2cb877200117ebb384269d73bcb93.zip
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'make/util.mk')
-rw-r--r--make/util.mk72
1 files changed, 72 insertions, 0 deletions
diff --git a/make/util.mk b/make/util.mk
new file mode 100644
index 0000000..43923fc
--- /dev/null
+++ b/make/util.mk
@@ -0,0 +1,72 @@
+#
+# mal (Make Lisp) utility functions/definitions
+#
+
+ifndef __mal_util_included
+__mal_util_included := true
+
+_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+include $(_TOP_DIR)gmsl.mk
+
+SEMI := ;
+COMMA := ,
+LCURLY := {
+RCURLY := }
+LPAREN := (
+RPAREN := )
+LBRACKET := [
+RBRACKET := ]
+DQUOTE := "# "
+SLASH := $(strip \ )
+ESC_DQUOTE := $(SLASH)$(DQUOTE)
+SQUOTE := '# '
+QQUOTE := `# `
+SPACE :=
+SPACE +=
+NUMBERS := 0 1 2 3 4 5 6 7 8 9
+UNQUOTE := ~
+SPLICE_UNQUOTE := ~@
+define NEWLINE
+
+
+endef
+CARET := ^
+ATSIGN := @
+
+# \u00ab
+_LP := «
+# \u00bb
+_RP := »
+# \u00ed
+_LC := í
+# \u00ec
+_RC := ì
+## \u00a7
+_SP := §
+## \u00ae
+_SUQ := ®
+## \u015e
+_DOL := Ş
+## \u00b6
+_NL := ¶
+## \u00a8
+###_EDQ := ¨
+
+
+#
+# Utility functions
+#
+
+_EQ = $(if $(subst x$1,,x$2)$(subst x$2,,x$1),,true)
+
+_NOT = $(if $1,,true)
+
+# READ: read and parse input
+str_encode = $(strip $(eval __temp := $$(subst $$$$,$(_DOL) ,$$(subst $(SPLICE_UNQUOTE),$(_SUQ) ,$$(subst $$(LPAREN),$$(_LP) ,$$(subst $$(RPAREN),$$(_RP) ,$$(subst $$(LCURLY),$$(_LC) ,$$(subst $$(RCURLY),$$(_RC) ,$$(subst $$(NEWLINE),$$(_NL) ,$$(subst $$(SPACE),$(_SP) ,$$1)))))))))$(foreach a,$(__gmsl_characters),$(eval __temp := $$(subst $$a,$$a$$(SPACE),$(__temp))))$(__temp))
+
+str_decode = $(subst $(_SP),$(SPACE),$(subst $(_NL),$(NEWLINE),$(subst $(_LC),$(LCURLY),$(subst $(_RC),$(RCURLY),$(subst $(_LP),$(LPAREN),$(subst $(_RP),$(RPAREN),$(subst $(_SUQ),$(SPLICE_UNQUOTE),$(subst $(_DOL),$$,$(strip $(call gmsl_merge,,$(1)))))))))))
+
+# Read a whole file substituting newlines with $(_NL)
+_read_file = $(subst $(_NL),$(NEWLINE),$(shell out=""; while read -r l; do out="$${out}$${l}$(_NL)"; done < $(1); echo "$$out"))
+
+endif