* configure.in, configure: configure dies if bison and flex are not
[fw/sdcc] / configure.in
1 #!/bin/sh
2
3 AC_PREREQ(2.54)
4 AC_INIT
5 AC_CONFIG_SRCDIR([Makefile.in])
6 AC_CONFIG_HEADER(sdccconf.h:sdccconf_in.h)
7
8 AC_PROG_AWK
9
10 AC_MSG_CHECKING(version of the package)
11 if test -f ${srcdir}/.version; then
12   VERSION=`cat ${srcdir}/.version`
13 elif test -f ../.version; then
14   VERSION=`cat ../.version`
15 else
16   VERSION="0.0.0"
17 fi
18 VERSIONHI=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $1}'`
19 VERSIONLO=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $2}'`
20 VERSIONP=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $3}'`
21
22 AC_MSG_RESULT(${VERSION})
23 AC_SUBST(VERSION)
24 AC_SUBST(VERSIONHI)
25 AC_SUBST(VERSIONLO)
26 AC_SUBST(VERSIONP)
27 AC_DEFINE_UNQUOTED(SDCC_VERSION_LO, ${VERSIONLO})
28 AC_DEFINE_UNQUOTED(SDCC_VERSION_HI, ${VERSIONHI})
29 AC_DEFINE_UNQUOTED(SDCC_VERSION_P, ${VERSIONP})
30 AC_DEFINE_UNQUOTED(SDCC_VERSION_STR, "${VERSION}")
31 AC_ARG_PROGRAM
32 sdcc_cv_version=$VERSION
33 sdcc_cv_versionhi=$VERSIONHI
34 sdcc_cv_versionlo=$VERSIONLO
35 sdcc_cv_versionp=$VERSIONP
36
37
38 # Required programs
39 # ===========================================================================
40 AC_PROG_CC
41 AC_PROG_CPP
42 AC_PROG_INSTALL
43 AC_PROG_RANLIB
44 AC_CHECK_PROG(AUTOCONF, autoconf, autoconf, :)
45 AC_CHECK_PROG(STRIP, strip, strip, :)
46 AC_CHECK_PROG(AS, as, as, :)
47 AC_CHECK_PROG(CP, cp, cp, :)
48
49 dnl Don't use AC_PROG_LEX; we insist on flex.
50 dnl LEXLIB is not useful in gcc.
51 AC_CHECK_PROGS([FLEX], flex, :)
52
53 dnl Don't use AC_PROG_YACC; we insist on bison.
54 AC_CHECK_PROGS([BISON], bison, :)
55
56 AC_DEFUN(SDCC_REQUIRE_PROG,
57 [if test "$1" = ":"; then
58   AC_MSG_ERROR([Cannot find required program $2.])
59  fi
60 ])
61
62 SDCC_REQUIRE_PROG($BISON, bison)
63 SDCC_REQUIRE_PROG($FLEX, flex)
64
65 AC_LANG_C
66
67
68 # Checking for functions
69 # ===========================================================================
70 AC_CHECK_FUNCS(strerror)
71 AC_CHECK_FUNCS(vsnprintf snprintf vsprintf mkstemp)
72
73
74 # Macro definitions
75 # ===========================================================================
76
77 # adl_DD_COPT macro checks if the compiler specified as the 1st parameter
78 # supports option specified as the 2nd parameter
79 # For example: DD_CPORT(CXX, fPIC)
80
81 AC_DEFUN(adl_DD_COPT, [
82 AC_CACHE_CHECK(whether $$1 accepts -$2,sdcc_cv_$1$2,
83 cat >_test_.c <<EOF
84 #include <stdio.h>
85 void main(void) {}
86 EOF
87 $$1 -v -$2 -c _test_.c 1>&5 2>&5
88 if test "$?" = "0"; then
89   sdcc_cv_$1$2="yes"
90 else
91   sdcc_cv_$1$2="no"
92 fi
93 rm -f _test_.* a.out)
94 ])
95
96 # This macro expands DIR and assigns it to RET.
97 # If DIR is NONE, then it's replaced by DEFAULT.
98 #
99 # Based on AC_DEFINE_DIR
100 #
101 # Examples:
102 #
103 #  adl_EXPAND(prefix, "/usr/local", expanded_prefix)
104
105 AC_DEFUN([adl_EXPAND], [
106   test "x$prefix" = xNONE && prefix="$ac_default_prefix"
107   test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
108   ac_expand=[$]$1
109   test "x$ac_expand" = xNONE && ac_expand="[$]$2"
110   ac_expand=`eval echo [$]ac_expand`
111   $3=`eval echo [$]ac_expand`
112 ])
113
114 # adl_NORMALIZE_PATH
115 #
116 #  - empty paths are changed to '.'
117 #  - trailing slashes are removed
118 #  - repeated slashes are squeezed except a leading doubled slash '//'
119 #    (which might indicate a networked disk on some OS).
120 #
121 #
122 # REFERENCE_STRING is used to turn '/' into '\' and vice-versa: if
123 # REFERENCE_STRING contains some backslashes, all slashes and backslashes
124 # are turned into backslashes, otherwise they are all turned into slashes.
125 #
126 # This makes processing of DOS filenames quite easier, because you can turn a
127 # filename to the Unix notation, make your processing, and turn it back to
128 # original notation.
129
130 dnl Available from the GNU Autoconf Macro Archive at:
131 dnl http://www.gnu.org/software/ac-archive/htmldoc/normpath.html
132 dnl
133 AC_DEFUN([adl_NORMALIZE_PATH],
134 [case ":[$]$1:" in
135 dnl change empty paths to '.'
136   ::) $1='.' ;;
137 dnl strip trailing slashes
138   :*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;;
139   :*:) ;;
140 esac
141 dnl squeze repeated slashes
142 case ifelse($2,,"[$]$1",$2) in
143 dnl if the path contains any backslashes, turn slashes into backslashes
144
145 dnl Bernhard Held 2003-04-06
146 dnl This was the original line. It does not:
147 dnl - convert the first slash
148 dnl - replace a slash with a double-backslash
149 dnl *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\,g'` ;;
150     *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\\\\\,g
151                                   s,^[[\\/]],\\\\\\\\,'` ;;
152
153 dnl if the path contains slashes, also turn backslashes into slashes
154  *) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;;
155 esac])
156
157
158 # adl_COMPUTE_RELATIVE_PATH
159 #
160 # PATH_LIST is a space-separated list of colon-separated triplets of the form
161 # 'FROM:TO:RESULT'. This function iterates over these triplets and set $RESULT
162 # to the relative path from $FROM to $TO. Note that $FROM and $TO needs to be
163 # absolute filenames for this macro to success.
164
165 AC_DEFUN([adl_COMPUTE_RELATIVE_PATHS],
166 [for _lcl_i in $1; do
167   _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'`
168   _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'`
169   _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'`
170   adl_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from])
171   adl_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to])
172   _lcl_notation="$_lcl_from$_lcl_to"
173   adl_NORMALIZE_PATH([_lcl_from],['/'])
174   adl_NORMALIZE_PATH([_lcl_to],['/'])
175   adl_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp])
176   adl_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"])
177   eval $_lcl_result_var='[$]_lcl_result_tmp'
178 done])
179
180 ## Note:
181 ## *****
182 ## The following helper macros are too fragile to be used out
183 ## of adl_COMPUTE_RELATIVE_PATHS (mainly because they assume that
184 ## paths are normalized), that's why I'm keeping them in the same file.
185 ## Still, some of them maybe worth to reuse.
186
187 dnl adl_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
188 dnl ===========================================
189 dnl Compute the relative path to go from $FROM to $TO and set the value
190 dnl of $RESULT to that value.  This function work on raw filenames
191 dnl (for instead it will considerate /usr//local and /usr/local as
192 dnl two distinct paths), you should really use adl_COMPUTE_REALTIVE_PATHS
193 dnl instead to have the paths sanitized automatically.
194 dnl
195 dnl For instance:
196 dnl    first_dir=/somewhere/on/my/disk/bin
197 dnl    second_dir=/somewhere/on/another/disk/share
198 dnl    adl_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
199 dnl will set $first_to_second to '../../../another/disk/share'.
200 AC_DEFUN([adl_COMPUTE_RELATIVE_PATH],
201 [adl_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
202 adl_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
203 adl_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
204 $3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
205
206 dnl adl_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
207 dnl ============================================
208 dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
209 dnl
210 dnl For instance:
211 dnl    first_path=/somewhere/on/my/disk/bin
212 dnl    second_path=/somewhere/on/another/disk/share
213 dnl    adl_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
214 dnl will set $common_path to '/somewhere/on'.
215 AC_DEFUN([adl_COMPUTE_COMMON_PATH],
216 [$3=''
217 _lcl_second_prefix_match=''
218 while test "[$]_lcl_second_prefix_match" != 0; do
219   _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"`
220   _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"`
221   if test "[$]_lcl_second_prefix_match" != 0; then
222     if test "[$]_lcl_first_prefix" != "[$]$3"; then
223       $3="[$]_lcl_first_prefix"
224     else
225       _lcl_second_prefix_match=0
226     fi
227   fi
228 done])
229
230 dnl adl_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
231 dnl ==============================================
232 dnl Substrack $SUBPATH from $PATH, and set the resulting suffix
233 dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
234 dnl to $RESULT.
235 dnl
236 dnl For instace:
237 dnl    first_path=/somewhere/on/my/disk/bin
238 dnl    second_path=/somewhere/on
239 dnl    adl_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
240 dnl will set $common_path to '/my/disk/bin'.
241 AC_DEFUN([adl_COMPUTE_SUFFIX_PATH],
242 [$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
243
244 dnl adl_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
245 dnl ============================================
246 dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
247 dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
248 dnl should be needed to move from $PATH to $SUBPATH) and set the value
249 dnl of $RESULT to that value.  If $SUBPATH is not a subpath of PATH,
250 dnl set $RESULT to the empty string.
251 dnl
252 dnl For instance:
253 dnl    first_path=/somewhere/on/my/disk/bin
254 dnl    second_path=/somewhere/on
255 dnl    adl_COMPUTE_BACK_PATH(first_path, second_path, back_path)
256 dnl will set $back_path to '../../../'.
257 AC_DEFUN([adl_COMPUTE_BACK_PATH],
258 [adl_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
259 $3=''
260 _lcl_tmp='xxx'
261 while test "[$]_lcl_tmp" != ''; do
262   _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"`
263   if test "[$]_lcl_first_suffix" != ''; then
264      _lcl_first_suffix="[$]_lcl_tmp"
265      $3="../[$]$3"
266   fi
267 done])
268
269
270 dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
271 dnl =================================
272 dnl Interpolate the VALUE in loop until it does not change,
273 dnl and set the result to $RESULT.
274 dnl WARNING: It is easy to get an infinite loop with some unsane input.
275 AC_DEFUN([adl_RECURSIVE_EVAL],
276 [_lcl_receval="$1"
277 $2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix"
278      test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
279      _lcl_receval_old=''
280      while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
281        _lcl_receval_old="[$]_lcl_receval"
282        eval _lcl_receval="\"[$]_lcl_receval\""
283      done
284      echo "[$]_lcl_receval")`])
285
286 dnl adl_NORMALIZE_DEFINE_UNQUOTED(var, DEFINE, REFERENCE_STRING)
287 AC_DEFUN([adl_NORMALIZE_DEFINE_UNQUOTED], [
288   ac_ndu=[$]$1
289   adl_NORMALIZE_PATH([ac_ndu], [$]$3)
290   AC_DEFINE_UNQUOTED($2, "${ac_ndu}")
291 ])
292
293 dnl adl_NORMALIZE_PATH_MSG(input_string, var, dir_separator)
294 dnl ========================================================
295 dnl call adl_NORMALIZE_PATH and format it for the result message
296 AC_DEFUN([adl_NORMALIZE_PATH_MSG], [
297 dnl replace /./ by /
298 $2=`echo "$1" | sed 's,/\./,/,g'`
299 adl_NORMALIZE_PATH([$2], [$3])
300 dnl replace \\ by \
301 $2=`echo "[$]$2" | sed 's,\\\\\\\\,\\\\,g'`
302 ])
303
304
305 # Checking characteristics of compilers and other programs
306 # ===========================================================================
307 AC_CACHE_CHECK(whether preprocessor accepts -MM or -M,sdcc_cv_MM,
308 echo "#include <stdio.h>" >_test_.c
309 echo "" >>_test_.c
310 $CPP -v -MM _test_.c 1>&5 2>&5
311 if test "$?" = "0"; then
312   sdcc_cv_MM="-MM"
313 else
314   sdcc_cv_MM="-M"
315 fi
316 rm -f _test_.*)
317 M_OR_MM=$sdcc_cv_MM
318 AC_SUBST(M_OR_MM)
319
320 # This is the first time when CFLAGS are set/modified!!
321 adl_DD_COPT(CC, ggdb)
322 if test "$sdcc_cv_CCggdb" = "yes"; then
323   CFLAGS="-ggdb ${CFLAGS}"
324 fi
325
326 adl_DD_COPT(CC, pipe)
327 if test "$sdcc_cv_CCpipe" = "yes"; then
328   CFLAGS="-pipe $CFLAGS"
329 fi
330
331
332 # Checks for typedefs, structures, and compiler characteristics.
333 # ===========================================================================
334 AC_TYPE_SIGNAL
335
336 AC_CHECK_SIZEOF(char)
337 AC_CHECK_SIZEOF(short)
338 AC_CHECK_SIZEOF(int)
339 AC_CHECK_SIZEOF(long)
340 AC_C_CHAR_UNSIGNED
341
342 type_name()
343 {
344   if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
345       echo "char"
346     exit
347   fi
348   if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
349     echo "short"
350     exit
351   fi
352   if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
353     echo "int"
354     exit
355   fi
356   if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
357     echo "long"
358     exit
359   fi
360   echo "long"
361 }
362
363 AC_MSG_CHECKING(type name for byte)
364 TYPE_CHAR=`type_name 1`
365 if test "$ac_cv_c_char_unsigned" = "yes"; then
366   TYPE_BYTE="signed $TYPE_CHAR"
367 else
368   TYPE_BYTE=$TYPE_CHAR
369 fi
370 AC_MSG_RESULT($TYPE_BYTE)
371 AC_MSG_CHECKING(type name for word)
372 TYPE_WORD=`type_name 2`
373 AC_MSG_RESULT($TYPE_WORD)
374 AC_MSG_CHECKING(type name for dword)
375 TYPE_DWORD=`type_name 4`
376 AC_MSG_RESULT($TYPE_DWORD)
377
378 AC_DEFINE_UNQUOTED(TYPE_BYTE,  $TYPE_BYTE)
379 AC_DEFINE_UNQUOTED(TYPE_WORD,  $TYPE_WORD)
380 AC_DEFINE_UNQUOTED(TYPE_DWORD, $TYPE_DWORD)
381
382 AC_DEFINE_UNQUOTED(TYPE_UBYTE,  unsigned $TYPE_CHAR)
383 AC_DEFINE_UNQUOTED(TYPE_UWORD,  unsigned $TYPE_WORD)
384 AC_DEFINE_UNQUOTED(TYPE_UDWORD, unsigned $TYPE_DWORD)
385
386 AC_C_BIGENDIAN
387
388 # Set standard installation paths
389 # ===========================================================================
390
391 # In the Makefiles we need paths with '/' as directory separator, even if
392 # crosscompiling for Win32.
393 # And we want to preserve the macros (e.g. ${prefix}) in the Makefiles.
394 # The variables in the Makefiles are replaced by AC_SUBST()
395 #
396 # In sdccconf.h the '/' in paths can be replaced by "\\" (normalized), if
397 #
398 # The macros are expanded for the header.
399 # The variables in the header are replaced by AC_*DEFINE*()
400 # sdccconf_h_dir_separator contains a backslash.
401 AC_ARG_VAR(sdccconf_h_dir_separator, needed in sdccconf.h: either "/" (default) or "\\")
402 if test "x${sdccconf_h_dir_separator}" = "x"; then
403     sdccconf_h_dir_separator="/"
404 fi
405
406 # Makefiles
407 ###########
408
409 # include_dir_suffix:
410 # *nix default: "sdcc/include"
411
412 AC_ARG_VAR(include_dir_suffix, appended to datadir to define SDCC's include directory)
413 if test "${include_dir_suffix}" = ""; then
414     include_dir_suffix="sdcc/include"
415 fi
416 AC_SUBST(include_dir_suffix)
417
418 # lib_dir_suffix:
419 # *nix default: "sdcc/lib"
420 AC_ARG_VAR(lib_dir_suffix, appended to datadir to define SDCC's library root directory)
421 if test "${lib_dir_suffix}" = ""; then
422     lib_dir_suffix="sdcc/lib"
423 fi
424 AC_SUBST(lib_dir_suffix)
425
426 # docdir:
427 # *nix default: "${datadir}/sdcc/doc"
428 AC_ARG_VAR(docdir, documentation installation directory)
429 if test "${docdir}" = ""; then
430     docdir="\${datadir}"/sdcc/doc
431 fi
432 AC_SUBST(docdir)
433
434 AC_SUBST(EXEEXT)
435
436 # sdccconf.h
437 ############
438
439 AC_DEFINE_UNQUOTED(DIR_SEPARATOR_STRING, "${sdccconf_h_dir_separator}")
440 AC_DEFINE_UNQUOTED(DIR_SEPARATOR_CHAR  , '${sdccconf_h_dir_separator}')
441
442 # prefix:
443 # default: "NONE", ${ac_default_prefix}: "/usr/local"
444 adl_EXPAND(prefix, ac_default_prefix, expanded_prefix)
445 adl_NORMALIZE_DEFINE_UNQUOTED(expanded_prefix, PREFIX, sdccconf_h_dir_separator)
446
447 # exec_prefix:
448 # default: "${prefix}"
449 adl_EXPAND(exec_prefix, expanded_prefix, expanded_exec_prefix)
450 adl_NORMALIZE_DEFINE_UNQUOTED(expanded_exec_prefix, EXEC_PREFIX, sdccconf_h_dir_separator)
451
452 # bindir:
453 # default: "${exec_prefix}/bin"
454 adl_EXPAND(bindir, "NONE", expanded_bindir)
455 adl_NORMALIZE_DEFINE_UNQUOTED(expanded_bindir, BINDIR, sdccconf_h_dir_separator)
456
457 # datadir:
458 # default: "${prefix}/share"
459 adl_EXPAND(datadir, "NONE", expanded_datadir)
460 adl_NORMALIZE_DEFINE_UNQUOTED(expanded_datadir, DATADIR, sdccconf_h_dir_separator)
461
462 # include/lib suffix
463 norm_inc_dir_suffix=${include_dir_suffix}
464 adl_NORMALIZE_PATH([norm_inc_dir_suffix], [$sdccconf_h_dir_separator])
465 AC_DEFINE_UNQUOTED(INCLUDE_DIR_SUFFIX,
466                    DIR_SEPARATOR_STRING "${norm_inc_dir_suffix}")
467 norm_lib_dir_suffix=${lib_dir_suffix}
468 adl_NORMALIZE_PATH([norm_lib_dir_suffix], [$sdccconf_h_dir_separator])
469 AC_DEFINE_UNQUOTED(LIB_DIR_SUFFIX,
470                    DIR_SEPARATOR_STRING "${norm_lib_dir_suffix}")
471
472 # relative paths
473 adl_COMPUTE_RELATIVE_PATHS([expanded_bindir:expanded_datadir:bin2data_dir])
474 adl_NORMALIZE_PATH(bin2data_dir, [$sdccconf_h_dir_separator])
475 AC_DEFINE_UNQUOTED(BIN2DATA_DIR,
476                    DIR_SEPARATOR_STRING "${bin2data_dir}")
477
478 adl_COMPUTE_RELATIVE_PATHS([expanded_prefix:expanded_bindir:prefix2bin_dir])
479 adl_NORMALIZE_PATH(prefix2bin_dir, [$sdccconf_h_dir_separator])
480 AC_DEFINE_UNQUOTED(PREFIX2BIN_DIR,
481                    DIR_SEPARATOR_STRING "${prefix2bin_dir}")
482
483 adl_COMPUTE_RELATIVE_PATHS([expanded_prefix:expanded_datadir:prefix2data_dir])
484 adl_NORMALIZE_PATH(prefix2data_dir, [$sdccconf_h_dir_separator])
485 if test "${prefix2data_dir}" = "."; then
486     # small optimization for Mingw32; otherwise Borut will complain ;-)
487     AC_DEFINE_UNQUOTED(PREFIX2DATA_DIR, "")
488 else
489     AC_DEFINE_UNQUOTED(PREFIX2DATA_DIR,
490                        DIR_SEPARATOR_STRING "${prefix2data_dir}")
491 fi
492
493 # standard libs
494 AC_DEFINE_UNQUOTED(STD_LIB,       "libsdcc")
495 AC_DEFINE_UNQUOTED(STD_INT_LIB,   "libint")
496 AC_DEFINE_UNQUOTED(STD_LONG_LIB,  "liblong")
497 AC_DEFINE_UNQUOTED(STD_FP_LIB,    "libfloat")
498 AC_DEFINE_UNQUOTED(STD_DS390_LIB, "libds390")
499 AC_DEFINE_UNQUOTED(STD_DS400_LIB, "libds400")
500 AC_DEFINE_UNQUOTED(STD_XA51_LIB,  "libxa51")
501
502 # SDCC runtime environment variables
503 sdcc_dir_name="SDCC_HOME"
504 AC_DEFINE_UNQUOTED(SDCC_DIR_NAME, "${sdcc_dir_name}")
505
506 sdcc_include_name="SDCC_INCLUDE"
507 AC_DEFINE_UNQUOTED(SDCC_INCLUDE_NAME, "${sdcc_include_name}")
508
509 sdcc_lib_name="SDCC_LIB"
510 AC_DEFINE_UNQUOTED(SDCC_LIB_NAME, "${sdcc_lib_name}")
511
512 # Port selection helper
513 # ===========================================================================
514 # macro AC_DO_ENABLER()
515 #   $1 used to access enable_$1, e.g. enable-doc
516 #   $2 OPT_DISABLE_$2, normally uppercase of $1, e.g. DOC
517 #   $3 help string
518 AC_DEFUN([AC_DO_ENABLER], [
519   AC_ARG_ENABLE($1, AC_HELP_STRING([--enable-$1], $3))
520
521   if test "[$]enable_$1" = "yes"; then
522     OPT_ENABLE_$2=1
523   else
524     OPT_ENABLE_$2=0
525   fi
526
527   AC_DEFINE_UNQUOTED(OPT_ENABLE_$2, [$]OPT_ENABLE_$2)
528   AC_SUBST(OPT_ENABLE_$2)
529 ])
530
531 # macro AC_DO_DISABLER()
532 #   $1 used to access disable_$1, e.g. ucsim
533 #   $2 OPT_DISABLE_$2, normally uppercase of $1, e.g. UCSIM
534 #   $3 help string
535 AC_DEFUN([AC_DO_DISABLER], [
536   AC_ARG_ENABLE($1, AC_HELP_STRING([--disable-$1], $3))
537
538   dnl the '-' in 'device-lib' needs special handling,
539   dnl because the variable is 'enable_device_lib'
540   arg1=`echo $1 | sed s/-/_/`
541
542   if test "`eval echo \\$enable_$arg1`" = "no"; then
543     OPT_DISABLE_$2=1
544   else
545     OPT_DISABLE_$2=0
546   fi
547
548   AC_DEFINE_UNQUOTED(OPT_DISABLE_$2, [$]OPT_DISABLE_$2)
549   AC_SUBST(OPT_DISABLE_$2)
550 ])
551
552 # macro AC_DO_PORT($1, $2, $3, $4)
553 #   $1 used to access enable_$2_port, e.g. gbz80
554 #   $2 port name in ports.all and ports.build, e.g. z80
555 #   $3 OPT_DISABLE_$3, normally uppercase of $2, e.g. GBZ80
556 #   $4 help string
557 AC_DEFUN([AC_DO_PORT], [
558   AC_ARG_ENABLE($1-port,
559                 AC_HELP_STRING([--disable-$1-port], $4))
560
561   if test "[$]enable_$1_port" = "no"; then
562     OPT_DISABLE_$3=1
563   else
564     enable_$1_port="yes"
565     OPT_DISABLE_$3=0
566   fi
567
568   AC_DEFINE_UNQUOTED(OPT_DISABLE_$3, [$]OPT_DISABLE_$3)
569   AC_SUBST(OPT_DISABLE_$3)
570
571   echo $2 >>ports.all
572   if test [$]OPT_DISABLE_$3 = 0; then
573     echo $2 >>ports.build
574   fi
575 ])
576
577 # Now handle the port selection
578 # ===========================================================================
579 rm -f ports.all ports.build
580 AC_DO_PORT(mcs51, mcs51, MCS51, [Excludes the Intel mcs51 port])
581 AC_DO_PORT(gbz80, z80,   GBZ80, [Excludes the Gameboy gbz80 port])
582 AC_DO_PORT(z80,   z80,   Z80,   [Excludes the z80 port])
583 AC_DO_PORT(avr,   avr,   AVR,   [Excludes the AVR port])
584 AC_DO_PORT(ds390, ds390, DS390, [Excludes the DS390 port])
585 AC_DEFINE_UNQUOTED(OPT_DISABLE_TININative, $OPT_DISABLE_DS390)
586 AC_DO_PORT(ds400, ds400, DS400, [Excludes the DS400 port])
587 AC_DO_PORT(pic,   pic,   PIC,   [Excludes the PIC port])
588 AC_DO_PORT(pic16, pic16, PIC16, [Excludes the PIC16 port])
589 AC_DO_PORT(xa51,  xa51,  XA51,  [Excludes the XA51 port])
590 AC_DO_PORT(hc08,  hc08,  HC08,  [Excludes the HC08 port])
591
592 AC_DO_DISABLER(ucsim,      UCSIM,      [Disables configuring and building of ucsim])
593 AC_DO_DISABLER(device-lib, DEVICE_LIB, [Disables building device libraries])
594 AC_DO_DISABLER(packihx,    PACKIHX,    [Disables building packihx])
595 AC_DO_DISABLER(sdcpp,      SDCPP,      [Disables building sdcpp])
596 AC_DO_DISABLER(sdcdb,      SDCDB,      [Disables building sdcdb])
597
598 AC_DO_ENABLER(doc,   DOC,   [Enables building the documentation])
599 if test $OPT_ENABLE_DOC = 1; then
600   AC_CHECK_PROG(LYX,        lyx,        lyx, :)
601   AC_CHECK_PROG(LATEX2HTML, latex2html, latex2html, :)
602   AC_CHECK_PROG(PDFLATEX,   pdflatex,   pdflatex, :)
603   AC_CHECK_PROG(PDFOPT,     pdfopt,     pdfopt, :)
604   AC_CHECK_PROG(MAKEINDEX,  makeindex,  makeindex, :)
605
606   SDCC_REQUIRE_PROG($LYX,        lyx)
607   SDCC_REQUIRE_PROG($LATEX2HTML, latex2html)
608   SDCC_REQUIRE_PROG($PDFLATEX,   pdflatex)
609   SDCC_REQUIRE_PROG($PDFOPT,     pdfopt)
610   SDCC_REQUIRE_PROG($MAKEINDEX,  makeindex)
611 fi
612
613 AC_DO_ENABLER(libgc, LIBGC, [Use the Bohem memory allocator. Lower runtime footprint.])
614 if test $OPT_ENABLE_LIBGC = 1; then
615   AC_CHECK_LIB(gc, GC_malloc)
616   if test $ac_cv_lib_gc_GC_malloc = no; then
617     AC_MSG_ERROR([Cannot find library libgc with Bohem memory allocator.])
618   fi
619 fi
620
621 #remove duplicates
622 uniq ports.all ports
623 mv ports ports.all
624 uniq ports.build ports
625 mv ports ports.build
626
627 # Generating output files
628 # ===========================================================================
629 test $OPT_DISABLE_SDCPP   = 0 && AC_CONFIG_SUBDIRS(support/cpp2)
630 test $OPT_DISABLE_PACKIHX = 0 && AC_CONFIG_SUBDIRS(support/packihx)
631 test $OPT_DISABLE_UCSIM   = 0 && AC_CONFIG_SUBDIRS(sim/ucsim)
632 test $OPT_DISABLE_SDCDB   = 0 && AC_CONFIG_SUBDIRS(debugger/mcs51)
633 AC_CONFIG_FILES([doc/Makefile])
634
635 test $OPT_DISABLE_AVR = 0 && AC_CONFIG_FILES([src/avr/Makefile])
636
637 if test $OPT_DISABLE_DS390 = 0; then
638   AC_CONFIG_FILES([src/ds390/Makefile])
639   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/ds390/Makefile])
640 fi
641
642 if test $OPT_DISABLE_DS400 = 0; then
643   AC_CONFIG_FILES([src/ds400/Makefile])
644   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/ds400/Makefile])
645 fi
646
647 if test $OPT_DISABLE_HC08 = 0; then
648   AC_CONFIG_FILES([src/hc08/Makefile
649                    as/hc08/Makefile
650                    as/link/hc08/Makefile])
651   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/hc08/Makefile])
652 fi
653
654 if test $OPT_DISABLE_MCS51 = 0; then
655   AC_CONFIG_FILES([src/mcs51/Makefile
656                    as/mcs51/Makefile
657                    as/link/mcs51/Makefile])
658   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/mcs51/Makefile
659                                                        device/lib/small/Makefile
660                                                        device/lib/medium/Makefile
661                                                        device/lib/large/Makefile])
662 fi
663
664 if test $OPT_DISABLE_PIC = 0; then
665   AC_CONFIG_FILES(src/pic/Makefile)
666   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_SUBDIRS(device/lib/pic)
667 fi
668 if test $OPT_DISABLE_PIC16 = 0; then
669   AC_CONFIG_FILES(src/pic16/Makefile)
670   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_SUBDIRS(device/lib/pic16)
671 fi
672
673 test $OPT_DISABLE_XA51 = 0 && AC_CONFIG_FILES([src/xa51/Makefile])
674
675 if test $OPT_DISABLE_Z80 = 0; then
676   AC_CONFIG_FILES([src/z80/Makefile
677                    as/Makefile
678                    as/z80/Makefile
679                    as/link/Makefile
680                    as/link/z80/Makefile])
681   test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/z80/Makefile
682                                                        device/lib/gbz80/Makefile])
683 fi
684
685 test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/Makefile])
686
687 AC_CONFIG_FILES([main.mk:main_in.mk
688 src/Makefile
689 device/include/Makefile
690 support/librarian/Makefile
691 support/makebin/Makefile
692 support/regression/Makefile
693 support/valdiag/Makefile
694 Makefile
695 Makefile.common:Makefile.common.in
696 ])
697 AC_OUTPUT
698
699 # I found no better place
700 mkdir -p bin
701
702 # Prepare result message
703 # ======================
704
705 # In the C-header we need \\ as dir-separator, but in the message only \
706 dirch=${sdccconf_h_dir_separator}
707 test ${dirch} = '\\' && dirch='\'
708
709 # calc friendly strings
710 adl_NORMALIZE_PATH_MSG(/${prefix2bin_dir},                         [binPath],  [$dirch])
711 adl_NORMALIZE_PATH_MSG(/${prefix2data_dir}/${norm_inc_dir_suffix}, [incPath1], [$dirch])
712 adl_NORMALIZE_PATH_MSG(/${bin2data_dir}/${norm_inc_dir_suffix},    [incPath2], [$dirch])
713 adl_NORMALIZE_PATH_MSG(${expanded_datadir}/${norm_inc_dir_suffix}, [incPath3], [$dirch])
714 adl_NORMALIZE_PATH_MSG(/${prefix2data_dir}/${norm_lib_dir_suffix}, [libPath1], [$dirch])
715 adl_NORMALIZE_PATH_MSG(/${bin2data_dir}/${norm_lib_dir_suffix},    [libPath2], [$dirch])
716 adl_NORMALIZE_PATH_MSG(${expanded_datadir}/${norm_lib_dir_suffix}, [libPath3], [$dirch])
717
718 AC_MSG_RESULT([
719 sdcc ${VERSION} is now configured for
720
721   Build:                ${build_alias}
722   Host:                 ${host_alias}
723   Source directory:     ${srcdir}
724   C compiler:           ${CC}
725   CFLAGS:               ${CFLAGS}
726
727   ENABLED Ports:
728     avr                 ${enable_avr_port}
729     ds390               ${enable_ds390_port}
730     ds400               ${enable_ds400_port}
731     gbz80               ${enable_gbz80_port}
732     hc08                ${enable_hc08_port}
733     pic                 ${enable_pic_port}
734     pic16               ${enable_pic16_port}
735     xa51                ${enable_xa51_port}
736     z80                 ${enable_z80_port}
737
738   Disable packihx:      ${OPT_DISABLE_PACKIHX}
739   Disable ucsim:        ${OPT_DISABLE_UCSIM}
740   Disable device lib:   ${OPT_DISABLE_DEVICE_LIB}
741   Disable sdcpp:        ${OPT_DISABLE_SDCPP}
742   Disable sdcdb:        ${OPT_DISABLE_SDCDB}
743   Enable documentation: ${OPT_ENABLE_DOC}
744   Enable libgc:         ${OPT_ENABLE_LIBGC}
745
746   Install paths:
747     binary files:       ${exec_prefix}
748     include files:      ${datadir}/${include_dir_suffix}
749     library files:      ${datadir}/${lib_dir_suffix}
750     documentation:      ${docdir}
751
752     prefix:             ${prefix}
753     datadir:            ${datadir}
754
755   Search paths (incomplete, see manual for all search paths):
756     binary files:       \$SDCC_HOME${binPath}
757     include files:      ${incPath1}
758                         path(argv[[0]])${incPath2}
759                         ${incPath3}
760     library files:      \$SDCC_HOME${libPath1}${dirch}<model>
761                         path(argv[[0]])${libPath2}${dirch}<model>
762                         ${libPath3}${dirch}<model>
763 ])
764 # End of configure/configure.in