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