-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfigure
executable file
·172 lines (158 loc) · 4.64 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
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh -e
#
# Copyright (c) 2022 Mark Heily <mark@heily.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
err() {
echo "ERROR: $*"
exit 1
}
cd "$(dirname "$0")"
prefix="/usr/local"
build_type="debug"
objdir=""
mandir=""
coverage="no"
use_msan="no"
use_lto="yes"
target_cxxflags="-std=gnu++17 -D_GNU_SOURCE"
for arg in "$@"
do
key=$(echo "$arg" | sed 's/^--//; s/=.*//')
val=$(echo "$arg" | grep '=' | sed "s/^--${key}=//")
case $key in
build-type)
build_type=$val
;;
objdir)
objdir="$val"
;;
mandir)
mandir="$val" ;;
prefix)
prefix=$val
;;
enable-coverage)
coverage="yes"
;;
enable-msan)
use_msan="yes"
;;
disable-lto)
use_lto="no"
;;
*)
echo "invalid usage"
exit 1
esac
done
project=relaunchd
project_version=$(grep 'project(relaunchd VERSION' CMakeLists.txt| awk '{print $3}' | sed 's/)//')
printf 'configuring %s version %s\n' "$project" "$project_version"
printf 'setting build type to %s\n' $build_type
case $build_type in
debug)
build_type_flags="-g3 -O0 -Wall -Wextra -fno-omit-frame-pointer"
# Enable GNU libstdc++ debug mode, which adds some sanity checking to STL containers"
build_type_flags="${build_type_flags} -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC"
;;
release)
build_type_flags="-Os -Wall -Wextra -Werror"
;;
*)
exit 2
esac
if [ -z "$objdir" ] ; then
objdir=$(pwd)
fi
if [ ! -e "$objdir" ] ; then
mkdir "$objdir"
else
test -O "$objdir"
fi
objdir=$(realpath "$objdir")
printf 'build artifacts will be created in %s\n' "$objdir"
printf 'executables will be installed using the prefix of %s\n' "$prefix"
if [ -z "$mandir" ] ; then
mandir="${prefix}/share/man"
fi
printf 'man pages will be installed in %s\n' "$mandir"
printf 'checking if code coverage is enabled.. '
if [ "$coverage" = "yes" ] ; then
echo 'yes'
if [ "$objdir" = "$(pwd)" ] ; then
echo "Error: coverage reports require an out-of-tree build"
exit 1
fi
else
echo 'no'
fi
printf 'checking for nlohmann::json... '
if pkg-config --cflags nlohmann_json >/dev/null 2>&1 ; then
echo "found"
target_cxxflags="$target_cxxflags $(pkg-config --cflags nlohmann_json)"
else
echo "not found"
exit 1
fi
if [ "$objdir" = "$(pwd)" ] ; then
makefilepath="Makefile"
config_h_path="src/config.h"
else
makefilepath="$objdir/Makefile"
config_h_path="$objdir/src/config.h"
test -e "$objdir/src" || ln -s "$(pwd)/src" "$objdir/src"
test -e "$objdir/man" || ln -s "$(pwd)/man" "$objdir/man"
test -e "$objdir/test" || ln -s "$(pwd)/test" "$objdir/test"
mkdir -p "$objdir/tmp"
fi
echo "writing $makefilepath"
rm -f $makefilepath
(
echo "# DO NOT EDIT: generated by ./configure"
echo "PROJECT_VERSION=$project_version"
echo "OBJDIR=$objdir"
echo "MANDIR=$mandir"
echo "PREFIX=$(echo "$prefix" | sed 's,/$,,')"
echo "TARGET_CXXFLAGS = $build_type_flags -D_GNU_SOURCE $target_cxxflags"
if [ "$coverage" = "yes" ] ; then
echo "# Enable code coverage"
echo "TARGET_CXXFLAGS += -fprofile-arcs -ftest-coverage"
fi
if [ "$use_msan" = "yes" ] ; then
echo "# Enable MSAN"
echo "TARGET_CXXFLAGS += -fsanitize=memory -fsanitize-memory-track-origins=2"
fi
if [ "$use_lto" = "yes" ] ; then
echo "# Enable LTO"
echo "TARGET_CXXFLAGS += -flto"
fi
) >> "$makefilepath"
cat Makefile.in >> $makefilepath
for file in src/config.h man/launchd.8
do
outfile="$objdir/$(basename "$file")"
printf "writing %s\n" "$outfile"
sed -e "
s,\${PREFIX},$prefix,g;
s,\${CMAKE_PROJECT_VERSION},$project_version,g;
s,\${PKGSTATEDIR},/var/db/relaunchd,g;
s,\${XML_MANIFEST_SUPPORT},0,g;
s,\${SYSTEM_AGENT_LOAD_PATH},/etc/relaunchd/LaunchAgents,g;
s,\${SYSTEM_DAEMON_LOAD_PATH},/etc/relaunchd/LaunchDaemons,g;
s,\${USER_AGENT_LOAD_PATH},~/.config/relaunchd/LaunchAgents,g;
s,\${VENDOR_AGENT_LOAD_PATH},/lib/relaunchd/LaunchAgents,g;
s,\${VENDOR_DAEMON_LOAD_PATH},/lib/relaunchd/LaunchDaemons,g;
" < "${file}.in" > "$outfile"
done