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