a8c506ec0c1301d7669f4b64b33987b7ab14afd9
[fw/sdcc] / sim / ucsim / configure.in
1 #!/bin/sh
2
3 AC_PREREQ(2.60)
4 AC_INIT(.version)
5 AC_CONFIG_HEADER(ddconfig.h:ddconfig_in.h)
6
7 AC_PROG_AWK
8
9 AC_MSG_CHECKING(version of the package)
10 if test -f ${srcdir}/.version; then
11   VERSION=`cat ${srcdir}/.version`
12   AC_MSG_RESULT($VERSION)
13 else
14   VERSION="0.0.0"
15   AC_MSG_RESULT(unknown using 0.0.0)
16 fi
17 VERSIONHI=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $1}'`
18 VERSIONLO=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $2}'`
19 VERSIONP=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $3}'`
20 AC_SUBST(VERSION)
21 AC_SUBST(VERSIONHI)
22 AC_SUBST(VERSIONLO)
23 AC_SUBST(VERSIONP)
24 AC_DEFINE_UNQUOTED(VERSIONSTR, "${VERSION}")
25 AC_DEFINE_UNQUOTED(VERSIONHI, $VERSIONHI)
26 AC_DEFINE_UNQUOTED(VERSIONLO, $VERSIONLO)
27 AC_DEFINE_UNQUOTED(VERSIONP, $VERSIONP)
28
29 # Some options
30 #==============
31 # *nix default: "${datadir}/sdcc/doc"
32 AC_ARG_VAR(docdir, documentation installation directory)
33 if test "${docdir}" = ""; then
34     docdir="\${datadir}"/sdcc/doc
35 fi
36 AC_SUBST(docdir)
37
38 AC_ARG_ENABLE(ucsim,
39 [  --enable-ucsim          compile ucsim frontend],
40 if test $enable_ucsim != "no"; then
41     enable_ucsim="yes"
42 fi,
43 #default
44 enable_ucsim="no")
45 AC_ARG_ENABLE(dlso,
46 [  --enable-dlso           compile dynamically loadable shared libraries],
47 if test $enable_dlso != "no"; then
48     enable_dlso="yes"
49 fi,
50 enable_dlso="no")
51 AC_ARG_ENABLE(51,
52 [  --disable-51            do not compile simulator for MCS51],
53 if test $enable_51 != "no"; then
54     enable_51="yes"
55 fi,
56 enable_51="yes")
57 AC_ARG_ENABLE(avr,
58 [  --disable-avr           do not compile simulator for AVR],
59 if test $enable_avr != "no"; then
60     enable_avr="yes"
61 fi,
62 enable_avr="yes")
63 AC_ARG_ENABLE(z80,
64 [  --disable-z80           do not compile simulator for Z80],
65 if test $enable_z80 != "no"; then
66     enable_z80="yes"
67 fi,
68 enable_z80="yes")
69 AC_ARG_ENABLE(hc08,
70 [  --disable-hc08          do not compile simulator for hc08],
71 if test $enable_hc08 != "no"; then
72     enable_hc08="yes"
73 fi,
74 enable_hc08="yes")
75 AC_ARG_ENABLE(xa,
76 [  --enable-xa             compile simulator for XA],
77 if test $enable_xa != "no"; then
78     enable_xa="yes"
79 fi,
80 enable_xa="no")
81 AC_ARG_ENABLE(portmon,
82 [  --enable-serio          compile serio GUI tool (needs curses)],
83 if test $enable_serio != "no"; then
84     enable_serio="yes"
85 fi,
86 enable_serio="no")
87 AC_SUBST(enable_ucsim)
88 AC_SUBST(enable_dlso)
89 AC_SUBST(enable_51)
90 AC_SUBST(enable_avr)
91 AC_SUBST(enable_z80)
92 AC_SUBST(enable_hc08)
93 AC_SUBST(enable_xa)
94 AC_SUBST(enable_serio)
95
96 AC_ARG_ENABLE(statistic,
97 [  --enable-statistic      compile statistical features (slower simulation)],
98 if test $enable_statistic != "no"; then
99    enable_statistic="yes"
100 fi,
101 enable_statistic="no")
102 AC_DEFINE_UNQUOTED(STATISTIC, $enable_statistic)
103
104
105 # Required programs
106 #-------------------
107 AC_PROG_CXX
108 AC_PROG_CXXCPP
109 AC_PROG_INSTALL
110 AC_PROG_RANLIB
111 dnl AC_LANG_CPLUSPLUS
112
113 AC_CHECK_PROG(STRIP, strip, strip, :)
114
115 AC_LIBTOOL_DLOPEN
116 dnl AC_LIBTOOL_WIN32_DLL
117 AC_PROG_LIBTOOL
118 AC_SUBST(LIBTOOL_DEPS)
119
120 AC_PROG_LEX
121 if test ${LEX} = "flex"; then
122         AC_DEFINE(HAVE_FLEX)
123 fi
124 AC_PROG_YACC
125 AC_CHECK_PROG(BISON_PLUS_PLUS, bison++, bison++, :)
126
127
128 AC_LANG_CPLUSPLUS
129
130 # Checking for header files.
131 # ===========================================================================
132
133 if test -d /stuff/include; then
134   CPPFLAGS="$CPPFLAGS -I/stuff/include"
135 fi
136
137 AC_HEADER_STDC
138 AC_CHECK_HEADERS(getopt.h unistd.h termios.h)
139
140 AC_CHECK_HEADER(curses.h,
141   AC_DEFINE(HAVE_CURSES_H)
142   curses_h_ok=yes,
143   curses_h_ok=no
144 )
145
146 ucsim_cv_socket="unknown"
147 AC_CHECK_HEADER(sys/socket.h,
148   AC_DEFINE(HAVE_SYS_SOCKET_H)
149   AC_DEFINE(SOCKET_AVAIL)
150   AC_DEFINE_UNQUOTED(UCSOCKET_T, int)
151   ucsim_cv_socket="<sys/socket.h>"
152 )
153
154 WINSOCK_AVAIL=0
155 if test $ucsim_cv_socket = unknown; then
156   AC_CHECK_HEADER(winsock2.h,
157     AC_DEFINE(HAVE_WINSOCK2_H)
158     AC_DEFINE(SOCKET_AVAIL)
159     AC_DEFINE_UNQUOTED(UCSOCKET_T, SOCKET)
160     ucsim_cv_socket="<winsock2.h>"
161     WINSOCK_AVAIL=1
162   )
163 fi
164 AC_SUBST(WINSOCK_AVAIL)
165
166 if test $ucsim_cv_socket != unknown; then
167   AC_EGREP_HEADER(socklen_t,
168     $ucsim_cv_socket,
169     AC_DEFINE_UNQUOTED(SOCKLEN_T, socklen_t),
170     AC_DEFINE_UNQUOTED(SOCKLEN_T, uint))
171 fi
172 AC_DEFINE_UNQUOTED(HEADER_SOCKET, ${ucsim_cv_socket})
173
174 AC_CHECK_HEADER(dlfcn.h)
175 AC_HEADER_DIRENT
176
177 # This must be after CXXCPP
178
179 AC_CACHE_CHECK(which header file defines FD_ macros, ucsim_cv_fd,
180 [ucsim_cv_fd="unknown"
181 AC_EGREP_CPP(yes, [
182 #include <winsock2.h>
183 #ifdef FD_ZERO
184 yes
185 #endif], ucsim_cv_fd="<winsock2.h>")
186 AC_EGREP_CPP(yes, [
187 #include <sys/time.h>
188 #ifdef FD_ZERO
189 yes
190 #endif], ucsim_cv_fd="<sys/time.h>")
191 AC_EGREP_CPP(yes, [
192 #include <sys/types.h>
193 #ifdef FD_ZERO
194 yes
195 #endif], ucsim_cv_fd="<sys/types.h>")
196 AC_EGREP_CPP(yes, [
197 #include <sys/select.h>
198 #ifdef FD_ZERO
199 yes
200 #endif], ucsim_cv_fd="<sys/select.h>")])
201
202 ucsim_cv_header_ok=0
203 if echo $ucsim_cv_fd|grep time >/dev/null 2>&1; then
204 AC_DEFINE(FD_NEED_TIME_H, 1)
205 ucsim_cv_header_ok=1
206 else
207 AC_DEFINE(FD_NEED_TIME_H, 0)
208 fi
209 if echo $ucsim_cv_fd|grep types >/dev/null 2>&1; then
210 AC_DEFINE(FD_NEED_TYPES_H, 1)
211 ucsim_cv_header_ok=1
212 else
213 AC_DEFINE(FD_NEED_TYPES_H, 0)
214 fi
215 if echo $ucsim_cv_fd|grep select >/dev/null 2>&1; then
216 AC_DEFINE(FD_NEED_SELECT_H, 1)
217 ucsim_cv_header_ok=1
218 else
219 AC_DEFINE(FD_NEED_SELECT_H, 0)
220 fi
221 if echo $ucsim_cv_fd|grep winsock2 >/dev/null 2>&1; then
222 AC_DEFINE(FD_NEED_WINSOCK2_H, 1)
223 ucsim_cv_header_ok=1
224 else
225 AC_DEFINE(FD_NEED_WINSOCK2_H, 0)
226 fi
227
228 AC_DEFINE_UNQUOTED(FD_HEADER_OK, ${ucsim_cv_header_ok})
229 AC_DEFINE_UNQUOTED(HEADER_FD, ${ucsim_cv_fd})
230
231
232 # Checking for functions/libs
233 # ===========================================================================
234 if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then
235   LIBS="-lws2_32 $LIBS"
236 else
237   AC_CHECK_LIB(socket,socket)
238   AC_CHECK_LIB(nsl,xdr_short)
239 fi
240
241 AC_CHECK_LIB(dl,dlopen,
242 dl_ok="yes"
243 DL="-ldl",
244 dl_ok="no"
245 DL="")
246 AC_SUBST(dl_ok)
247 AC_SUBST(DL)
248
249 #AC_CHECK_LIB(panel,panel_above,
250 #panel_ok="yes"
251 #curses_ok="yes"
252 #CURSES_LIBS="-lpanel -lcurses"
253 #,
254 #panel_ok="no"
255 #AC_CHECK_LIB(curses,nl,
256 #curses_ok="yes"
257 #CURSES_LIBS="-lcurses"
258 #,
259 #curses_ok="no")
260 #,
261 #-lcurses)
262
263 if test $curses_h_ok != yes; then
264   panel_ok="no"
265   curses_ok="no"
266 else
267   AC_CHECK_LIB(panel,panel_above,
268     panel_ok="yes"
269     curses_ok="yes"
270     CURSES_LIBS="-lpanel",
271     panel_ok="no"
272     curses_ok="no"
273   )
274
275   if test $curses_ok != yes; then
276     AC_CHECK_LIB(curses,nl,
277       curses_ok="yes"
278       CURSES_LIBS="-lcurses",
279       curses_ok="no")
280   fi
281
282   if test $curses_ok != yes; then
283     AC_CHECK_LIB(ncurses,nl,
284       curses_ok="yes"
285       CURSES_LIBS="-lncurses",
286       curses_ok="no")
287   fi
288 fi
289
290 AC_SUBST(panel_ok)
291 AC_SUBST(curses_ok)
292 AC_SUBST(CURSES_LIBS)
293
294 AC_FUNC_VPRINTF
295 AC_CHECK_FUNCS(vsnprintf)
296 AC_CHECK_FUNCS(_vsnprintf)
297 AC_CHECK_FUNCS(vasprintf)
298 AC_CHECK_FUNCS(strlen strcpy strcat strstr strcmp strerror strtok strdup)
299 AC_CHECK_FUNCS(strchr memcpy)
300 dnl AC_CHECK_FUNCS(getline)
301 dnl AC_CHECK_FUNCS(getdelim)
302 AC_CHECK_FUNCS(fgets)
303 AC_CHECK_FUNCS(yylex)
304
305 AC_CACHE_CHECK(whether scanf knows %a, ucsim_cv_scanf_a,
306 [echo "a b" >conftest.data
307 AC_TRY_RUN([
308 #include <stdio.h>
309 void main(void)
310 {
311   FILE *f;
312   char *a;
313   int  i;
314   if ((f= fopen("conftest.data", "r")) == NULL)
315     exit(1);
316   i= fscanf(f, " %a[a-z] ", &a);
317   fclose(f);
318   if (i == 0)
319     exit(2);
320   if (i == 1)
321     exit(0);
322   exit(3);
323 }],
324 ucsim_cv_scanf_a="yes",
325 ucsim_cv_scanf_a="no",
326 ucsim_cv_scanf_a="unknown")
327 ])
328 if test "$ucsim_cv_scanf_a" = "yes"; then
329   AC_DEFINE(SCANF_A)
330 fi
331
332 AC_CACHE_CHECK(whether getcwd is GNUish, ucsim_cv_getcwd,
333 [AC_TRY_RUN([
334 #include <unistd.h>
335 void main(void)
336 {
337   if ((getcwd(NULL, 0)) == NULL)
338     exit(1);
339   exit(0);
340 }],
341 ucsim_cv_getcwd="yes",
342 ucsim_cv_getcwd="no",
343 ucsim_cv_getcwd="unknown")
344 ])
345 if test "$ucsim_cv_getcwd" = "yes"; then
346   AC_DEFINE(GNU_GETCWD)
347 fi
348
349 AC_DEFUN(ucsim_ACCEPT_LENGTH_T,
350  [AC_CACHE_CHECK([for type of length pointer parameter of accept],
351    ucsim_cv_accept_length_type,
352    [ac_save_CPPFLAGS="$CPPFLAGS"
353     ucsim_cv_accept_length_type=no
354     for ac_val in int size_t socklen_t; do
355       CPPFLAGS="$ac_save_CPPFLAGS -DACCEPT_SOCKLEN_T=$ac_val"
356       AC_TRY_COMPILE([#include <sys/types.h>
357 #include ${ucsim_cv_socket}],
358         [struct sockaddr a; $ac_val len; accept (0, &a, &len);],
359         [ucsim_cv_accept_length_type=$ac_val; break])
360     done
361     CPPFLAGS="$ac_save_CPPFLAGS"])
362   if test "$ucsim_cv_accept_length_type" != no; then
363     AC_DEFINE_UNQUOTED(ACCEPT_SOCKLEN_T, $ucsim_cv_accept_length_type,
364       [Define to be the type of length parameter of accept (without the \*').])
365   fi
366  ]
367 )
368 #'
369
370 ucsim_ACCEPT_LENGTH_T
371
372 # Macro definitions
373 ###################
374
375 # DD_COPT macro checks if the compiler specified as the 1st parameter
376 # supports option specified as the 2nd parameter
377 # For example: DD_COPT(CXX, fPIC)
378
379 AC_DEFUN(DD_COPT, [
380 AC_CACHE_CHECK(whether $$1 accepts -$2,ucsim_cv_$1$2,
381 cat >_test_.c <<EOF
382 int main(void) {return(0);}
383 EOF
384 $$1 -v -$2 -c _test_.c 1>&5 2>&5
385 if test "$?" = "0"; then
386   ucsim_cv_$1$2="yes"
387 else
388   ucsim_cv_$1$2="no"
389 fi
390 rm -f _test_.* a.out)
391 ])
392
393 # DD_COPT_NO_IGNORE macro checks if the compiler specified as the
394 # 1st parameter supports and doesn't ignore option specified as the
395 # 2nd parameter
396 # For example: DD_COPT_NO_IGNORE(CXX, fPIC)
397
398 AC_DEFUN(DD_COPT_NO_IGNORE, [
399 AC_CACHE_CHECK(whether $$1 accepts and doesn't ignore -$2,ucsim_cv_$1$2,
400 cat >_test_.c <<EOF
401 int main(void) {return(0);}
402 EOF
403 ucsim_cv_$1$2=$($$1 -v -$2 -c _test_.c 2>&1 1>&5)
404 if test "$?" = "0"; then
405   expr "$ucsim_cv_$1$2" : '.*'-$2'.*ignored' 1>&5 2>&5
406   if test "$?" = "0"; then
407     ucsim_cv_$1$2="no"
408   else
409     ucsim_cv_$1$2="yes"
410   fi
411 else
412   ucsim_cv_$1$2="no"
413 fi
414 rm -f _test_.* a.out)
415 ])
416
417
418 # Checking characteristics of compilers and other programs
419 # --------------------------------------------------------
420
421 # Cross compiling overrides
422 # FIXME
423 if test "$CC" = "i586-mingw32msvc-gcc"; then
424   ac_cv_c_bigendian=no
425   ac_cv_sizeof_char=1
426   ac_cv_sizeof_short=2
427   ac_cv_sizeof_int=4
428   ac_cv_sizeof_long=4
429   ac_cv_sizeof_long_long=4
430 fi
431
432 if test "$cross_compiling" = "no"
433 then
434     AC_C_BIGENDIAN
435 else
436 #echo "CROSS ENDIAN"
437     if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
438         ac_cv_c_bigendian=no
439     else
440         : # FIXME
441     fi
442 #echo "CROSS ENDIAN DONE"
443 fi
444
445 AC_CACHE_CHECK(whether preprocessor accepts -MM or -M,ucsim_cv_MM,
446 echo "#include <stdio.h>" >_test_.c
447 echo "" >>_test_.c
448 $CXXCPP -v -MM _test_.c 1>&5 2>&5
449 if test "$?" = "0"; then
450   ucsim_cv_MM="-MM"
451 else
452   ucsim_cv_MM="-M"
453 fi
454 rm -f _test_.*)
455 M_OR_MM=$ucsim_cv_MM
456 AC_SUBST(M_OR_MM)
457
458 # This is the first time when CFLAGS are set/modified!!
459
460 DD_COPT(CXX, ggdb)
461 DD_COPT(CXX, gstabs)
462 if test "$ucsim_cv_CXXgstabs" = "yes"; then
463    gopt="-gstabs+ -g3"
464 elif test "$ucsim_cv_CXXggdb" = "yes"; then
465      gopt="-ggdb -g3"
466 else
467      gopt="-g"
468 fi
469 if test "$CXXFLAGS"x = x ;then
470         CXXFLAGS="$gopt"
471 else
472         CXXFLAGS="$CXXFLAGS $gopt"
473 fi
474
475 DD_COPT(CXX, pipe)
476 if test "$ucsim_cv_CXXpipe" = "yes"; then
477   CXXFLAGS="$CXXFLAGS -pipe"
478 fi
479
480 PICOPT=""
481 SHAREDLIB="no"
482 DD_COPT_NO_IGNORE(CXX, fPIC)
483 if test "$ucsim_cv_CXXfPIC" = "yes"; then
484     PICOPT="-fPIC"
485 else
486     DD_COPT_NO_IGNORE(CXX, fpic)
487     if test "$ucsim_cv_CXXfpic" = "yes"; then
488         PICOPT="-fpic"
489     fi
490 fi
491 if test "$PICOPT"x != "x"; then
492     SHAREDLIB="yes"
493 fi
494 AC_SUBST(SHAREDLIB)
495 AC_SUBST(PICOPT)
496
497 dlso_ok="no"
498 if test $SHAREDLIB = "yes" -a $dl_ok = "yes" -a $enable_dlso = "yes"; then
499     dlso_ok="yes"
500 fi
501 AC_SUBST(dlso_ok)
502
503 # Checks for typedefs, structures, and compiler characteristics.
504 # ===========================================================================
505
506 AC_TYPE_SIGNAL
507 if test "$cross_compiling" = "no"; then
508 AC_CHECK_SIZEOF(char)
509 AC_CHECK_SIZEOF(short)
510 AC_CHECK_SIZEOF(int)
511 AC_CHECK_SIZEOF(long)
512 AC_CHECK_SIZEOF(long long)
513 else
514     if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
515         ac_cv_sizeof_char=1
516         ac_cv_sizeof_short=2
517         ac_cv_sizeof_int=4
518         ac_cv_sizeof_long=4
519         ac_cv_sizeof_long_long=4
520     else
521         : # FIXME
522     fi
523 #echo
524 fi
525
526 type_name()
527 {
528     if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
529         echo "char"
530         exit
531     fi
532     if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
533         echo "short"
534         exit
535     fi
536     if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
537         echo "int"
538         exit
539     fi
540     if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
541         echo "long"
542         exit
543     fi
544     if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then
545         echo "long long"
546         exit
547     fi
548     echo "long long"
549 }
550
551 AC_MSG_CHECKING(type name for byte)
552 TYPE_BYTE=`type_name 1`
553 AC_MSG_RESULT($TYPE_BYTE)
554 AC_MSG_CHECKING(type name for word)
555 TYPE_WORD=`type_name 2`
556 AC_MSG_RESULT($TYPE_WORD)
557 AC_MSG_CHECKING(type name for dword)
558 TYPE_DWORD=`type_name 4`
559 AC_MSG_RESULT($TYPE_DWORD)
560 AC_DEFINE_UNQUOTED(TYPE_BYTE, $TYPE_BYTE)
561 AC_DEFINE_UNQUOTED(TYPE_WORD, $TYPE_WORD)
562 AC_DEFINE_UNQUOTED(TYPE_DWORD, $TYPE_DWORD)
563
564 if echo $TYPE_DWORD|grep short >/dev/null; then
565     A="h"
566 elif echo $TYPE_DWORD|grep long >/dev/null; then
567     A="l"
568 else
569     A=""
570 fi
571
572 if echo $TYPE_WORD|grep short >/dev/null; then M="h"
573 elif echo $TYPE_WORD|grep long >/dev/null; then M="l"
574 else M=""
575 fi
576
577 AC_DEFINE_UNQUOTED(_A_, "${A}")
578 AC_DEFINE_UNQUOTED(_M_, "${M}")
579
580 # Generating output files
581 # ===========================================================================
582
583 AC_OUTPUT(Makefile
584 main.mk:main_in.mk
585 packages.mk:packages_in.mk
586 sim.src/Makefile
587 cmd.src/Makefile
588 s51.src/Makefile
589 avr.src/Makefile
590 z80.src/Makefile
591 hc08.src/Makefile
592 xa.src/Makefile
593 gui.src/Makefile
594 gui.src/serio.src/Makefile
595 doc/Makefile
596 )
597
598 #gui.src/portmon.src/Makefile
599
600
601 # End of configure/configure.in