2022-09-25 00:52:42 -05:00
|
|
|
#!/usr/bin/env bash
|
2013-03-06 04:58:07 -06:00
|
|
|
|
|
|
|
help() {
|
2013-11-19 15:48:48 -06:00
|
|
|
{
|
|
|
|
echo ""
|
2015-02-07 17:14:07 -06:00
|
|
|
echo "Usage: $0 [--exec] [--prefix pf] args.."
|
|
|
|
echo " $0 --build modname.so cppsources.."
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
2020-04-22 10:30:03 -05:00
|
|
|
echo "Replacement args:"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo " --cxx @CXX@"
|
|
|
|
echo " --cxxflags $( echo '@CXXFLAGS@' | fmt -w60 | sed ':a;N;$!ba;s/\n/ \\\n /g' )"
|
2024-02-25 11:48:21 -06:00
|
|
|
echo " --linkflags @LINKFLAGS@"
|
|
|
|
echo " --ldflags (alias of --linkflags)"
|
|
|
|
echo " --libs @LIBS@"
|
|
|
|
echo " --ldlibs (alias of --libs)"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo " --bindir @BINDIR@"
|
|
|
|
echo " --datdir @DATDIR@"
|
|
|
|
echo ""
|
2015-02-07 17:16:59 -06:00
|
|
|
echo "All other args are passed through as they are."
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
2015-02-07 17:14:07 -06:00
|
|
|
echo "Use --exec to call a command instead of generating output. Example usage:"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
2024-02-25 11:48:21 -06:00
|
|
|
echo " $0 --exec --cxx --cxxflags --ldflags -o plugin.so -shared plugin.cc --libs"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
2015-02-07 17:14:07 -06:00
|
|
|
echo "The above command can be abbreviated as:"
|
|
|
|
echo ""
|
2020-04-10 03:38:40 -05:00
|
|
|
echo " $0 --build plugin.so plugin.cc"
|
2015-02-07 17:14:07 -06:00
|
|
|
echo ""
|
2013-11-19 15:48:48 -06:00
|
|
|
echo "Use --prefix to change the prefix for the special args from '--' to"
|
|
|
|
echo "something else. Example:"
|
|
|
|
echo ""
|
2020-04-10 03:38:40 -05:00
|
|
|
echo " $0 --prefix @ bindir: @bindir"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
|
|
|
echo "The args --bindir and --datdir can be directly followed by a slash and"
|
|
|
|
echo "additional text. Example:"
|
|
|
|
echo ""
|
2020-04-10 03:38:40 -05:00
|
|
|
echo " $0 --datdir/simlib.v"
|
2013-11-19 15:48:48 -06:00
|
|
|
echo ""
|
|
|
|
} >&2
|
2013-03-06 04:58:07 -06:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
help
|
|
|
|
fi
|
|
|
|
|
2024-10-14 18:06:34 -05:00
|
|
|
if [ "$1" = "--build" ]; then
|
2015-02-07 17:14:07 -06:00
|
|
|
modname="$2"; shift 2
|
2024-02-25 11:48:21 -06:00
|
|
|
set -- --exec --cxx --cxxflags --ldflags -o "$modname" -shared "$@" --libs
|
2015-02-07 17:14:07 -06:00
|
|
|
fi
|
|
|
|
|
2013-11-19 15:48:48 -06:00
|
|
|
prefix="--"
|
|
|
|
get_prefix=false
|
|
|
|
exec_mode=false
|
|
|
|
declare -a tokens=()
|
|
|
|
|
2013-03-06 04:58:07 -06:00
|
|
|
for opt; do
|
2013-11-19 15:48:48 -06:00
|
|
|
if $get_prefix; then
|
|
|
|
prefix="$opt"
|
|
|
|
get_prefix=false
|
|
|
|
continue
|
|
|
|
fi
|
2013-03-06 04:58:07 -06:00
|
|
|
case "$opt" in
|
2013-11-19 15:48:48 -06:00
|
|
|
"$prefix"cxx)
|
|
|
|
tokens=( "${tokens[@]}" @CXX@ ) ;;
|
|
|
|
"$prefix"cxxflags)
|
|
|
|
tokens=( "${tokens[@]}" @CXXFLAGS@ ) ;;
|
2024-02-25 11:48:21 -06:00
|
|
|
"$prefix"linkflags)
|
|
|
|
tokens=( "${tokens[@]}" @LINKFLAGS@ ) ;;
|
|
|
|
"$prefix"libs)
|
|
|
|
tokens=( "${tokens[@]}" @LIBS@ ) ;;
|
2013-11-19 15:48:48 -06:00
|
|
|
"$prefix"ldflags)
|
2024-02-25 11:35:43 -06:00
|
|
|
tokens=( "${tokens[@]}" @LINKFLAGS@ ) ;;
|
2013-11-19 15:48:48 -06:00
|
|
|
"$prefix"ldlibs)
|
2024-02-25 11:35:43 -06:00
|
|
|
tokens=( "${tokens[@]}" @LIBS@ ) ;;
|
2013-11-19 15:48:48 -06:00
|
|
|
"$prefix"bindir)
|
|
|
|
tokens=( "${tokens[@]}" '@BINDIR@' ) ;;
|
|
|
|
"$prefix"datdir)
|
|
|
|
tokens=( "${tokens[@]}" '@DATDIR@' ) ;;
|
|
|
|
"$prefix"bindir/*)
|
|
|
|
tokens=( "${tokens[@]}" '@BINDIR@'"${opt#${prefix}bindir}" ) ;;
|
|
|
|
"$prefix"datdir/*)
|
|
|
|
tokens=( "${tokens[@]}" '@DATDIR@'"${opt#${prefix}datdir}" ) ;;
|
|
|
|
--help|-\?|-h)
|
|
|
|
if [ ${#tokens[@]} -eq 0 ]; then
|
|
|
|
help
|
|
|
|
else
|
|
|
|
tokens=( "${tokens[@]}" "$opt" )
|
|
|
|
fi ;;
|
|
|
|
--exec)
|
|
|
|
if [ ${#tokens[@]} -eq 0 ]; then
|
|
|
|
exec_mode=true
|
|
|
|
else
|
|
|
|
tokens=( "${tokens[@]}" "$opt" )
|
|
|
|
fi ;;
|
|
|
|
--prefix)
|
|
|
|
if [ ${#tokens[@]} -eq 0 ]; then
|
|
|
|
get_prefix=true
|
|
|
|
else
|
|
|
|
tokens=( "${tokens[@]}" "$opt" )
|
|
|
|
fi ;;
|
2013-03-06 04:58:07 -06:00
|
|
|
*)
|
2013-11-19 15:48:48 -06:00
|
|
|
tokens=( "${tokens[@]}" "$opt" )
|
2013-03-06 04:58:07 -06:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2013-11-19 15:48:48 -06:00
|
|
|
if $exec_mode; then
|
|
|
|
exec "${tokens[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${tokens[@]}"
|
2013-03-06 04:58:07 -06:00
|
|
|
exit 0
|