-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautogen.sh
executable file
·212 lines (175 loc) · 4.99 KB
/
autogen.sh
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env bash
set -e
function get_output_indent()
{
declare -i i=0
declare -i len=0
local line=`grep "Install prefix..." configure.ac.template`
if [ -n "$line" ]; then
line=`echo -n "${line#*\"}"`
len=`echo -n "${line%:*}" | wc -c`+2
fi
OUTPUT_STATUS_INDENT=`printf "%${len}s" ' '`
}
function newline_escape()
{
local nl
local result
for l in "$@"; do
result+="${nl}${l}"
test -z "$nl" && nl="\\\\\n"
done
echo -e "$result"
}
function get_plugins()
{
local p
local indent
local plug_name
local plugins_podir
declare -a plugins
declare -a plugins_enabled
declare -a plugins_intltool
declare -a plugins_makefiles
declare -r PLUGIN_DIR="src/plugins"
for p in `find $PLUGIN_DIR -maxdepth 1 -type d | sort`
do
test $p == $PLUGIN_DIR -o ! -f "${p}/Makefile.am" -o -f "${p}/disabled" && continue
plug_name=`basename $p`
plugins+=($plug_name)
plugins_enabled+=("${indent}${plug_name}")
plugins_makefiles+=("\t ${p}/Makefile")
if [ -f "${p}/po/POTFILES.in" ]; then
local podir="po-plugin-${plug_name}"
plugins_podir+="${podir} "
plugins_intltool+=("IT_PO_SUBDIR([${podir}])")
plugins_makefiles+=("\t ${podir}/Makefile.in")
PO_PLUGINS+=($p)
fi
test -z $indent && indent="${OUTPUT_STATUS_INDENT}"
done
sed s,"PO_PLUGINS","${plugins_podir}", \
Makefile.am.template >Makefile.am
sed s,"#SUBDIRS[[:space:]]*=.*","SUBDIRS = ${plugins[*]}",\
$PLUGIN_DIR/Makefile.am.template >$PLUGIN_DIR/Makefile.am
sed -e s,"PLUGINS_INTLTOOL","$(newline_escape "${plugins_intltool[@]}")",\
-e s,"PLUGINS_MAKEFILES","$(newline_escape "${plugins_makefiles[@]}")",\
-e s,"PLUGINS_ENABLED","$(newline_escape "${plugins_enabled[@]}")",\
configure.ac.template >configure.ac
}
function get_autotools()
{
local t tool
declare -a tools="ACLOCAL AUTOCONF AUTOHEADER AUTOMAKE INTLTOOLIZE LIBTOOLIZE"
for t in ${tools[@]}
do
if [ -n "${!t}" ]; then
tool=${!t}
else
tool=`echo $t | tr '[:upper:]' '[:lower:]'`
fi
if [ -z `which $tool` &> /dev/null ]; then
echo "Error: $tool not found." >&2
exit 1
fi
export $t=$tool
done
}
function run_autotools()
{
$ACLOCAL --force $VERBOSE
$LIBTOOLIZE $DEBUG --automake --force $AUTOTOOLSCOPY
$AUTOHEADER --force $DEBUG $VERBOSE
$INTLTOOLIZE --force $DEBUG $AUTOTOOLSCOPY
update_po_dirs
$AUTOMAKE --gnu --add-missing $VERBOSE $AUTOTOOLSCOPY
$AUTOCONF $DEBUG $VERBOSE
}
function update_po_dir()
{
local l linguas
local domain=${1:+"-${1}"}
local path="po${domain}"
pushd $path >/dev/null
for l in `find . -name "*.po" |sort`
do
l=${l##*/}; l=${l%.po}
linguas="${linguas}${l}\n"
done
if [ -n "$domain" ]; then
$COPYTOOL ../po/Makefile.in.in .
test ! -r Makevars && $COPYTOOL ../po/Makevars .
fi
sed -E "/^(GETTEXT_PACKAGE|subdir) =/s/[ ]*$/$domain/"\
Makefile.in.in > Makefile.in.in.ag
test -L Makefile.in.in && rm Makefile.in.in
mv Makefile.in.in.ag Makefile.in.in
echo -en $linguas >LINGUAS
popd >/dev/null
}
function update_po_dirs()
{
update_po_dir
update_po_dir "engine"
for p in "${PO_PLUGINS[@]}"
do
local plug_name="${p##*/}"
local domain="plugin-${plug_name}"
local po_dir="po-${domain}"
test -d $po_dir || mkdir $po_dir
pushd $po_dir >/dev/null
$COPYTOOL ../${p}/po/* .
popd >/dev/null
update_po_dir $domain
done
}
function show_help()
{
echo
echo "autogen.sh usage:"
echo
echo " Produces all files necessary to build the the project."
echo " The files are sym-linked by default, if you run ./autogen.sh without an option."
echo
echo " -h Print this help message."
echo " -c Copy files instead to sym-link them."
echo " -f FILE Output everything to FILE (debugging). Useful for debug output."
echo " -v Be more verbose about every step (debugging)."
echo
echo " You can overwrite the automatically determined location of aclocal (>= 1.8),"
echo " automake (>= 1.8), autoheader, autoconf, libtoolize and intltoolize using:"
echo
echo " ACLOCAL=/opt/foo/bin/aclocal-1.9 AUTOMAKE=automake-1.9 ./autogen.sh"
echo
}
### main() ###
cd "${0%/*}"
COPYTOOL="ln -s -f"
while getopts "chvf:" options
do
case "$options" in
h)
show_help
exit 0
;;
c)
COPYTOOL="cp -p -f"
AUTOTOOLSCOPY="-c"
;;
f)
OUTPUTFILE=$OPTARG
;;
v)
DEBUG="--debug"
VERBOSE="--verbose"
set -x
;;
esac
done
if [ -n "$OUTPUTFILE" ]; then
exec &>$OUTPUTFILE
fi
get_autotools
get_output_indent
get_plugins
run_autotools