Created
April 10, 2020 12:44
-
-
Save bng44270/9c66b7b003e171ff4475aaa1f25d4dd7 to your computer and use it in GitHub Desktop.
Makefile macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################# | |
# newsetting | |
# | |
# Writes a name/value pair to a defined text file. This function pairs with the getsetting function. | |
# | |
# Syntax: | |
# $(call newsetting,PROMPT-TEXT,SETTING-NAME,DEFAULT-VALUE,SETTING-FILE) | |
# | |
# Example: | |
# $(call newsetting,Enter the binary path,BINPATH,/usr/local/bin,/tmp/settings) | |
# | |
# This will create the following user prompt: | |
# Enter the binary path [/usr/local/bin]: | |
# | |
# The resulting file (/tmp/settings) if left with the default settings will look like this: | |
# BINPATH /usr/local/bin | |
################# | |
define newsetting | |
@read -p "$(1) [$(3)]: " thisset ; [[ -z "$$thisset" ]] && echo "$(2) $(3)" >> $(4) || echo "$(2) $$thisset" | sed 's/\/$$//g' >> $(4) | |
endef | |
################# | |
# getsetting | |
# | |
# Reads a value from a file based on the name. This fucntion pairs with the newsetting function. | |
# | |
# Syntax: | |
# $(call getsetting,SETTING-NAME,SETTING-FILE) | |
# | |
# Example: | |
# $(call newsetting,BINPATH,/tmp/settings) | |
################# | |
define getsetting | |
$$(grep "^$(2)[ \t]*" $(1) | sed 's/^$(2)[ \t]*//g') | |
endef | |
################# | |
# newlist | |
# | |
# Defines a list and writes list to a specified file | |
# | |
# Syntax: | |
# $(call newlist,/tmp/people) | |
################# | |
define newlist | |
@echo "Enter a blank line when finished" | |
@while true; do read -p "$(1): " thisval ; [[ -z "$$thisval" ]] && break ; echo "$$thisval" >> $(2) ; done | |
endef | |
################# | |
# m4define | |
# | |
# Defines an m4 macro | |
# | |
# Syntax (single-line): | |
# $(call m4define,TMPFOLDER,/tmp)" > test.m4 | |
# | |
# Syntax (multi-line): | |
# $(call m4define,FILEDATA,Line 1\nLine2\nLine 3) | |
################# | |
define m4define | |
@echo -e "define(\`$(1)',\`$(shell printf "$(2)" | sed -z 's/\n/\\n/g')')" | |
endef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment