-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathconfigure
executable file
·198 lines (168 loc) · 5.66 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#! /bin/sh
######################################################################
# Project Configuration #
######################################################################
pkg_name="berry"
pkg_verstr="0.1.7"
pkg_bugreport="Joshua L Ervin <[email protected]>"
# Files that get created by this script
files="Config.mk config.h"
# Package options
components='
{
name=[with-debug]
desc=[ Compile for debugging]
seds=[s/^#\(debug\)/\1/]
}{
name=[with-native]
desc=[ Use -march=native]
seds=[s/ -std=c/ -march=native -std=c/]
}';
# First pair is used if nothing matches
progs="CC=gcc CC=clang CC=cc INSTALL=install"
# Required dependencies
pkgs="x11 xinerama fontconfig xft"
# Default pkg flags to substitute when pkg-config is not found
pkg_libs="-lX11 -lXinerama -lfontconfig -lfreetype -lXft"
pkg_cflags="-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
pkg_ldflags=""
# Automatic vars
if [ -d .git ]; then
pkg_vverstr=$(git describe --always --tags)
[ -z "$pkg_vverstr" ] || pkg_verstr=$pkg_vverstr
fi
pkg_major=$(expr "$pkg_verstr" : '\([0-9]*\)\.[0-9]*\.[0-9]*')
pkg_minor=$(expr "$pkg_verstr" : '[0-9]*\.\([0-9]*\)\.[0-9]*')
pkg_build=$(expr "$pkg_verstr" : '[0-9]*\.[0-9]*\.\([0-9]*\)')
pkg_string="$pkg_name $pkg_verstr"
# Miscellaneous substitutions
custsubs="s/@pkg_name@/$pkg_name/g
s/@pkg_version@/0x$pkg_major$pkg_minor$pkg_build/g
s/@pkg_verstr@/$pkg_verstr/g
s/@pkg_string@/$pkg_string/g
s/@pkg_uname@/$(echo $pkg_name|tr a-z A-Z)/g
s/@pkg_bugreport@/$pkg_bugreport/g
s/@pkg_major@/$pkg_major/g
s/@pkg_minor@/$pkg_minor/g
s/@pkg_build@/$pkg_build/g"
######################################################################
#### The rest of the file is configuration code. Leave it alone. #####
######################################################################
die() { rm -f config.sed; exit; }
sub() { printf "%s\n" "$1">>config.sed; }
escpath() { echo "$@" | sed 's/\//\\\//g'; }
#### Printing helper functions #######################################
print_components() {
local cc name desc
cc=$components
echo "Options:"
while [ -n "$cc" ]; do
name=$(expr "$cc" : '[^}]*name=\[\([^]]*\)\]')
desc=$(expr "$cc" : '[^}]*desc=\[\([^]]*\)\]')
echo " --$name $desc"
cc=$(expr "$cc" : '[^}]*}\(.*\)')
done
echo
}
print_help() {
echo "This program configures $pkg_string build system.
Usage: configure [option]...
Configuration:
-h, --help display this help and exit
-V, --version display version information and exit
Installation directories:
--prefix=dir architecture-independent root [/usr/local]
--bindir=dir admin executable dir [prefix/bin]
--datadir=dir architecture-independent data dir [prefix/share]
--mandir=dir man page root [datadir/man]
--man1dir=dir man 1 page root [mandir/man1]
--builddir=dir location for compiled objects [\$TMPDIR/make]
"
print_components
echo "Report bugs to $pkg_bugreport"
}
print_version() {
echo "$pkg_name $pkg_verstr configure"
}
sub_var() {
local esc2
esc2=$(escpath $2)
eval ac_var_$1='$esc2';
sub "s/@$1@/$esc2/g"
}
sub_comp() {
local cc name seds
cc=$components
while [ -n "$cc" ]; do
name=$(expr "$cc" : '[^}]*name=\[\([^]]*\)\]')
seds=$(expr "$cc" : '[^}]*seds=\[\([^]]*\)\]')
[ "$name" = "$1" ] && sub "$seds"
cc=$(expr "$cc" : '[^}]*}\(.*\)')
done
}
for i in "$@"; do
case "$i" in
--) break;;
--version |-V) print_version && die;;
--help |-h |-?) print_help && die;;
--*=*) sub_var $(expr "$i" : '--\([^=]*\)=') "$(expr "$i" : '[^=]*=\(.*\)')";;
--*) sub_comp $(expr "$i" : '--\(.*\)');;
*) echo "Error: unrecognized option \"$i\"" && die;;
esac
done
#### Set directory prefixes ##########################################
sub "s/@prefix@/${ac_var_prefix:=\/usr\/local}/g
s/@bindir@/${ac_var_bindir:=\$\{prefix\}\/bin}/g
s/@datadir@/${ac_var_datadir:=\$\{prefix\}\/share}/g
s/@mandir@/${ac_var_mandir:=\$\{datadir\}\/man}/g
s/@man1dir@/${ac_var_man1dir:=\$\{mandir\}\/man1}/g
s/@TMPDIR@/$(escpath ${TMPDIR:-/tmp})/g
s/@builddir@/\$\{TMPDIR\}\/make/g"
#### Find headers, libs, programs, and subs ##########################
# Programs found using which
for i in $progs; do
pname=$(expr $i : '\([^=]*\)')
pcall=$(expr $i : '[^=]*=\([^=]*\)')
ppath=$(escpath $(eval echo \$\{$pname\}))
# First check if an environment variable is set
[ -n "$ppath" ] && sub "s/@$pname@/$ppath/g"
# Check if the program exists
ppath=$(which $pcall 2>/dev/null)
[ -n "$ppath" ] && [ -x "$ppath" ] && sub "s/@$pname@/$pcall/g"
done
# If nothing found in first loop, set the first pair anyway
for i in $progs; do
pname=$(expr $i : '\([^=]*\)')
pcall=$(expr $i : '[^=]*=\([^=]*\)')
sub "s/@$pname@/$pcall/g"
done
# Packages found using pkg-config
pkgconfig=$(which pkg-config 2>/dev/null)
if [ -n "$pkgconfig" ] && [ -x "$pkgconfig" ]; then
faildeps=""
for i in $pkgs; do
$($pkgconfig --exists $i) || faildeps="$i $faildeps"
done
if [ -n "$faildeps" ]; then
echo "Error: missing required packages: $faildeps"; die
fi
pkg_cflags=$($pkgconfig --cflags $pkgs)
pkg_libs=$($pkgconfig --libs-only-l $pkgs)
pkg_ldflags=$($pkgconfig --libs-only-L --libs-only-other $pkgs)
fi
sub "s/@pkg_cflags@/$(escpath $pkg_cflags)/"
sub "s/@pkg_libs@/$(escpath $pkg_libs)/"
sub "s/@pkg_ldflags@/$(escpath $pkg_ldflags)/"
# Miscellaneous custom substitutions
sub "$custsubs"
#### Apply substitutions to all files ################################
for i in $files; do
sed -f config.sed $i.in > $i
done
touch config.status
echo "#! /bin/sh
$0 $@
$(tail -n+3 config.status)" > config.status.new
chmod u+x config.status.new
mv config.status.new config.status
die