fixes of curses lib detection
[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
29 # Required programs
30 #-------------------
31 AC_PROG_CXX
32 AC_PROG_CXXCPP
33 AC_PROG_INSTALL
34 AC_PROG_RANLIB
35 AC_LANG_CPLUSPLUS
36
37
38 # Checking for header files.
39 # ===========================================================================
40
41 if test -d /stuff/include; then
42   CPPFLAGS="$CPPFLAGS -I/stuff/include"
43 fi
44
45 AC_HEADER_STDC
46 AC_CHECK_HEADERS(getopt.h)
47 AC_CHECK_HEADERS(unistd.h)
48 AC_CHECK_HEADER(sys/socket.h,
49   AC_DEFINE(SOCKET_AVAIL)
50   AC_DEFINE(HAVE_SYS_SOCKET_H))
51 AC_HEADER_DIRENT
52
53 # This must be after CXXCPP
54
55 AC_CACHE_CHECK(which header file defines FD_ macros, s51_cv_fd,
56 [s51_cv_fd="unknown"
57 AC_EGREP_CPP(yes, [
58 #include <sys/time.h>
59 #ifdef FD_ZERO
60 yes
61 #endif], s51_cv_fd="<sys/time.h>")
62 AC_EGREP_CPP(yes, [
63 #include <sys/types.h>
64 #ifdef FD_ZERO
65 yes
66 #endif], s51_cv_fd="<sys/types.h>")
67 AC_EGREP_CPP(yes, [
68 #include <sys/select.h>
69 #ifdef FD_ZERO
70 yes
71 #endif], s51_cv_fd="<sys/types.h>")])
72
73 AC_DEFINE(FD_HEADER_OK, 0)
74 if echo $s51_cv_fd|grep time >/dev/null 2>&1; then
75 AC_DEFINE(FD_NEED_TIME_H, 1)
76 AC_DEFINE(FD_HEADER_OK, 1)
77 else
78 AC_DEFINE(FD_NEED_TIME_H, 0)
79 fi
80 if echo $s51_cv_fd|grep types >/dev/null 2>&1; then
81 AC_DEFINE(FD_NEED_TYPES_H, 1)
82 AC_DEFINE(FD_HEADER_OK, 1)
83 else
84 AC_DEFINE(FD_NEED_TYPES_H, 0)
85 fi
86 if echo $s51_cv_fd|grep select >/dev/null 2>&1; then
87 AC_DEFINE(FD_NEED_SELECT_H, 1)
88 AC_DEFINE(FD_HEADER_OK, 1)
89 else
90 AC_DEFINE(FD_NEED_SELECT_H, 0)
91 fi
92
93 AC_DEFINE_UNQUOTED(HEADER_FD, ${s51_cv_fd})
94
95
96 # Checking for functions/libs
97 # ===========================================================================
98 AC_CHECK_LIB(socket,socket)
99 AC_CHECK_LIB(nsl,xdr_short)
100 AC_CHECK_LIB(panel,panel_above,
101 panel_ok="yes"
102 curses_ok="yes"
103 CURSES_LIBS="-lpanel -lcurses"
104 ,
105 panel_ok="no"
106 AC_CHECK_LIB(curses,nl,
107 curses_ok="yes"
108 CURSES_LIBS="-lcurses"
109 ,
110 ncurses_ok="no")
111 ,
112 -lcurses)
113 AC_SUBST(panel_ok)
114 AC_SUBST(curses_ok)
115 AC_SUBST(CURSES_LIBS)
116
117 AC_FUNC_VPRINTF
118 AC_CHECK_FUNCS(vsnprintf vasprintf)
119 AC_CHECK_FUNCS(strlen strcpy strcat strstr strcmp strerror strtok strdup)
120 AC_CHECK_FUNCS(strchr memcpy)
121 dnl AC_CHECK_FUNCS(getline)
122 dnl AC_CHECK_FUNCS(getdelim)
123 AC_CHECK_FUNCS(fgets)
124 AC_CHECK_FUNCS(yylex)
125
126 AC_CACHE_CHECK(whether scanf knows %a, s51_cv_scanf_a,
127 [echo "a b" >conftest.data
128 AC_TRY_RUN([
129 #include <stdio.h>
130 void main(void)
131 {
132   FILE *f;
133   char *a;
134   int  i;
135   if ((f= fopen("conftest.data", "r")) == NULL)
136     exit(1);
137   i= fscanf(f, " %a[a-z] ", &a);
138   fclose(f);
139   if (i == 0)
140     exit(2);
141   if (i == 1)
142     exit(0);
143   exit(3);
144 }],
145 s51_cv_scanf_a="yes",
146 s51_cv_scanf_a="no",
147 s51_cv_scanf_a="unknown")
148 ])
149 if test "$s51_cv_scanf_a" = "yes"; then
150   AC_DEFINE(SCANF_A)
151 fi
152
153 AC_CACHE_CHECK(whether getcwd is GNUish, s51_cv_getcwd,
154 [AC_TRY_RUN([
155 #include <unistd.h>
156 void main(void)
157 {
158   if ((getcwd(NULL, 0)) == NULL)
159     exit(1);
160   exit(0);
161 }],
162 s51_cv_getcwd="yes",
163 s51_cv_getcwd="no",
164 s51_cv_getcwd="unknown")
165 ])
166 if test "$s51_cv_getcwd" = "yes"; then
167   AC_DEFINE(GNU_GETCWD)
168 fi
169
170
171 # Macro definitions
172 ###################
173
174 # DD_COPT macro checks if the compiler specified as the 1st parameter
175 # supports option specified as the 2nd parameter
176 # For example: DD_CPORT(CXX, fPIC)
177
178 AC_DEFUN(DD_COPT, [
179 AC_CACHE_CHECK(whether $$1 accepts -$2,s51_cv_$1$2,
180 cat >_test_.c <<EOF
181 #include <stdio.h>
182 void main(void) {}
183 EOF
184 $$1 -v -$2 -c _test_.c 1>&5 2>&5
185 if test "$?" = "0"; then
186   s51_cv_$1$2="yes"
187 else
188   s51_cv_$1$2="no"
189 fi
190 rm -f _test_.* a.out)
191 ])
192
193
194 # Checking characteristics of compilers and other programs
195 # --------------------------------------------------------
196 AC_C_BIGENDIAN
197 AC_CACHE_CHECK(whether preprocessor accepts -MM or -M,s51_cv_MM,
198 echo "#include <stdio.h>" >_test_.c
199 echo "" >>_test_.c
200 $CXXCPP -v -MM _test_.c 1>&5 2>&5
201 if test "$?" = "0"; then
202   s51_cv_MM="-MM"
203 else
204   s51_cv_MM="-M"
205 fi
206 rm -f _test_.*)
207 M_OR_MM=$s51_cv_MM
208 AC_SUBST(M_OR_MM)
209
210 # This is the first time when CFLAGS are set/modified!!
211
212 DD_COPT(CXX, ggdb)
213 if test "$s51_cv_CXXggdb" = "yes"; then
214     if test "$CXXFLAGS"x = x ;then
215         CXXFLAGS="-ggdb -O"
216     else
217         CXXFLAGS="$CXXFLAGS -ggdb"
218     fi
219 fi
220
221 DD_COPT(CXX, pipe)
222 if test "$s51_cv_CXXpipe" = "yes"; then
223   CXXFLAGS="$CXXFLAGS -pipe"
224 fi
225
226
227 # Checks for typedefs, structures, and compiler characteristics.
228 # ===========================================================================
229
230 AC_TYPE_SIGNAL
231 AC_CHECK_SIZEOF(char)
232 AC_CHECK_SIZEOF(short)
233 AC_CHECK_SIZEOF(int)
234 AC_CHECK_SIZEOF(long)
235 AC_CHECK_SIZEOF(long long)
236
237 type_name()
238 {
239     if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
240         echo "char"
241         exit
242     fi
243     if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
244         echo "short"
245         exit
246     fi
247     if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
248         echo "int"
249         exit
250     fi
251     if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
252         echo "long"
253         exit
254     fi
255     if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then
256         echo "long long"
257         exit
258     fi
259     echo "long long"
260 }
261
262 AC_MSG_CHECKING(type name for byte)
263 TYPE_BYTE=`type_name 1`
264 AC_MSG_RESULT($TYPE_BYTE)
265 AC_MSG_CHECKING(type name for word)
266 TYPE_WORD=`type_name 2`
267 AC_MSG_RESULT($TYPE_WORD)
268 AC_MSG_CHECKING(type name for dword)
269 TYPE_DWORD=`type_name 4`
270 AC_MSG_RESULT($TYPE_DWORD)
271 AC_DEFINE_UNQUOTED(TYPE_BYTE, $TYPE_BYTE)
272 AC_DEFINE_UNQUOTED(TYPE_WORD, $TYPE_WORD)
273 AC_DEFINE_UNQUOTED(TYPE_DWORD, $TYPE_DWORD)
274
275 # Generating output files
276 # ===========================================================================
277
278 AC_OUTPUT(main.mk:main_in.mk
279 sim.src/Makefile
280 cmd.src/Makefile
281 s51.src/Makefile
282 avr.src/Makefile
283 z80.src/Makefile
284 gui.src/Makefile
285 gui.src/serio.src/Makefile
286 gui.src/portmon.src/Makefile
287 doc/Makefile
288 )
289
290
291 # End of configure/configure.in