Skip to content

Instantly share code, notes, and snippets.

@xyproto
Created July 26, 2017 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyproto/d48d375de7a4774773bd1db908f2cc4c to your computer and use it in GitHub Desktop.
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.
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