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