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