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