#!/usr/bin/env bash release_bindir="$(dirname "${BASH_SOURCE[0]}")" release_bindir_abs="$(readlink -f "$release_bindir")" release_topdir_abs="$(readlink -f "$release_bindir/..")" #!/usr/bin/env bash help() { { echo "" echo "Usage: $0 [--exec] [--prefix pf] args.." echo " $0 --build modname.so cppsources.." echo "" echo "Replacement args:" echo " --cxx /usr/bin/clang++" echo " --cxxflags $( echo '-std=c++20 -fPIC -D_YOSYS_ -DYOSYS_VER="0.69+190" -DYOSYS_MAJOR=0 -DYOSYS_MINOR=69 -DYOSYS_COMMIT=190 -I${release_topdir_abs}/share/yosys/include' | fmt -w60 | sed ':a;N;$!ba;s/\n/ \\\n /g' )" echo " --linkflags -fPIC" echo " --ldflags (alias of --linkflags)" echo " --libs " echo " --ldlibs (alias of --libs)" echo " --bindir ${release_topdir_abs}/bin" echo " --datdir ${release_topdir_abs}/share/yosys" echo "" echo "All other args are passed through as they are." echo "" echo "Use --exec to call a command instead of generating output. Example usage:" echo "" echo " $0 --exec --cxx --cxxflags --ldflags -o plugin.so -shared plugin.cc --libs" echo "" echo "The above command can be abbreviated as:" echo "" echo " $0 --build plugin.so plugin.cc" echo "" echo "Use --prefix to change the prefix for the special args from '--' to" echo "something else. Example:" echo "" echo " $0 --prefix @ bindir: @bindir" echo "" echo "The args --bindir and --datdir can be directly followed by a slash and" echo "additional text. Example:" echo "" echo " $0 --datdir/simlib.v" echo "" } >&$(( $1 + 1)) exit $1 } if [ $# -eq 0 ]; then help 1 fi if [ "$1" = "--build" ]; then modname="$2"; shift 2 set -- --exec --cxx --cxxflags --ldflags -o "$modname" -shared "$@" --libs fi prefix="--" get_prefix=false exec_mode=false declare -a tokens=() for opt; do if $get_prefix; then prefix="$opt" get_prefix=false continue fi case "$opt" in "$prefix"cxx) tokens=( "${tokens[@]}" /usr/bin/clang++ ) ;; "$prefix"cxxflags) tokens=( "${tokens[@]}" -std=c++20 -fPIC -D_YOSYS_ -DYOSYS_VER="0.69+190" -DYOSYS_MAJOR=0 -DYOSYS_MINOR=69 -DYOSYS_COMMIT=190 -I${release_topdir_abs}/share/yosys/include ) ;; "$prefix"linkflags) tokens=( "${tokens[@]}" -fPIC ) ;; "$prefix"libs) tokens=( "${tokens[@]}" ) ;; "$prefix"ldflags) tokens=( "${tokens[@]}" -fPIC ) ;; "$prefix"ldlibs) tokens=( "${tokens[@]}" ) ;; "$prefix"bindir) tokens=( "${tokens[@]}" ${release_topdir_abs}'/bin' ) ;; "$prefix"datdir) tokens=( "${tokens[@]}" ${release_topdir_abs}'/share/yosys' ) ;; "$prefix"bindir/*) tokens=( "${tokens[@]}" ${release_topdir_abs}'/bin'"${opt#${prefix}bindir}" ) ;; "$prefix"datdir/*) tokens=( "${tokens[@]}" ${release_topdir_abs}'/share/yosys'"${opt#${prefix}datdir}" ) ;; --help|-\?|-h) if [ ${#tokens[@]} -eq 0 ]; then help 0 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 ;; *) tokens=( "${tokens[@]}" "$opt" ) esac done if $exec_mode; then exec "${tokens[@]}" fi echo "${tokens[@]}" exit 0