forked from TanmayPatil105/procfetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·113 lines (94 loc) · 2.71 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
set -o nounset
PROJECT=procfetch
VERSION="$(cat VERSION)"
CXX=g++
CXXFLAGS=${CXXFLAGS:-}
LIBS=${LIBS:-}
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"
elif [[ -d "/opt/homebrew/opt/gnu-getopt/bin" ]]; then
PATH="/opt/homebrew/opt/gnu-getopt/bin:$PATH"
fi
function show_usage {
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).
--enable-code-coverage enable coverage testing
Some influential environment variables:
CXX C++ compiler command
CXXFLAGS C++ compiler flags
LIBS libraries to pass to the linker, e.g. -l<library>
EOF
exit $1
}
#
# parse options
#
help_option=0
version_option=0
code_coverage_option=0
parsed_arguments=$(getopt -n $0 -o hv \
--long help,version,prefix:,with-cxx:,enable-code-coverage -- "$@")
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 ;;
--enable-code-coverage )
code_coverage_option=1 ; shift ;;
--) shift; break;;
*) echo "Error: Unknown option: $1"
show_usage 1;;
esac
done
if [[ $# -ne 0 ]]; then
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
if [[ $code_coverage_option == 1 ]]; then
if [[ $CXX =~ clang\+\+ ]]; then # for clang++
echo "Not implemented yet"
exit 1
else # for gcc
CXXFLAGS="-fprofile-arcs -ftest-coverage -O0"
LIBS="-lgcov"
fi
fi
BIN_DIR="${PREFIX:-}${BIN_DIR}"
LIB_DIR="${PREFIX:-/usr}${LIB_DIR}"
for f in Makefile ascii/Makefile src/Makefile src/config.h \
Doxyfile build-deb.sh debian/control
do
echo "creating $f"
sed -e "s/@VERSION@/${VERSION}/g" \
-e "s/@CXX@/${CXX}/g" \
-e "s/@CXXFLAGS@/${CXXFLAGS}/g" \
-e "s/@LIBS@/${LIBS}/g" \
-e "s:@BIN_DIR@:${BIN_DIR}:g" \
-e "s:@LIB_DIR@:${LIB_DIR}:g" "$f.in" > "$f"
done
chmod +x build-deb.sh