diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 50777e5..fb5eb48 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -18,6 +18,10 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 + - name: Install GNU Getopt on macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + brew install gnu-getopt - name: configure run: ./configure - name: build diff --git a/configure b/configure index 74288b4..8334677 100755 --- a/configure +++ b/configure @@ -2,40 +2,78 @@ set -o nounset +PROJECT=procfetch VERSION="$(cat VERSION)" -CONFIG_BREW=OFF +CXX=g++ +unset PREFIX BIN_DIR=/bin LIB_DIR=/share/procfetch +if [[ -d "/usr/local/opt/gnu-getopt/bin" ]]; then + PATH="/usr/local/opt/gnu-getopt/bin:$PATH" +fi + function show_usage { - echo "Usage: $0 [--prefix=]" - echo " $0 --help" + cat <<-EOF + \`$0' configures $PROJECT $VERSION to adapt to many kinds of systems. + + Usage: $0 [OPTION]... + + Options: + -h, --help display this help and exit. + -v, --versoin display version information and exit. + --prefix=PREFIX install files in PREFIX. + --with-cxx=CXX use CXX to compile (default=gcc). + + Some influential environment variables: + CXX C++ compiler command +EOF + exit $1 } # # parse options # -if [[ $# -ge 1 ]]; then - if [[ ${1%%=*} == --prefix ]]; then - PREFIX="${1##*=}" - shift - elif [[ $1 == --help || $1 = -h ]]; then - show_usage - exit 0 - fi +help_option=0 +version_option=0 + +parsed_arguments=$(getopt -n $0 -o hv --long help,version,prefix:,with-cxx: -- "$@") +if [[ $? != 0 ]]; then + show_usage 1 fi +eval set -- "$parsed_arguments" +while true; do + case "$1" in + -h | --help ) help_option=1 ; shift ;; + -v | --version ) version_option=1 ; shift ;; + --prefix ) PREFIX="$2" ; shift 2 ;; + --with-cxx ) CXX="$2" ; shift 2 ;; + --) shift; break;; + *) echo "Error: Unknown option: $1" + show_usage 1;; + esac +done + if [[ $# -ne 0 ]]; then - echo "Error: Invalid options or arguments" - show_usage - exit 1 + echo "Error: Invalid argument: $@" + show_usage 1 fi # # main process # +if [[ $help_option == 1 ]]; then + show_usage 0 +fi + +if [[ $version_option == 1 ]]; then + echo "$PROJECT configure $VERSION" + exit 0 +fi + BIN_DIR="${PREFIX:-}${BIN_DIR}" LIB_DIR="${PREFIX:-/usr}${LIB_DIR}" @@ -43,6 +81,7 @@ for f in Makefile ascii/Makefile src/Makefile src/config.h Doxyfile do echo "creating $f" sed -e "s/@VERSION@/${VERSION}/g" \ + -e "s/@CXX@/${CXX}/g" \ -e "s:@BIN_DIR@:${BIN_DIR}:g" \ -e "s:@LIB_DIR@:${LIB_DIR}:g" "$f.in" > "$f" done diff --git a/src/Makefile.in b/src/Makefile.in index 9a44f16..ca90a85 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -2,6 +2,7 @@ TARGET = procfetch SRCS = fetch.cpp main.cpp util.cpp OBJS = $(SRCS:.cpp=.o) +CXX = @CXX@ CXXFLAGS = -std=c++2a -Wall -Wextra --pedantic-errors ifeq ($(COVERAGE_TEST), 1)