-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.sub
More file actions
422 lines (356 loc) · 10.1 KB
/
config.sub
File metadata and controls
422 lines (356 loc) · 10.1 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#
# Copyright (c) 2016 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.
#
###### PRIVATE ######
ARGV=$*
PACKAGE_NAME=myprogram
PACKAGE_VERSION=0.0.1
# TOPDIR=""
# DISTFILES=""
# SUBDIRS=""
# LIBRARIES=""
# If set to "yes", this is the top-level ./configure script within the project
TOP_LEVEL="yes"
# Sections within the makefile
_mf_vars=""
_mf_default_target="all: "
_mf_targets=""
_mf_install_rules="install:"
_mf_dependencies=""
_mf_clean_files=""
log_debug() {
message="[DEBUG] $*"
printf "%s\n" "$message" >> config.log
}
err() {
message="[ERROR] $*"
printf "%s\n" "$message" >> config.log
echo "*** ERROR *** $*"
exit 1
}
###### PUBLIC #######
init_maketool() {
rm -f config.log
test -n "$CC" || CC="cc"
echo "/* Automatically generated -- do not edit */" > config.h
echo "# Automatically generated -- do not edit" > config.mk
echo "# Automatically generated -- do not edit" > vars.sh
# Assume that all subdirectories share a common "config.sub"
# at the top-level. Use this assumption to detect what level we
# are at
test -f config.sub || TOP_LEVEL="no"
}
package_version() {
_version=$1
PACKAGE_VERSION=$_version
MAJOR_VERSION=`echo $_version | cut -f1 -d.`
MINOR_VERSION=`echo $_version | cut -f2 -d.`
PATCH_VERSION=`echo $_version | cut -f3 -d.`
}
package() {
PACKAGE_NAME=$1
package_version $2
}
getopt() {
match=$1
handler=$2
for arg in $ARGV ; do
if [ $arg = $match ] ; then
eval "$handler"
break
fi
done
}
# A custom target supplied by the user
target() {
_body=$1
EXTRA_TARGETS="$EXTRA_TARGETS
$_body
"
}
# A variable definition in the Makefile
make_define() {
_ident=$1
shift
printf "%s=%s\n" "$_ident" "$*" >> config.mk
printf "%s=\"%s\"\n" "$_ident" "$*" >> vars.sh
eval "$_ident=\"$*\""
}
check_header() {
_header=$1
_sym=`echo $_header | tr 'a-z' 'A-Z' | sed 's/[\-\.\/]/_/g'`
_lc_sym=`echo $_sym | tr 'A-Z' 'a-z'`
printf "checking for the existence of <$_header>.. "
printf "#include <sys/types.h>\n#include <$_header>\nint main() {}\n" > test-$$.c
eval "$CC -I/usr/local/include $CFLAGS -o /dev/null test-$$.c >> config.log 2>&1"
if [ $? -eq 0 ] ; then
echo yes ; val=1
else
echo no ; val=0
fi
rm -f test-$$.c
echo "#define HAVE_$_sym $val" >> config.h
eval "check_header_${_lc_sym}=$val"
}
emit_scripts() {
for _prog in $bin_SCRIPTS ; do
DISTFILES="$DISTFILES $program"
_mf_install_rules="$_mf_install_rules
\$(INSTALL) -m 755 $TOPDIR$_prog \$\$DESTDIR\$(BINDIR)"
done
for _prog in $sbin_SCRIPTS ; do
DISTFILES="$DISTFILES $program"
_mf_install_rules="$_mf_install_rules
\$(INSTALL) -m 755 $TOPDIR$_prog \$\$DESTDIR\$(SBINDIR)"
done
}
emit_compilation_units() {
_prefix=$1
_all_mkdeps=""
for source in $sources ; do
_obj=`echo $source | sed 's/\.c\$/.o/' | sed 's/.*\///'`
test -n "$_prefix" && _obj="${_prefix}${_obj}"
_mkdep_command="$CC $cflags $CFLAGS -MM -MT $_obj"
log_debug "checking dependencies of ${_obj}:\\n + ${_mkdep_command} ${source}"
_mkdeps=`${_mkdep_command} $source 2>>config.log`
test $? -eq 0 || err "Unable to generate dependencies for $source"
_all_mkdeps="$_all_mkdeps `echo $_mkdeps | head -1 | sed 's/.*: //'`"
_mf_dependencies="$_mf_dependencies
$_mkdeps
\$(CC) -c $cflags \$(CFLAGS) -o \$@ $source
"
done
DISTFILES="$DISTFILES $_all_mkdeps"
}
emit_static_library() {
_mf_install_rules="$_mf_install_rules
\$(INSTALL) -m 755 ${_library}.a \$\$DESTDIR\$(LIBDIR)"
_objs=`echo $sources | sort | sed 's/\.c/.o/g'`
_curdir_objs=`for x in $_objs ; do basename $x ; done | sed 's/^/static-/g' | tr '\n' ' '`
_mf_default_target="$_mf_default_target ${_library}.a"
_mf_clean_files="$_mf_clean_files ${_library}.a"
_mf_targets="$_mf_targets
${_library}.a: $_curdir_objs $depends
\$(AR) rcs ${_library}.a $_curdir_objs
"
emit_compilation_units 'static-'
}
emit_shared_library() {
_saved_cflags=$cflags
_mf_install_rules="$_mf_install_rules
\$(INSTALL) -s -m 755 $realname \$\$DESTDIR\$(LIBDIR)
\$(INSTALL) -ls $realname \$\$DESTDIR\$(LIBDIR)/$soname
\$(INSTALL) -ls $realname \$\$DESTDIR\$(LIBDIR)/$_library.so
"
_objs=`echo $sources | sort | sed 's/\.c/.o/g'`
_curdir_objs=`for x in $_objs ; do basename $x ; done | tr '\n' ' '`
_mf_default_target="$_mf_default_target $realname"
_mf_clean_files="$_mf_clean_files $realname $soname $_library.so"
_mf_targets="$_mf_targets
$realname: $_curdir_objs $depends
\$(CC) -shared -fvisibility=hidden -Wl,-soname,$soname -o \$@ \\
$ldflags \$(LDFLAGS) $_curdir_objs $ldadd \$(LDADD)
"
cflags="$cflags -fpic -fvisibility=hidden"
emit_compilation_units ''
cflags=$_saved_cflags
}
emit_libraries() {
for _library in $LIBRARIES; do
# common to all targets
eval "sources=\$${_library}_SOURCES"
eval "cflags=\$${_library}_CFLAGS"
eval "ldflags=\$${_library}_LDFLAGS"
eval "ldadd=\$${_library}_LDADD"
eval "depends=\$${_library}_DEPENDS"
# specific to libraries
eval "soname=\$${_library}_SONAME"
eval "realname=\$${_library}_REALNAME"
emit_static_library
emit_shared_library
done
}
emit_programs() {
# Build a list of all of the programs along with
# where to install them
_all_programs=""
for program in $bin_PROGRAMS ; do
_all_programs="$_all_programs \$(BINDIR)|$program"
done
for program in $sbin_PROGRAMS ; do
_all_programs="$_all_programs \$(SBINDIR)|$program"
done
for program in $TESTS ; do
_all_programs="$_all_programs /dev/null|$program"
done
for _rec in $bin_PROGRAMS $sbin_PROGRAMS $TESTS; do
program=`echo $_rec | cut -f1 -d\|`
_install_to=`echo $_rec | cut -f2 -d\|`
if [ "$_install_to" != "/dev/null" ] ; then
_mf_install_rules="$_mf_install_rules
\$(INSTALL) -s -m 755 $TOPDIR$program \$\$DESTDIR\$(SBINDIR)"
fi
eval "sources=\$${program}_SOURCES"
eval "cflags=\$${program}_CFLAGS"
eval "ldflags=\$${program}_LDFLAGS"
eval "ldadd=\$${program}_LDADD"
eval "depends=\$${program}_DEPENDS"
_objs=`echo $sources | sort | sed 's/\.c/.o/g'`
_curdir_objs=`for x in $_objs ; do basename $x ; done | tr '\n' ' '`
_mf_default_target="$_mf_default_target $program"
_mf_clean_files="$_mf_clean_files $program"
_mf_targets="$mf_targets
$TOPDIR$program: $_curdir_objs $depends
\$(CC) -o \$@ $ldflags \$(LDFLAGS) $_curdir_objs $ldadd \$(LDADD)
"
emit_compilation_units
done
}
# Add any vendor tarballs to the distribution
emit_vendored_items() {
if [ -x ./vendor ] ; then
for dep in `find ./vendor -depth 1 -name '*.gz' -o -name '*.tgz'` ; do
DISTFILES="$DISTFILES $dep"
done
fi
}
emit_tests() {
if [ -z "$TOPDIR" ] ; then
_topdir="./"
else
_topdir="./$TOPDIR"
fi
# _mf_vars="$_mf_vars
#TESTS=$TESTS"
_test_rules=`echo $TESTS | tr ' ' '\n' | sed "s,^, $_topdir,"`
if [ -n "$TESTS" ] ; then
_mf_targets="$_mf_targets
check: $TESTS
$_test_rules
"
else
_mf_targets="$_mf_targets
check:
"
fi
if [ -n "$SUBDIRS" ] ; then
_mf_targets="$_mf_targets
for dir in $SUBDIRS ; do cd \$\$dir && \$(MAKE) check && cd .. ; done
"
fi
}
emit_packaging() {
if [ "$TOP_LEVEL" = "no" ] ; then return ; fi
_mf_packaging="PACKAGE_NAME=$PACKAGE_NAME
PACKAGE_VERSION=$PACKAGE_VERSION
MAJOR_VERSION=$MAJOR_VERSION
MINOR_VERSION=$MINOR_VERSION
PATCH_VERSION=$PATCH_VERSION
PREFIX ?= /usr/local
LIBDIR = \$(PREFIX)/lib
BINDIR = \$(PREFIX)/bin
SBINDIR = \$(PREFIX)/sbin
LIBEXECDIR = \$(PREFIX)/libexec
MANDIR = \$(PREFIX)/man
SYSCONFDIR = \$(PREFIX)/etc
DATADIR = \$(PREFIX)/share
LOCALSTATEDIR = /var
RUNSTATEDIR = \$(LOCALSTATEDIR)/run
INSTALL ?= /usr/bin/install
"
}
emit_distribution() {
if [ "$TOP_LEVEL" = "no" ] ; then return ; fi
_distfiles=`echo "$DISTFILES" | tr ' ' '\n' | sort | uniq | tr '\n' ' '`
_mf_distribution="dist:
mkdir \$(PACKAGE_NAME)-\$(PACKAGE_VERSION)
for file in $_distfiles ; do \
install -d \$(PACKAGE_NAME)-\$(PACKAGE_VERSION)/\`dirname \$\$file\` ; \
install \$\$file \$(PACKAGE_NAME)-\$(PACKAGE_VERSION)/\$\$file ; \
done
tar cf \$(PACKAGE_NAME)-\$(PACKAGE_VERSION).tar.gz \$(PACKAGE_NAME)-\$(PACKAGE_VERSION)
rm -rf \$(PACKAGE_NAME)-\$(PACKAGE_VERSION)
"
}
emit_cleanup() {
_mf_clean_rules="clean:
rm -f *.o $_mf_clean_files"
if [ -n "$SUBDIRS" ] ; then
_mf_clean_rules="$_mf_clean_rules
for dir in $SUBDIRS ; do cd \$\$dir && \$(MAKE) clean && cd .. ; done
"
fi
}
emit_subdir_rules() {
if [ -z "$SUBDIRS" ] ; then return ; fi
_mf_default_target="$_mf_default_target
for dir in $SUBDIRS ; do cd \$\$dir && \$(MAKE) all && cd .. ; done
"
}
emit_platform_tweaks() {
if [ `uname` = 'Linux' ] ; then
_mf_vars="$mf_vars
CFLAGS+=-D_GNU_SOURCE"
fi
}
write_makefile() {
emit_packaging
emit_programs
emit_libraries
emit_scripts
emit_tests
emit_distribution
emit_cleanup
emit_subdir_rules
emit_vendored_items
emit_platform_tweaks
if [ -z "$TOPDIR" ] ; then
_outfile="Makefile"
else
_outfile="Makefile.inc"
fi
echo "creating $_outfile"
cat <<__EOF__ >$_outfile
# Automatically generated -- do not edit
$_mf_packaging
$_mf_vars
# Files to include in the tarball
DISTFILES = ${TOPDIR}configure ${TOPDIR}config.sub $DISTFILES
$_mf_default_target
$_mf_targets
$_mf_distribution
$_mf_install_rules
$_mf_clean_rules
$_mf_dependencies
$EXTRA_TARGETS
.PHONY: clean check
__EOF__
# Convert C preprocessor definitions into shell variables
egrep '^#define' config.h | sed 's/^#define //; s/ /=/' >> vars.sh
# Perform recursive ./configure invocation
if [ -n "$SUBDIRS" ] ; then
for x in $SUBDIRS ; do
echo "configuring ./$x"
cd $x
./configure
test $? -eq 0 || err "Unable to run configure in ./$x/"
cd ..
done
fi
}
#
# MAIN()
#
init_maketool