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