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