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