-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·159 lines (131 loc) · 4.26 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${0}" )" && pwd )"
TMP_TARGET_FILE_NAME="$(mktemp Makefile.$(date +"%Y-%m-%d_%T_XXXXXX"))"
TARGET_FILE_NAME=Makefile
# Configurable options
prefix=/usr/local
debugsym=false
sanitizer=false
coverage=false
profile=false
pkgconfig=false
generator=Ninja
# Figure out project name:
project_name=$(basename $DIR)
if [ -f "PROJECT.name" ]; then
project_name="$(cat 'PROJECT.name')"
else
echo "Warning: no file 'PROJECT.name' found, guessing project name: '${project_name}'"
fi
for arg in "$@"; do
case "$arg" in
--prefix=*)
prefix=`echo $arg | sed 's/--prefix=//'`
;;
--conan-profile=*)
conan_profile=`echo $arg | sed 's/--conan-profile=//'`
# Check selected profile actually exist:
if ! $(conan profile list | grep -q $conan_profile); then
echo "Error: selected conan profile '$conan_profile' does not exist. valid local profiles are:" 1>&2;
conan profile list 1>&2;
exit 1
fi
;;
--generator=*)
generator=`echo $arg | sed 's/--generator=//'`
;;
--enable-debug )
debugsym=true
;;
--disable-debug )
debugsym=false
;;
--enable-sanitizer )
sanitizer=true
;;
--disable-sanitizer )
sanitizer=false
;;
--enable-coverage )
coverage=true
;;
--disable-coverage )
coverage=false
;;
--enable-profile )
profile=true
;;
--disable-profile )
profile=true
;;
--enable-pkgconfig )
pkgconfig=true
;;
--disable-pkgconfig )
pkgconfig=true
;;
--help)
echo 'usage: ./configure [options]'
echo 'options:'
echo ' --prefix=<path>: installation prefix'
echo ' --generator=<generator>: CMake generator'
echo ' --conan-profile=<profile>: Use custom conan profil'
echo ' --enable-debug include debug symbols'
echo ' --disable-debug do not include debug symbols'
echo ' --enable-sanitizer To enable -fsanitize compiler option'
echo ' --disable-sanitizer To disable -fsanitize compiler option'
echo ' --enable-coverage To enable compiler coverage option'
echo ' --disable-coverage To disable compiler coverage option'
echo ' --enable-profile To enable compiler profiler info generation'
echo ' --disable-profile To disable compiler profiler info generation'
echo ' --enable-pkgconfig To include generated .PC library descriptor when installing'
echo ' --disable-pkgconfig To exclude generated .PC library descriptor when installing'
echo ''
echo 'all invalid options are silently ignored'
exit 0
;;
*)
echo "Unexpected option '$arg'"
exit 0
;;
esac
done
echo "Generating Makefile for ${project_name}..."
echo "# Generated Makefile for ${project_name}: $(date)" >> "${TMP_TARGET_FILE_NAME}"
echo "PREFIX ?= ${prefix}" >> "${TMP_TARGET_FILE_NAME}"
echo "PROJECT ?= ${project_name}" >> "${TMP_TARGET_FILE_NAME}"
echo "GENERATOR ?= ${generator}" >> "${TMP_TARGET_FILE_NAME}"
if $debugsym; then
echo 'dbg = -g' >> "${TMP_TARGET_FILE_NAME}"
fi
if $sanitizer; then
echo 'sanitize = address,undefined,leak' >> "${TMP_TARGET_FILE_NAME}"
fi
if $coverage; then
echo 'coverage = -coverage' >> "${TMP_TARGET_FILE_NAME}"
fi
if $profile; then
echo 'profile = -pg' >> "${TMP_TARGET_FILE_NAME}"
fi
if $pkgconfig; then
echo 'PKG_CONFIG = ON' >> "${TMP_TARGET_FILE_NAME}"
fi
if [ ! -z "$conan_profile" ] ; then
echo "CONAN_PROFILE ?= ${conan_profile}" >> "${TMP_TARGET_FILE_NAME}"
fi
if [ ! -z "${CXX}" ] || [ ! -z "${CC}" ] ; then
echo "Using custom copiler: CXX=$CXX CC=$CC"
printf "\n# Compiler config\n" >> "${TMP_TARGET_FILE_NAME}"
if [ ! -z "${CXX}" ] ; then
echo "CXX ?= ${CXX}" >> "${TMP_TARGET_FILE_NAME}"
fi
if [ ! -z "${CC}" ]; then
echo "CC ?= ${CC}" >> "${TMP_TARGET_FILE_NAME}"
fi
fi
echo '' >> "${TMP_TARGET_FILE_NAME}"
cat Makefile.in >> "${TMP_TARGET_FILE_NAME}"
# Atomic move if above was successful
mv "${TMP_TARGET_FILE_NAME}" "${TARGET_FILE_NAME}"
# Congrats
echo "Configuration complete, type 'make' to build ${project_name}."