1dnl Process this file with autoconf to produce a configure script
2
3dnl ------------------------------------------------
4dnl Initialization and Versioning
5dnl ------------------------------------------------
6
7AC_INIT
8AC_PREREQ(2.52)
9AC_CONFIG_SRCDIR(src/gs.c)
10
11CFLAGS="${CFLAGS:=}"
12CPPFLAGS="${CPPFLAGS:=}"
13CXXFLAGS="${CXXFLAGS:=}"
14LDFLAGS="${LDFLAGS:=}"
15
16dnl --------------------------------------------------
17dnl Local utilities
18dnl --------------------------------------------------
19
20dnl GS_SPLIT_LIBS( LIBS, LINKLINE )
21dnl Split a unix-style link line into a list of
22dnl bare library names. For example, the line
23dnl '-L/usr/X11R6/lib -lX11 -lXt' splits into
24dnl LIB='X11 Xt'
25dnl
26AC_DEFUN([GS_SPLIT_LIBS], [
27# the makefile wants a list of just the library names
28for gs_item in $2; do
29  gs_stripped_item=`echo "$gs_item" | sed -e 's/^-l//'`
30  if test "x$gs_stripped_item" != "x$gs_item"; then
31    $1="$[$1] $gs_stripped_item"
32  fi
33done
34])
35
36dnl GS_SPLIT_LIBPATHS( LIBPATHS, LINKLINE )
37dnl Split a unix-style link line into a list of
38dnl bare search path entries. For example,
39dnl '-L/usr/X11R6/lib -lX11 -L/opt/lib -lXt'
40dnl splits to LIBPATHS='/usr/X11R6/lib /opt/lib'
41dnl
42AC_DEFUN([GS_SPLIT_LIBPATHS], [
43for gs_item in $2; do
44  gs_stripped_item=`echo "$gs_item" | sed -e 's/-L//'`
45  if test "x$gs_stripped_item" != "x$gs_item"; then
46    $1="$[$1] $gs_stripped_item"
47  fi
48done
49])
50
51dnl --------------------------------------------------
52dnl Check for programs
53dnl --------------------------------------------------
54
55dnl AC_PROG_CC likes to add '-g -O2' to CFLAGS. however,
56dnl we ignore those flags and construct our own.
57AC_PROG_CC
58AC_PROG_CPP
59
60AC_PROG_RANLIB
61#AC_PROG_INSTALL
62
63dnl --------------------------------------------------
64dnl Set build flags based on environment
65dnl --------------------------------------------------
66
67#AC_CANONICAL_HOST
68
69dnl Add our standard set of gcc flags if possible
70if test $ac_cv_prog_gcc = yes; then
71    cflags_to_try="-Wall -Wstrict-prototypes \
72-Wmissing-declarations -Wmissing-prototypes \
73-Wcast-qual -Wwrite-strings \
74-fno-builtin -fno-common"
75else
76    cflags_to_try=
77fi
78optflags_to_try="-O2"
79
80AC_MSG_CHECKING([supported compiler flags])
81old_cflags=$CFLAGS
82echo
83for flag in $optflags_to_try; do
84    CFLAGS="$CFLAGS $flag"
85    AC_TRY_COMPILE(, [return 0;], [
86      echo "   $flag"
87      OPT_CFLAGS="$OPT_CFLAGS $flag"
88    ])
89    CFLAGS=$old_cflags
90done
91for flag in $cflags_to_try; do
92    CFLAGS="$CFLAGS $flag"
93    AC_TRY_COMPILE(, [return 0;], [
94	echo "   $flag"
95	GCFLAGS="$GCFLAGS $flag"
96    ])
97    CFLAGS=$old_cflags
98done
99AC_MSG_RESULT([ ...done.])
100
101
102dnl --------------------------------------------------
103dnl Check for headers
104dnl --------------------------------------------------
105
106AC_HEADER_DIRENT
107AC_HEADER_STDC
108AC_CHECK_HEADERS([errno.h fcntl.h limits.h malloc.h memory.h stdlib.h string.h strings.h sys/ioctl.h sys/param.h sys/time.h syslog.h unistd.h])
109
110# for gdev3b1.c (AT&T terminal interface)
111AC_CHECK_HEADER([sys/window.h])
112
113dnl --------------------------------------------------
114dnl Check for typedefs, structures, etc
115dnl --------------------------------------------------
116
117AC_C_CONST
118AC_C_INLINE
119AC_TYPE_MODE_T
120AC_TYPE_OFF_T
121AC_TYPE_SIZE_T
122AC_STRUCT_ST_BLOCKS
123AC_HEADER_TIME
124AC_STRUCT_TM
125
126dnl we aren't interested in all of DEFS, so manually insert
127dnl the flags we care about
128if test "$ac_cv_c_const" = yes; then
129	GCCFLAGS="$GCCFLAGS -Dconst="
130fi
131
132dnl --------------------------------------------------
133dnl Check for libraries
134dnl --------------------------------------------------
135
136AC_CHECK_LIB(m, cos)
137SYNC="nosync"
138PTHREAD_LIBS=""
139AC_CHECK_LIB(pthread, pthread_create, [
140  SYNC=posync;
141  PTHREAD_LIBS="-lpthread"
142])
143AC_SUBST(SYNC)
144AC_SUBST(PTHREAD_LIBS)
145
146AC_SUBST(SHARE_LIBJPEG)
147AC_SUBST(LIBJPEGDIR)
148
149dnl these are technically optional
150
151AC_MSG_CHECKING([for local zlib source])
152dnl zlib is needed for language level 3, and libpng
153# we must define ZLIBDIR regardless because libpng.mak does a -I$(ZLIBDIR)
154# this seems a harmless default
155ZLIBDIR=src
156if test -d zlib; then
157	AC_MSG_RESULT([zlib])
158	SHARE_ZLIB=0
159	ZLIBDIR=zlib
160elif test -d zlib-1.1.4; then
161	AC_MSG_RESULT([zlib-1.1.4])
162	SHARE_ZLIB=0
163	ZLIBDIR=zlib-1.1.4
164else
165	AC_MSG_RESULT([no])
166	AC_CHECK_LIB(z, deflate, [SHARE_ZLIB=1], [
167		AC_MSG_ERROR([I did not find a copy of libz on your system.
168  Please either install it, or unpack a copy of the source in a
169  local directory named 'zlib'.
170		])
171	])
172fi
173AC_SUBST(SHARE_ZLIB)
174AC_SUBST(ZLIBDIR)
175
176dnl png for the png output device; it also requires zlib
177AC_MSG_CHECKING([for local png library source])
178LIBPNGDIR=src
179PNGDEVS='$(DD)png16m.dev $(DD)pnggray.dev $(DD)pngmono.dev $(DD)png256.dev $(DD)png16.dev $(DD)pngalpha.dev'
180if test -d libpng; then
181	AC_MSG_RESULT([libpng])
182	SHARE_LIBPNG=0
183	LIBPNGDIR=libpng
184elif test -d libpng-1.2.5; then
185	AC_MSG_RESULT([libpng-1.2.5])
186	SHARE_LIBPNG=0
187	LIBPNGDIR=libpng-1.2.5
188else
189	AC_MSG_RESULT([no])
190	AC_CHECK_LIB(png, png_check_sig, [
191		SHARE_LIBPNG=1
192	], [
193		SHARE_LIBPNG=0
194		AC_MSG_NOTICE([disabling png output devices])
195		PNGDEVS=''
196	], [-lz])
197fi
198AC_SUBST(SHARE_LIBPNG)
199AC_SUBST(LIBPNGDIR)
200AC_SUBST(PNGDEVS)
201
202dnl look for IJS implementation
203AC_ARG_WITH(ijs, AC_HELP_STRING([--with-ijs],[include IJS driver support]))
204dnl set safe defaults
205    IJSDIR=src
206    IJSDEVS=''
207if test x$with_ijs != xno; then
208    AC_MSG_CHECKING([for local ijs library source])
209    if test -d ijs; then
210        AC_MSG_RESULT([yes])
211        IJSDIR=ijs
212        IJSDEVS='$(DD)ijs.dev'
213    else
214        AC_MSG_RESULT([no])
215    fi
216fi
217AC_SUBST(IJSDIR)
218AC_SUBST(IJSDEVS)
219
220dnl look for gimp-print (stp) library implementation
221AC_ARG_WITH([gimp-print], AC_HELP_STRING([--with-gimp-print],
222	[build the gimp-print (stp) driver]))
223dnl set safe defaults
224    STPLIB=gimpprint
225    STPDEVS=''
226if test x$with_gimp_print != xno; then
227    AC_CHECK_LIB($STPLIB, stp_init, [
228       AC_CHECK_HEADER([gimp-print/gimp-print.h], [
229           STPDEVS='$(DD)stp.dev'
230       ])
231    ])
232fi
233AC_SUBST(STPLIB)
234AC_SUBST(STPDEVS)
235
236SOC_CFLAGS=""
237SOC_LIBS=""
238SOC_LOADER="dxmainc.c"
239
240AC_SUBST(SOC_CFLAGS)
241AC_SUBST(SOC_LIBS)
242AC_SUBST(SOC_LOADER)
243
244dnl optional X11 for display devices
245AC_PATH_XTRA
246
247X_LDFLAGS=""
248X_CFLAGS=""
249X_DEVS=""
250X_LIBS=""
251
252if test x$with_x != xno; then
253	if test "$x_libraries" = "/usr/lib"; then
254		echo "Ignoring X library directory \"$x_libraries\" requested by configure."
255		x_libraries="NONE"
256	fi
257	if test ! "$x_libraries" = "NONE" -a ! "$x_libraries" = ""; then
258		X_LDFLAGS="-L$x_libraries"
259		if test "$uname" = "SunOS"; then
260			X_LDFLAGS="$X_LDFLAGS -R$x_libraries"
261		fi
262	fi
263
264	if test "$x_includes" = "/usr/include"; then
265		echo "Ignoring X include directory \"$x_includes\" requested by configure."
266		x_includes="NONE"
267	fi
268	if test ! "$x_includes" = "NONE" -a ! "$x_includes" = ""; then
269		X_CFLAGS="-I$x_includes"
270	fi
271
272	SAVELIBS="$LIBS"
273	SAVELDFLAGS="$LDFLAGS"
274	LDFLAGS="$LDFLAGS $X_LDFLAGS"
275
276	AC_CHECK_LIB(X11,XOpenDisplay)
277	AC_CHECK_LIB(Xext,XdbeQueryExtension)
278	AC_CHECK_LIB(Xt,XtAppCreateShell)
279
280	LDFLAGS="$SAVELDFLAGS"
281	LIBS="$SAVELIBS"
282
283	if test "$ac_cv_lib_Xt_XtAppCreateShell" = yes; then
284		X11DEVS="\$(DD)x11.dev \$(DD)x11alpha.dev \$(DD)x11cmyk.dev \$(DD)x11mono.dev \$(DD)x11_.dev \$(DD)x11alt_.dev \$(DD)x11cmyk2.dev \$(DD)x11cmyk4.dev \$(DD)x11cmyk8.dev \$(DD)x11rg16x.dev \$(DD)x11rg32x.dev \$(DD)x11gray2.dev \$(DD)x11gray4.dev"
285		X_DEVS=$X11DEVS
286		# the makefile wants a list of just the library names in X_LIBS
287		GS_SPLIT_LIBS([X_LIBS],
288			[-lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
289	fi
290fi
291
292AC_SUBST(X_LDFLAGS)
293AC_SUBST(X_CFLAGS)
294AC_SUBST(X_LIBS)
295AC_SUBST(X_DEVS)
296AC_SUBST(X11DEVS)
297AC_SUBST(XLIBS)
298
299dnl executible name
300AC_ARG_WITH(gs, AC_HELP_STRING([--with-gs=NAME],
301	[name of the ghostscript executible [[gs]]]),
302	[GS="$with_gs"],[GS='gs'])
303AC_SUBST(GS)
304
305dnl do we compile the postscript initialization files into Ghostscript?
306COMPILE_INITS="0"
307AC_ARG_ENABLE(compile-inits, AC_HELP_STRING([--enable-compile-inits],
308	[compile initialization files into Ghostscript]),[
309		if test x$enable_compile_inits = xyes; then
310			COMPILE_INITS="1"
311		fi])
312AC_SUBST(COMPILE_INITS)
313
314dnl Dynamic device support.
315DYNAMIC_CFLAGS=""
316DYNAMIC_DEVS=""
317DYNAMIC_FLAGS=""
318DYNAMIC_LDFLAGS=""
319DYNAMIC_LIBS=""
320INSTALL_SHARED=""
321
322AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
323    [Enable dynamically loaded drivers]),
324[
325	INSTALL_SHARED="install-shared"
326	DYNAMIC_CFLAGS="-fPIC"
327	DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
328	DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
329	DYNAMIC_LDFLAGS="-fPIC -shared"
330	DYNAMIC_LIBS=""
331	X_DEVS=""
332])
333
334AC_SUBST(DYNAMIC_CFLAGS)
335AC_SUBST(DYNAMIC_DEVS)
336AC_SUBST(DYNAMIC_FLAGS)
337AC_SUBST(DYNAMIC_LDFLAGS)
338AC_SUBST(DYNAMIC_LIBS)
339AC_SUBST(INSTALL_SHARED)
340
341dnl --------------------------------------------------
342dnl Check for library functions
343dnl --------------------------------------------------
344
345AC_CHECK_FUNCS([mkstemp], [HAVE_MKSTEMP=-DHAVE_MKSTEMP])
346AC_SUBST(HAVE_MKSTEMP)
347
348AC_FUNC_FORK
349AC_PROG_GCC_TRADITIONAL
350AC_FUNC_MALLOC
351AC_FUNC_MEMCMP
352AC_TYPE_SIGNAL
353AC_FUNC_STAT
354AC_FUNC_VPRINTF
355AC_CHECK_FUNCS([bzero dup2 floor gettimeofday memchr memmove memset mkdir mkfifo modf pow putenv rint setenv sqrt strchr strerror strrchr strspn strstr])
356
357dnl --------------------------------------------------
358dnl Do substitutions
359dnl --------------------------------------------------
360
361AC_SUBST(OPT_CFLAGS)
362AC_SUBST(GCFLAGS)
363AC_OUTPUT(Makefile)
364