Open coriolinus opened 7 years ago
I know it is a bit late but: gcc
is your friend.
You can very well use the gcc
preprocessor to achieve not only #define
s but #include
s too.
I made this script for the exact purpose:
#!/bin/sh
FILE="$1"
if [ ! -f "$FILE" ]; then
echo "File '$FILE' not found"
exit 1;
fi
quiet=""
#quiet="2>/dev/null"
tmpfile=$(mktemp '/tmp/XXXX-btsh.c')
cp "$FILE" "$tmpfile"
gcc -E "$tmpfile" $quiet | egrep -v '^#'
rm "$tmpfile"
Right now, there's no good way to execute built-in commands which vary between systems. You're stuck with stuff like this:
It would be much more powerful if we could use extremely simple macro-style syntax to implement platform-dependent behavior. The above would, under this proposal, look something like this: