Created
July 26, 2017 14:00
-
-
Save xyproto/d48d375de7a4774773bd1db908f2cc4c to your computer and use it in GitHub Desktop.
One way of processing shell scripts through the C preprocessor + strip comments. Beware that cpp may do surprising things to shell scripts.
This file contains hidden or 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
RELEASE ?= 0 | |
%: %.in | |
@$(eval SHEBANG=$(shell head -1 ${<} | grep -q -F '#!' && echo 1 || echo 0)) | |
@if [ $(SHEBANG) = 1 ]; then \ | |
head -1 $< > $@; \ | |
tail -n +2 $< | sed -e 's/^ *# .*$$//' -e '/^$$/d' -e '/^#$$/d' | cpp -DRELEASE=$(RELEASE) -P >> $@; \ | |
else \ | |
sed -e 's/^ *# .*$$//' -e '/^$$/d' -e '/^#$$/d' $< | cpp -DRELEASE=$(RELEASE) -P > $@; \ | |
fi | |
# scriptfile.in must exist | |
all: scriptfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment