From 93c927aa14264a2b80b880d77b591e72e6a000cc Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Mon, 27 Mar 2023 09:22:09 +0900 Subject: [PATCH 1/7] Accept --with-cxx option --- configure | 60 ++++++++++++++++++++++++++++++++++++++----------- src/Makefile.in | 1 + 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 74288b4..1393777 100755 --- a/configure +++ b/configure @@ -2,40 +2,73 @@ set -o nounset +PROJECT=procfetch VERSION="$(cat VERSION)" CONFIG_BREW=OFF +CXX=g++ +unset PREFIX BIN_DIR=/bin LIB_DIR=/share/procfetch + 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 +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 [[ -v help_option ]]; then + show_usage 0 +fi + +if [[ -v version_option ]]; then + echo "$PROJECT configure $VERSION" + exit 0 +fi + BIN_DIR="${PREFIX:-}${BIN_DIR}" LIB_DIR="${PREFIX:-/usr}${LIB_DIR}" @@ -43,6 +76,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) From f69acbb5537ccf0a62ae19a8282a3158b6be6b7a Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Mon, 27 Mar 2023 09:24:07 +0900 Subject: [PATCH 2/7] Gleaning --- configure | 1 - 1 file changed, 1 deletion(-) diff --git a/configure b/configure index 1393777..680960b 100755 --- a/configure +++ b/configure @@ -4,7 +4,6 @@ set -o nounset PROJECT=procfetch VERSION="$(cat VERSION)" -CONFIG_BREW=OFF CXX=g++ unset PREFIX BIN_DIR=/bin From a4a4c8b8772348c37a590633f6b3602c9a7783b6 Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Wed, 29 Mar 2023 01:05:43 +0900 Subject: [PATCH 3/7] Install GNU Getopt on macOS --- .github/workflows/unit-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 50777e5..36d9d76 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 From 5ae3f8c979ca4917fa18a78cfad2d7088a46b0d3 Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Wed, 29 Mar 2023 01:07:37 +0900 Subject: [PATCH 4/7] fix --- .github/workflows/unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 36d9d76..fb5eb48 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install GNU Getopt on macOS - if ${{ matrix.os == 'macos-latest' }} + if: ${{ matrix.os == 'macos-latest' }} run: | brew install gnu-getopt - name: configure From 061e779ade91937dc76453cf66399e70bf24f8a2 Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Wed, 29 Mar 2023 01:28:33 +0900 Subject: [PATCH 5/7] Add PATH --- configure | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure b/configure index 680960b..e619f90 100755 --- a/configure +++ b/configure @@ -9,6 +9,9 @@ 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 { cat <<-EOF From 404acb6f435911eab2d0625191942cef828ad9f0 Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Wed, 29 Mar 2023 01:38:21 +0900 Subject: [PATCH 6/7] Compliant with bash on macOS --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index e619f90..2549141 100755 --- a/configure +++ b/configure @@ -62,11 +62,11 @@ fi # main process # -if [[ -v help_option ]]; then +if [[ $help_option == 1 ]]; then show_usage 0 fi -if [[ -v version_option ]]; then +if [[ $version_option == 1 ]]; then echo "$PROJECT configure $VERSION" exit 0 fi From d8eabe8d2a401ddec8bc0d0772e2b1fe46068a68 Mon Sep 17 00:00:00 2001 From: NAKAJIMA Yusaku Date: Wed, 29 Mar 2023 01:41:58 +0900 Subject: [PATCH 7/7] Compliant with bash on macOS --- configure | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure b/configure index 2549141..8334677 100755 --- a/configure +++ b/configure @@ -35,6 +35,9 @@ EOF # parse options # +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