File: configure

package info (click to toggle)
deutex 4.4.902-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,096 kB
  • ctags: 996
  • sloc: ansic: 10,805; sh: 424; makefile: 337; perl: 145; csh: 4
file content (532 lines) | stat: -rwxr-xr-x 11,595 bytes parent folder | download
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/bin/sh
#
#	configure - configure script for DeuTex
#	AYM 2005-08-17
#

# This file is copyright Andr Majorel 2002-2005.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


set -e

APPNAME=deutex
VERSION=`cat VERSION`

AWK=awk
CC=
# On HP-UX 11.11, /bin/sh unsetting an unset variable returns 1
# On HP-UX 11.11 "x= unset x" is equivalent to "x=; unset x". Same with
# Bash 3.0 except when invoked through #!/bin/sh, in which case it's
# equivalent to "x=".
CFLAGS=
unset CFLAGS
HAVE_INTTYPES=
unset HAVE_INTTYPES
HAVE_SNPRINTF=
INTTYPES=
LDFLAGS=
PREFIX=/usr/local

tmpdir="$TMPDIR"
[ -n "$tmpdir" ] || tmpdir=/tmp
cbasename=${APPNAME}_$$.c
obasename=${APPNAME}_$$.o
ebasename=${APPNAME}_$$
cout=${APPNAME}_$$.out
cerr=${APPNAME}_$$.err


#
#	check - perform a test (given C code compiles and links)
#
check () {
  printf '%s' "$3" >"$tmpdir/$cbasename"
  printf 'checking %s...' "$1"
  if
  (
    cd "$tmpdir"							&&
      "$CC" $CFLAGS -o $obasename -c $cbasename				&&
      "$CC" $LDFLAGS -o $ebasename $obasename
  ) >"$tmpdir/$cout" 2>&1
  then
    echo " yes"
    eval "$2=1"
    return 0
  else
    echo " no"
    sed 's/^/> /' "$tmpdir/$cout"
    eval "$2="
    return 1
  fi
}


#
#	genbool - generate a boolean macro definition
#
genbool () {
  name=$1
  if [ -n "`eval echo \\$HAVE_$name`" ]; then
    echo "#define HAVE_$name"
  else
    echo "#undef  HAVE_$name"
  fi
}


#
#	genh - generate config.h
#
genh () {
  pathname=$BUILDDIR/config.h
  echo generating $pathname
  (
    set -e
    echo '/* DO NOT EDIT -- generated by ./configure */'
    echo
    genbool INTTYPES
    genbool SNPRINTF
    [ -z "$INTTYPES" ] || printf '\n%s\n' "$INTTYPES"
  ) >$pathname
}


#
#	fatal - abort with an error message to stderr
#
fatal ()
{
  printf 'configure: %s\n' "$@" >&2
  exit 1
}


#
#	Parse the command line
#
while [ "$#" -ge 1 ]
do
  case "$1" in
    --help)
      cat <<EOF
Usage:
  configure --help
  configure [--cc string] [--cflags string] [--ldflags strings] [--prefix path]
    [--inttypes auto|no|yes]
EOF
      exit 0
      ;;

    --cc)
      shift
      [ "$#" -ge 1 ] || fatal "--cc requires an argument"
      CC="$1"
      ;;

    --cc=*)
      CC=`expr "x$1" : 'x--cc=\(.*\)'`
      ;;

    --cflags)
      shift
      [ "$#" -ge 1 ] || fatal "--cflags requires an argument"
      CFLAGS="$1"
      ;;

    --cflags=*)
      CFLAGS=`expr "x$1" : 'x--cflags=\(.*\)'`
      ;;

    --ldflags)
      shift
      [ "$#" -ge 1 ] || fatal "--ldflags requires an argument"
      LDFLAGS="$1"
      ;;

    --ldflags=*)
      LDFLAGS=`expr "x$1" : 'x--ldflags=\(.*\)'`
      ;;

    --inttypes)
      shift
      [ "$#" -ge 1 ] || fatal "--inttypes requires an argument"
      HAVE_INTTYPES="$1"
      if [ "x$HAVE_INTTYPES" = xauto ]
      then
	unset HAVE_INTTYPES
      elif [ "x$HAVE_INTTYPES" = xno ]
      then
        HAVE_INTTYPES=
      elif [ "x$HAVE_INTTYPES" = xyes ]
      then
	HAVE_INTTYPES=1
      else
	fatal "--inttypes: the argument must be \"auto\", \"no\" or \"yes\""
      fi
      ;;

    --inttypes=*)
      HAVE_INTTYPES=`expr "x$1" : 'x--inttypes=\(.*\)'`
      if [ "x$HAVE_INTTYPES" = xauto ]
      then
	unset HAVE_INTTYPES
      elif [ "x$HAVE_INTTYPES" = xno ]
      then
        HAVE_INTTYPES=
      elif [ "x$HAVE_INTTYPES" = xyes ]
      then
	HAVE_INTTYPES=1
      else
	fatal "--inttypes: the argument must be \"auto\", \"no\" or \"yes\""
      fi
      ;;

    --prefix)
      shift
      [ "$#" -ge 1 ] || fatal "--prefix requires an argument"
      PREFIX="$1"
      ;;

    --prefix=*)
      PREFIX=`expr "x$1" : 'x--prefix=\(.*\)'`
      ;;

    -*)
      echo "configure: bad argument \"$1\"" 1>&2
      exit 1
      ;;

    *)
      echo "configure: too many arguments" 1>&2
      exit 1
  esac
  shift
done

#
#	Sanity checks
#
if expr "x$PREFIX" : x/ >/dev/null
then
  true
else
  echo "configure: --prefix: argument is not an absolute path" 1>&2
  exit 1
fi

# Solaris /bin/grep doesn't know about -Fx.
GREP=/usr/xpg4/bin/grep
[ -x $GREP ] || GREP=grep

#
#	Look for a C compiler
#
#	We try "gcc" first as commercial Unixen often have a bundled
#	"cc" command that's useless for our purposes (antiquated KNR
#	compiler or front-end that just hangs waiting for an answer from
#	some licence manager).
#
printf "looking for a C compiler..."
if [ -n "$CC" ]
then
  printf ' using user-supplied value:'
else
  CC=gcc
  if type $CC >/dev/null 2>&1
  then
    set | $GREP -q '^CFLAGS=' || CFLAGS='-O2 -Wall'
  else
    CC=c89
    if type $CC >/dev/null 2>&1
    then
      set | $GREP -q '^CFLAGS=' || CFLAGS=-O
    else
      CC=cc
      if type $CC >/dev/null 2>&1
      then
	set | $GREP -q '^CFLAGS=' || CFLAGS=-O
      else
	echo " none"
	echo "error: none of (gcc, c89, cc) work, is your PATH set right?" 1>&2
	exit 1
      fi
    fi
  fi
fi
echo " $CC"

#
#	does the C compiler actually work ?
#
printf "checking whether the C compiler works..."
(
  cd "$tmpdir"
  echo 'main (int argc, char *argv[]) { return 0; }' >$cbasename
  if
  (
    "$CC" $CFLAGS -o $obasename -c $cbasename				&&
    rm -f $ebasename							&&
    "$CC" $LDFLAGS -o $ebasename $obasename				&&
    ./$ebasename
  ) >$cout 2>&1
  then
    echo " yes"
  else
    echo " no"
    sed 's/^/> /' $cout
    echo "error: looks like the C compiler is not working" 1>&2
    exit 1
  fi
)

#
#	Do we have snprintf() ?
#
check "for snprintf" HAVE_SNPRINTF '
#include <stdio.h>
int main (int argc, char *argv[])
{
  char buf[1];
  int n = snprintf (buf, sizeof buf, "%d", 42);
  return n;
}
' || true

#
#	Do we have inttypes.h ?
#
printf 'checking for inttypes.h...'
if [ -n "$HAVE_INTTYPES" ]
then
  echo " yes (forced)"
elif set | $GREP -q '^HAVE_INTTYPES='
then
  echo " no (forced)"
else
  if
  (
    cd "$tmpdir"							&&
      cat <<\EOF >$cbasename						&&
#include <inttypes.h>
#include <stdio.h>

#define CHECKSIZE(type, size)						\
do									\
{									\
  printf ("%s %u\n", #type, (unsigned) sizeof (type));			\
  if (sizeof (type) != (size))						\
  {									\
    fflush (stdout);							\
    fprintf (stderr, "inttypes: size of %s is %u, expected %u\n",	\
      #type, (unsigned) sizeof (type), (unsigned) (size));		\
    status = 1;								\
  }									\
}									\
while (0)

int main (int argc, char *argv[])
{
  int status = 0;

  CHECKSIZE (int8_t,   1);
  CHECKSIZE (int16_t,  2);
  CHECKSIZE (int32_t,  4);
  CHECKSIZE (uint8_t,  1);
  CHECKSIZE (uint16_t, 2);
  CHECKSIZE (uint32_t, 4);
  return status;
}
EOF
      "$CC" $CFLAGS -o $obasename -c $cbasename				&&
      rm -f $ebasename							&&
      "$CC" $LDFLAGS -o $ebasename $obasename				&&
      ./$ebasename
  ) >"$tmpdir/$cout" 2>&1
  then
    echo " yes"
    HAVE_INTTYPES=1
  else
    echo " no"
  fi
fi

#
#	If we don't have <inttypes.h>, make our own definitions for
#	{int,uint}{8,16,32}_t
#
if [ -z "$HAVE_INTTYPES" ]
then
  printf 'guessing at appropriate types for {int,uint}{8,16,32}_t...'
  if
  (
    cd "$tmpdir"							&&
      cat <<\EOF >$cbasename						&&
#include <assert.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
  assert (sizeof (signed char) == 1);
  puts ("typedef signed char    int8_t;");
  assert (sizeof (short) == 2);
  puts ("typedef short          int16_t;");
  if (sizeof (long) == 4)
    puts ("typedef long           int32_t;");
  else if (sizeof (int) == 4)
    puts ("typedef int            int32_t;");
  else
    fprintf (stderr,
      "no 32-bit signed type (sizeof (long) = %u, sizeof (int) = %u)\n",
      (unsigned) sizeof (long), (unsigned) sizeof (int));

  assert (sizeof (unsigned char) == 1);
  puts ("typedef unsigned char  uint8_t;");
  assert (sizeof (unsigned short) == 2);
  puts ("typedef unsigned short uint16_t;");
  if (sizeof (unsigned long) == 4)
    puts ("typedef unsigned long  uint32_t;");
  else if (sizeof (unsigned int) == 4)
    puts ("typedef unsigned int   uint32_t;");
  else
    fprintf (stderr,
      "no 32-bit unsigned type (sizeof (unsigned long) = %u, sizeof (unsigned)"
      " = %u)\n",
      (unsigned) sizeof (unsigned long), (unsigned) sizeof (unsigned int));
  return 0;
}
EOF
      "$CC" $CFLAGS -o $obasename -c $cbasename				&&
      rm -f $ebasename							&&
      "$CC" $LDFLAGS -o $ebasename $obasename				&&
      ./$ebasename >$cout 2>$cerr
  )
  then
    echo " success"
    INTTYPES=`cat "$tmpdir/$cout"`
  else
    echo " failure"
    cat "$tmpdir/$cerr"
    echo 'Report this bug to the maintainer!'
    exit 1
  fi
fi

#
#	Locate a POSIX-compatible awk(1)
#
printf "checking for a standard-compliant awk..."
if
(
  cd "$tmpdir"								&&
    echo a | $AWK '{ print sub(/^a/, "b") $0 }' >$cout 2>&1		&&
    [ "x`cat $tmpdir/$cout`" = "x1b" ]
)
then
  echo " yes"
else
  AWK=/usr/xpg4/bin/awk
  if
  (
    cd "$tmpdir"							&&
      echo a | $AWK '{ print sub(/^a/, "b") $0 }' >$cout 2>&1		&&
      [ "x`cat $tmpdir/$cout`" = "x1b" ]
  )
  then
    echo " yes ($AWK)"
  else
    echo " no"
    fatal "no suitable awk found, is your PATH set right?"
  fi
fi

#
#	Create the directory where the build-specific files go
#
SYSTEM_RAW=`uname -n`_`uname -a | cksum`
SYSTEM=`echo "$SYSTEM_RAW" | tr -dc '[:alnum:]._-'`
BUILDDIR=src
echo "build directory is $BUILDDIR"
[ -d $BUILDDIR ] || mkdir -p $BUILDDIR

#
#	FHS paths
#
if expr "$PREFIX" : '//*usr/*$' >/dev/null
then
  BINDIR=/usr/games
  ETCDIR=/etc/$APPNAME/%v
  ETCDIRNV=/etc/$APPNAME
  MANDIR=/usr/share/man
  SHAREDIR=/usr/share/games/$APPNAME/%v
  SHAREDIRNV=/usr/share/games/$APPNAME
elif expr "$PREFIX" : '//*usr//*local/*$' >/dev/null
then
  BINDIR=/usr/local/bin		# FHS-ly correct is /usr/local/games
  ETCDIR=/etc/$APPNAME/%v
  ETCDIRNV=/etc/$APPNAME
  MANDIR=/usr/local/man
  SHAREDIR=/usr/local/share/games/$APPNAME/%v
  SHAREDIRNV=/usr/local/share/games/$APPNAME
elif expr "$PREFIX" : '//*opt/*$' >/dev/null
then
  echo '/opt ? Surely you mean /opt/something, Mr. Feynman !' 1>&2
  exit 1
elif expr "$PREFIX" : '//*opt//*[^/]' >/dev/null
then
  BINDIR=$PREFIX/bin
  ETCDIR=/etc/opt/`expr "$PREFIX" : '//*opt//*\(.*\)'`
  ETCDIRNV=
  MANDIR=$PREFIX/man
  SHAREDIR=$PREFIX/share
  SHAREDIRNV=
else					# Probably /home/joe/*
  BINDIR=$PREFIX/bin
  ETCDIR=$PREFIX/etc
  ETCDIRNV=
  MANDIR=$PREFIX/man
  SHAREDIR=$PREFIX/share
  SHAREDIRNV=
fi

#
#	Write Makefile.config
#
echo generating Makefile
(
  echo "# DO NOT EDIT -- generated by ./configure"
  echo
  echo "AWK               = $AWK"
  echo "BINDIR            = \$(DESTDIR)/$BINDIR"
  echo "CC                = $CC"
  echo "CFLAGS            = $CFLAGS"
  echo "ETCDIR            = \$(DESTDIR)/$ETCDIR" | sed "s/%v/$VERSION/g"
  echo "ETCDIRNV          = \$(DESTDIR)/$ETCDIRNV"
  echo "HAVE_INTTYPES     = $HAVE_INTTYPES"
  echo "HAVE_SNPRINTF     = $HAVE_SNPRINTF"
  echo "LDFLAGS           = $LDFLAGS"
  echo "MANDIR            = \$(DESTDIR)/$MANDIR"
  echo "SHAREDIR          = \$(DESTDIR)/$SHAREDIR" | sed "s/%v/$VERSION/g"
  echo "SHAREDIRNV        = \$(DESTDIR)/$SHAREDIRNV"
  echo
  cat Makefile.in
) >Makefile

#
#	Write config.h
#
genh

exit 0