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