configure.ac 10.7 KB
Newer Older
Stephan Herhut's avatar
Stephan Herhut committed
1
dnl
2
dnl $Id$
Stephan Herhut's avatar
Stephan Herhut committed
3
4
5
dnl

dnl configure script for building sac2c compiler 
6
dnl on different hosts and operating systems
Stephan Herhut's avatar
Stephan Herhut committed
7
8
9

dnl tell configure who we are
dnl parameters: package name, version, where to send bugreports
Clemens Grelck's avatar
Clemens Grelck committed
10
AC_INIT(sac2c, svn, info@sac-home.org)
Stephan Herhut's avatar
Stephan Herhut committed
11
12

dnl set source directory and scripting directory
Stephan Herhut's avatar
Stephan Herhut committed
13
AC_CONFIG_SRCDIR(.)
Stephan Herhut's avatar
Stephan Herhut committed
14
15
16
17
18
19
AC_CONFIG_AUX_DIR(./config)

dnl we use C as our compiler language
AC_LANG(C)

dnl and which files to create
20
21
AC_CONFIG_FILES(../src/makefiles/config.mkf sac2crc)
AC_CONFIG_HEADER(../src/include/config.h)
Stephan Herhut's avatar
Stephan Herhut committed
22
23
24
25
26
27
28
29
30
31
32
33
34

dnl check for host type
AC_CANONICAL_BUILD()
AC_CANONICAL_HOST()
AC_CANONICAL_TARGET()

dnl set OS and ARCH flags
AC_DEFINE_UNQUOTED(OS,"$target_os",set to the os type)
AC_SUBST(OS,$target_os)
AC_DEFINE_UNQUOTED(ARCH,"$target_cpu",set to the architecture)
AC_SUBST(ARCH,$target_cpu)

dnl search for a C compiler
Stephan Herhut's avatar
Stephan Herhut committed
35
AC_PROG_CC(gcc cc)
Stephan Herhut's avatar
Stephan Herhut committed
36

37
dnl
Stephan Herhut's avatar
Stephan Herhut committed
38
dnl check whether its suns cc
39
40
dnl

Stephan Herhut's avatar
Stephan Herhut committed
41
42
43
44
45
46
47
48
49
50
51
AC_MSG_CHECKING(whether cc is a Sun Pro C compiler)
AC_TRY_COMPILE(,
[#ifndef __SUNPRO_C
  choke me
#endif],
AC_MSG_RESULT(yes)
SUNC=yes,
AC_MSG_RESULT(no)
SUNC=no
)

52
53

dnl
54
dnl check whether its compaqs (or dec) cc
55
56
dnl

Stephan Herhut's avatar
Stephan Herhut committed
57
58
59
60
61
62
63
64
65
66
67
AC_MSG_CHECKING(whether cc is a Compaq/DEC C compiler)
AC_TRY_COMPILE(,
[#ifndef __DECC
  choke me
#endif],
AC_MSG_RESULT(yes)
DECC=yes,
AC_MSG_RESULT(no)
DECC=no
)

68
69

dnl
Stephan Herhut's avatar
Stephan Herhut committed
70
dnl check whether its apples cc
71
72
dnl

Stephan Herhut's avatar
Stephan Herhut committed
73
74
75
76
77
78
79
80
81
82
83
84
AC_MSG_CHECKING(whether cc is a Apple compiler)
AC_TRY_COMPILE(,
[#ifndef __APPLE__
  choke me
  #endif],
  AC_MSG_RESULT(yes)
  MACC=yes
  GCC=no,
  AC_MSG_RESULT(no)
  MACC=no
)
  
85
86

dnl
Stephan Herhut's avatar
Stephan Herhut committed
87
dnl check whether popen is an extension
88
89
dnl

Stephan Herhut's avatar
Stephan Herhut committed
90
91
92
93
94
95
96
97
98
99
AC_MSG_CHECKING([need of _EXTENSIONS_ flag])
AC_TRY_COMPILE([#include <stdio.h>],[popen("rw","testfile")],
AC_MSG_RESULT(no)
need_ext_flags=no,
AC_MSG_RESULT(yes)
need_ext_flags=yes)

dnl check for C preprocessor
AC_PROG_CPP()

100
101
102
103
104
dnl check for ranlib
AC_PROG_RANLIB()
if test "$RANLIB"; then
  AC_MSG_CHECKING([whether ranlibs needs extra argument])
  case "$target_os" in
Stephan Herhut's avatar
Stephan Herhut committed
105
    *darwin*) RANLIB="$RANLIB -c"
106
107
108
109
110
111
112
113
    AC_MSG_RESULT([adding -c flag for OS X])
    ;;
    *)
    AC_MSG_RESULT([no])
    ;;
  esac
fi

Stephan Herhut's avatar
Stephan Herhut committed
114
115
116
dnl check, whether we need -traditinal flag
AC_PROG_GCC_TRADITIONAL

117
dnl
118
dnl check whether its gnu indent
119
120
dnl

121
AC_MSG_CHECKING([whether GNU indent works])
122
GNUINDENT=$(indent --version 2>/dev/null)
123
124
125
126
127
128
case "$GNUINDENT" in
  *GNU*) 
    CB="indent"
    AC_MSG_RESULT(yes)
    ;;
  *) 
129
130
131
132
133
134
135
    GNUINDENT=$(gindent --version 2>/dev/null)
    case "$GNUINDENT" in
    *GNU*)
      CB="gindent"
      AC_MSG_RESULT(yes)
      ;;
    *)
Clemens Grelck's avatar
Clemens Grelck committed
136
      CB="\$(PROJECT_ROOT)/src/bin/cb"
137
138
139
      AC_MSG_RESULT(no)
      ;;
    esac
140
141
esac
AC_SUBST(CB, $CB)
142

Stephan Herhut's avatar
Stephan Herhut committed
143
144
145
dnl search for bison, byacc or yacc
AC_PROG_YACC()

146
147

dnl
Stephan Herhut's avatar
Stephan Herhut committed
148
dnl check whether a non yacc works
149
150
dnl

Stephan Herhut's avatar
Stephan Herhut committed
151
152
153
154
if [ test "$YACC" != "yacc" ]; then
  AC_MSG_CHECKING([whether $YACC works])
  mkdir .ac_yacc_test
  cd .ac_yacc_test
155
  cp ../../src/libsac2c/scanparse/sac.y .
Stephan Herhut's avatar
Stephan Herhut committed
156
  if [ $YACC sac.y >/dev/null 2>/dev/null ]; then
Stephan Herhut's avatar
Stephan Herhut committed
157
158
159
    AC_MSG_RESULT(ok)
  else
    AC_MSG_RESULT(failed)
Stephan Herhut's avatar
Stephan Herhut committed
160
161
162
163
164
165
    AC_CHECK_PROG(YACC, [yacc], [yacc], [!fail])
    if [ test "$YACC" != "yacc" ]; then
      AC_MSG_ERROR([cannot find working bison/yacc], 10)
    else
      AC_MSG_NOTICE([using yacc instead])
    fi
Stephan Herhut's avatar
Stephan Herhut committed
166
167
168
169
170
  fi
  cd ..
  rm -rf .ac_yacc_test
fi

Stephan Herhut's avatar
Stephan Herhut committed
171
172
173
dnl search for flex or lex
AC_PROG_LEX()

174
dnl search for xlst engine
175
AC_CHECK_PROGS(XSLT, [xsltproc sabcmd], [!fail])
176

177
178
179
dnl search for m4 macro processor
AC_CHECK_PROGS(M4, [gm4 m4], [!fail])

Stephan Herhut's avatar
Stephan Herhut committed
180
181
182
dnl search for malloc.h
AC_CHECK_HEADERS(malloc.h)

Stephan Herhut's avatar
Stephan Herhut committed
183
184
185
dnl check for mkdtemp
AC_CHECK_FUNCS(mkdtemp)

Stephan Herhut's avatar
Stephan Herhut committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
dnl search for pthread.h
AC_CHECK_HEADER(pthread.h,[

dnl if found, enable multi threading
AC_DEFINE(HAVE_PTHREAD_H, 1, set to 1 if you have the <pthread.h> header file)
AC_SUBST(DISABLE_MT, no)

],[

dnl otherwise disable mt
AC_DEFINE(DISABLE_MT, 1, set to 1 to disable multi threading)
AC_SUBST(DISABLE_MT, yes)

])

Stephan Herhut's avatar
Stephan Herhut committed
201
dnl check whether to link math library
Stephan Herhut's avatar
Stephan Herhut committed
202
AC_SEARCH_LIBS(sqrt, m)
Stephan Herhut's avatar
Stephan Herhut committed
203

204
205
206
dnl check whether to link dlopen library
AC_SEARCH_LIBS(dlopen, dl)

Stephan Herhut's avatar
Stephan Herhut committed
207
208
209
210
211
212
213
214
215
216
dnl checking for presence of strtok and strrchr
AC_CHECK_FUNCS([strtok strrchr])

dnl check for sbrk function
AC_CHECK_FUNC(sbrk, [

dnl if found, check type
dnl  check definition of sbrk
AC_MSG_CHECKING(for sbrk argument type)
include_file_list=`ls -1 /usr/include/*.h`
Stephan Herhut's avatar
Stephan Herhut committed
217
sbrk_types=`for name in $include_file_list; do grep sbrk $name 2>/dev/null; done`
Stephan Herhut's avatar
Stephan Herhut committed
218
[sbrk_types=`echo "$sbrk_types" | sed -e 's/[A-Za-z0-9 _*]*([ ]*//g' | sed -e 's/)[A-Za-z0-9_* ;]*//g' | sed -e 's/ [A-Za-z0-9_* ]*//g'` ]
Stephan Herhut's avatar
Stephan Herhut committed
219
[ for name in $sbrk_types; do ]
Stephan Herhut's avatar
Stephan Herhut committed
220
221
222
223
224
225
226
227
228
 AC_TRY_COMPILE([#include <unistd.h>],[sbrk(($name) 0)],break,name=none)
[ done ]

[ if test $name = none ; then ]
AC_DEFINE(DISABLE_PHM, 1)
AC_SUBST(DISABLE_PHM, yes)
AC_MSG_RESULT(not found)
[ else ]
AC_DEFINE_UNQUOTED(SBRK_T,$name,set to the type of sbrk argument)
Stephan Herhut's avatar
Stephan Herhut committed
229
AC_MSG_RESULT($name)
Stephan Herhut's avatar
Stephan Herhut committed
230
AC_SUBST(DISABLE_PHM, no)
Stephan Herhut's avatar
Stephan Herhut committed
231
[ fi ]
Stephan Herhut's avatar
Stephan Herhut committed
232
233
234
235
236
237
238
],[

dnl otherwise disable pm
AC_DEFINE(DISABLE_PHM, 1, set to disable private heapmanagement)
AC_SUBST(DISABLE_PHM, yes)
])

239
240
241
242
243
244
245
dnl hack, as we don't know why phm doesn't work
dnl on macs. just disable it there
case "$target_os" in
    *darwin*) AC_DEFINE(DISABLE_PHM, 1)
              AC_SUBST(DISABLE_PHM, yes)
esac

246
247

dnl
Stephan Herhut's avatar
Stephan Herhut committed
248
dnl check if printf generates leading 0x for pointers
249
250
dnl

Stephan Herhut's avatar
Stephan Herhut committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
AC_MSG_CHECKING(for 0x prefix when printing pointers)
AC_EGREP_CPP(0x0*,
[#include <stdio.h>
int main()
{
printf("%p", (void*) 0);
}
], has_ptr_prefix=yes, has_ptr_prefix=no)
if [ test $has_ptr_prefix = yes ]; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
  AC_DEFINE(NEED_PTR_PREFIX, 1, set to 1 if printf does not print a leading
0x in front of pointers)
fi

267
268

dnl
Stephan Herhut's avatar
Stephan Herhut committed
269
dnl check if stderr is a constant (needed for dbug.c
270
271
dnl

Stephan Herhut's avatar
Stephan Herhut committed
272
273
274
275
AC_MSG_CHECKING(whether stderr is a constant)
AC_TRY_COMPILE([
#include <stdio.h>
#include <unistd.h>
Stephan Herhut's avatar
Stephan Herhut committed
276
277
#include <stdlib.h>

Stephan Herhut's avatar
Stephan Herhut committed
278
FILE *_db_fp_ = stderr;
279
],[],stderr_is_constant=yes,stderr_is_constant=no)
Stephan Herhut's avatar
Stephan Herhut committed
280
281
282
283
284
285
286
if [ test $stderr_is_constant = yes ]; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(STDERR_IS_CONSTANT, 1, set to 1 if stderr is a constant)
else
  AC_MSG_RESULT(no)
fi

287
288
289
290
291

dnl
dnl when not using bison, we need to reference YYLABELS
dnl

292
if test "$YACC" = "obsolete_yacc"; then
Stephan Herhut's avatar
Stephan Herhut committed
293
294
295
  AC_DEFINE(MUST_REFERENCE_YYLABELS, 1, set to 1 if gcc complains about unused labels)
fi

296
dnl
Stephan Herhut's avatar
Stephan Herhut committed
297
dnl check for pthread flag on gcc
298
299
dnl

Stephan Herhut's avatar
Stephan Herhut committed
300
301
302
if test "$GCC" = yes; then
  AC_MSG_CHECKING([existence of pthread flag])
  echo "int main(){return 0;}" > .sac_configure_temp.c
303
  if test "`gcc -o .sac_configure_temp -pthread .sac_configure_temp.c 2>&1 | grep "unrecognized option"`" = ""; then
Stephan Herhut's avatar
Stephan Herhut committed
304
305
306
307
308
309
    AC_MSG_RESULT([supported])
    GCC_PTHREADS="-pthread"
  else
    AC_MSG_RESULT([unsupported])
    GCC_PTHREADS="-lpthread"
  fi
310
  rm -f .sac_configure_temp.c .sac_configure_temp
Stephan Herhut's avatar
Stephan Herhut committed
311
fi
312
313
314
315
316
317


dnl
dnl test for compiler flags for sac2crc
dnl

Stephan Herhut's avatar
Stephan Herhut committed
318
319
320
321
322
323
324
325
AC_MSG_CHECKING([sac2crc compiler flags])
if [ test "$GCC" = yes ]; then
  AC_SUBST(OPT_O0, [""])
  AC_SUBST(OPT_O1, [-O1])
  AC_SUBST(OPT_O2, [-O2])
  AC_SUBST(OPT_O3, [-O3])
  AC_SUBST(OPT_g, [-g])
  AC_SUBST(RCLDFLAGS, [""])
326
  AC_SUBST(RCCCFLAGS, ["-Wall -Wno-unused -fno-builtin -fPIC -DPIC"])
Sven-Bodo Scholz's avatar
   
Sven-Bodo Scholz committed
327
328
  AC_SUBST(MKCCFLAGS, ["-Wall -g -std=c99"])
  AC_SUBST(PDCCFLAGS, ["-Wall -g -O3 -std=c99"])
Stephan Herhut's avatar
Stephan Herhut committed
329
  AC_SUBST(DEPSFLAG, ["-M"])
330
  AC_SUBST(CPPFILE, ["gcc -E -C -x c"])
Stephan Herhut's avatar
Stephan Herhut committed
331
  AC_SUBST(CCMTLINK, [$GCC_PTHREADS])
Stephan Herhut's avatar
Stephan Herhut committed
332
333
334
335
336
  AC_MSG_RESULT([gcc settings])
elif [ test "$SUNC" = yes ]; then
  AC_SUBST(OPT_O0, [""])
  AC_SUBST(OPT_O1, [-xO2])
  AC_SUBST(OPT_O2, [-xO4])
337
  AC_SUBST(OPT_O3, [-xO5])
Stephan Herhut's avatar
Stephan Herhut committed
338
339
340
  AC_SUBST(OPT_g, [-g])
  AC_SUBST(RCLDFLAGS, [""])
  AC_SUBST(RCCCFLAGS, ["-dalign -fsimple -xsafe=mem"])
Stephan Herhut's avatar
Stephan Herhut committed
341
342
  AC_SUBST(MKCCFLAGS, ["-erroff=E_CAST_DOESNT_YIELD_LVALUE -g -xc99=all -KPIC"])
  AC_SUBST(PDCCFLAGS, ["-erroff=E_CAST_DOESNT_YIELD_LVALUE -g -xO4 -xc99=all -KPIC"])
Stephan Herhut's avatar
Stephan Herhut committed
343
  AC_SUBST(DEPSFLAG, ["-xM"])
344
  AC_SUBST(CPPFILE, ["cc -E -C -x c"])
345
  AC_SUBST(CCMTLINK, ["-lpthread"])
Stephan Herhut's avatar
Stephan Herhut committed
346
347
348
  AC_MSG_RESULT([Sun cc settings])
elif [ test "$DECC" = yes ]; then
  AC_SUBST(OPT_O0, [""])
Stephan Herhut's avatar
Stephan Herhut committed
349
350
  AC_SUBST(OPT_O1, [-O1])
  AC_SUBST(OPT_O2, [-O2])
351
  AC_SUBST(OPT_O3, [-O3])
Stephan Herhut's avatar
Stephan Herhut committed
352
  AC_SUBST(OPT_g, [-g])
353
  AC_SUBST(RCLDFLAGS, [""])
Stephan Herhut's avatar
Stephan Herhut committed
354
355
356
357
  AC_SUBST(RCCCFLAGS, [""])
  AC_SUBST(MKCCFLAGS, ["-g"])
  AC_SUBST(PDCCFLAGS, ["-g3"])
  AC_SUBST(DEPSFLAG, ["-M"])
358
  AC_SUBST(CPPFILE, ["cc -E -C -x c"])
359
  AC_SUBST(CCMTLINK, ["-pthread"])
Stephan Herhut's avatar
Stephan Herhut committed
360
361
362
  AC_MSG_RESULT([Compaq/DEC cc settings])
elif [ test "$MACC" = yes ]; then
  AC_SUBST(OPT_O0, [""])
Stephan Herhut's avatar
Stephan Herhut committed
363
364
365
  AC_SUBST(OPT_O1, [-O1])
  AC_SUBST(OPT_O2, [-O2])
  AC_SUBST(OPT_O3, [-O3])
Stephan Herhut's avatar
Stephan Herhut committed
366
  AC_SUBST(OPT_g, [-g])
367
  AC_SUBST(RCLDFLAGS, [""])
368
  AC_SUBST(RCCCFLAGS, ["-Wall -no-cpp-precomp -Wno-unused -fno-builtin"])
Sven-Bodo Scholz's avatar
   
Sven-Bodo Scholz committed
369
370
  AC_SUBST(MKCCFLAGS, ["-g -Wall -std=c99"])
  AC_SUBST(PDCCFLAGS, ["-g -std=c99"])
Stephan Herhut's avatar
Stephan Herhut committed
371
  AC_SUBST(DEPSFLAG, ["-M"])
372
  AC_SUBST(CPPFILE, ["gcc -E -C -x c"])
373
  AC_SUBST(CCMTLINK, [""])
Stephan Herhut's avatar
Stephan Herhut committed
374
375
376
377
378
379
380
381
382
  AC_MSG_RESULT([Apple cc settings])
else
  AC_SUBST(OPT_O0, [""])
  AC_SUBST(OPT_O1, [""])
  AC_SUBST(OPT_O2, [""])
  AC_SUBST(OPT_O3, [""])
  AC_SUBST(OPT_g, [""])
  AC_SUBST(RCLDFLAGS, [""])
  AC_SUBST(RCCCFLAGS, [""])
Stephan Herhut's avatar
Stephan Herhut committed
383
384
385
  AC_SUBST(MKCCFLAGS, [""])
  AC_SUBST(PDCCFLAGS, [""])
  AC_SUBST(DEPSFLAG, ["-M"])
386
  AC_SUBST(CPPFILE, ["cpp -C"])
387
  AC_SUBST(CCMTLINK, [""])
Stephan Herhut's avatar
Stephan Herhut committed
388
389
390
  AC_MSG_RESULT([none found])
fi   

391
392
393
394
395

dnl 
dnl append platform specific files to sac2crc
dnl 

Stephan Herhut's avatar
Stephan Herhut committed
396
397
398
399
AC_SUBST_FILE(RCSUN)
AC_SUBST_FILE(RCX86)
AC_SUBST_FILE(RCALPHA)
AC_SUBST_FILE(RCMAC)
400
401
402
403
RCSUN=./sac2crc.SUN
RCX86=./sac2crc.X86
RCALPHA=./sac2crc.ALPHA
RCMAC=./sac2crc.MAC
Stephan Herhut's avatar
Stephan Herhut committed
404

405
406

dnl
Stephan Herhut's avatar
Stephan Herhut committed
407
dnl generate specific flags for known os
408
409
dnl

410
AC_MSG_CHECKING([sac2crc system flags])
411

Stephan Herhut's avatar
Stephan Herhut committed
412
413
OSFLAGS=""
case "$target_os" in
414
  solaris*)     
Stephan Herhut's avatar
Stephan Herhut committed
415
    OSFLAGS=["-D__EXTENSIONS__ -DMUST_INIT_YY -DPIC"]
416
    LD_DYNAMIC=["-dy"]
417
    LD_PATH=["-R"]
418
    AC_MSG_RESULT([solaris settings])
419
420
    ;;
  *linux*)      
421
    OSFLAGS=["-fPIC -DPIC -D_POSIX_SOURCE -D_SVID_SOURCE -D_BSD_SOURCE -Dlint"]
422
    LD_DYNAMIC=["-dy -shared -allow-shlib-undefined"]
423
    LD_PATH=["-Wl,-rpath,"]
424
    AC_MSG_RESULT([linux settings])
425
426
427
    ;;
  *osf*)	
    OSFLAGS=["-D_OSF_SOURCE"]
428
    LD_DYNAMIC=[""]
429
    LD_PATH=[""]
430
    AC_MSG_RESULT([OSF settings])
431
432
    ;;
  *darwin*)      
433
    OSFLAGS=["-no-cpp-precomp -Wno-long-double"]
434
    LD_DYNAMIC=["-undefined suppress -flat_namespace -bundle"]
435
    LD_PATH=["-install_name"]
436
437
    AC_MSG_RESULT([OS X settings])
    ;;
Stephan Herhut's avatar
Stephan Herhut committed
438
439
440
  *bsd*)
    OSFLAGS=["-fpic"]
    LD_DYNAMIC=["ld -dy -shared -symbolic"]
441
    LD_PATH=["-Wl,-rpath,"]
Stephan Herhut's avatar
Stephan Herhut committed
442
443
    AC_MSG_RESULT([BSD settings])
    ;;
444
445
  *)
    AC_MSG_RESULT([unknown])
446
    ;;
Stephan Herhut's avatar
Stephan Herhut committed
447
448
esac
AC_SUBST(OSFLAGS)
449
AC_SUBST(LD_DYNAMIC)
450
AC_SUBST(LD_PATH)
Stephan Herhut's avatar
Stephan Herhut committed
451

452

453
454
455
456
457
458
459
460
461
462
463
464
dnl 
dnl static sac2c settings for config.h
dnl

AC_DEFINE( MAX_PATH_LEN, 1024, [set to maximum path length])
AC_DEFINE( MAX_FILE_NAME, 256, [set to maximum file name length])
AC_DEFINE( PF_MAXFUN, 100, [set to maximum number of sac functions for profiling])
AC_DEFINE( PF_MAXFUNAP, 100, 
           [set to maximum number of sac function applications for profiling])
AC_DEFINE( PF_MAXFUNNAMELEN, 100, 
           [set to maximum length of sac function names for profiling])

Clemens Grelck's avatar
Clemens Grelck committed
465
AC_DEFINE( SAC_PRELUDE_NAME, "sacprelude", [name of sac prelude])
Stephan Herhut's avatar
Stephan Herhut committed
466
467


468
469
470
471
dnl
dnl create configure-generated file
dnl

Stephan Herhut's avatar
Stephan Herhut committed
472
AC_OUTPUT()