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_MSG_CHECKING([for local jpeg library source])
147dnl At present, we give the local source priority over the shared
148dnl build, so that the D_MAX_BLOCKS_IN_MCU patch will be applied.
149dnl A more sophisticated approach would be to test the shared lib
150dnl to see whether it has already been patched.
151LIBJPEGDIR=src
152if test -d jpeg; then
153	AC_MSG_RESULT([jpeg])
154	SHARE_LIBJPEG=0
155	LIBJPEGDIR=jpeg
156elif test -d jpeg-6b; then
157	AC_MSG_RESULT([jpeg-6b])
158	SHARE_LIBJPEG=0
159	LIBJPEGDIR=jpeg-6b
160else
161	AC_MSG_RESULT([no])
162	AC_CHECK_LIB(jpeg, jpeg_set_defaults, [SHARE_LIBJPEG=1], [
163		AC_MSG_ERROR([I wasn't able to find a copy
164  of the jpeg library. This is required for compiling
165  ghostscript. Please download a copy of the source,  e.g.
166  from http://www.ijg.org/, unpack it at the top level of
167  the gs source tree, and rename the directory to 'jpeg'.
168		])
169	])
170fi
171AC_SUBST(SHARE_LIBJPEG)
172AC_SUBST(LIBJPEGDIR)
173
174dnl these are technically optional
175
176AC_MSG_CHECKING([for local zlib source])
177dnl zlib is needed for language level 3, and libpng
178# we must define ZLIBDIR regardless because libpng.mak does a -I$(ZLIBDIR)
179# this seems a harmless default
180ZLIBDIR=src
181if test -d zlib; then
182	AC_MSG_RESULT([zlib])
183	SHARE_ZLIB=0
184	ZLIBDIR=zlib
185elif test -d zlib-1.1.4; then
186	AC_MSG_RESULT([zlib-1.1.4])
187	SHARE_ZLIB=0
188	ZLIBDIR=zlib-1.1.4
189else
190	AC_MSG_RESULT([no])
191	AC_CHECK_LIB(z, deflate, [SHARE_ZLIB=1], [
192		AC_MSG_ERROR([I did not find a copy of libz on your system.
193  Please either install it, or unpack a copy of the source in a
194  local directory named 'zlib'.
195		])
196	])
197fi
198AC_SUBST(SHARE_ZLIB)
199AC_SUBST(ZLIBDIR)
200
201dnl png for the png output device; it also requires zlib
202AC_MSG_CHECKING([for local png library source])
203LIBPNGDIR=src
204PNGDEVS='$(DD)png16m.dev $(DD)pnggray.dev $(DD)pngmono.dev $(DD)png256.dev $(DD)png16.dev $(DD)pngalpha.dev'
205if test -d libpng; then
206	AC_MSG_RESULT([libpng])
207	SHARE_LIBPNG=0
208	LIBPNGDIR=libpng
209elif test -d libpng-1.2.5; then
210	AC_MSG_RESULT([libpng-1.2.5])
211	SHARE_LIBPNG=0
212	LIBPNGDIR=libpng-1.2.5
213else
214	AC_MSG_RESULT([no])
215	AC_CHECK_LIB(png, png_check_sig, [
216		SHARE_LIBPNG=1
217	], [
218		SHARE_LIBPNG=0
219		AC_MSG_NOTICE([disabling png output devices])
220		PNGDEVS=''
221	], [-lz])
222fi
223AC_SUBST(SHARE_LIBPNG)
224AC_SUBST(LIBPNGDIR)
225AC_SUBST(PNGDEVS)
226
227dnl look for IJS implementation
228AC_ARG_WITH(ijs, AC_HELP_STRING([--with-ijs],[include IJS driver support]))
229dnl set safe defaults
230    IJSDIR=src
231    IJSDEVS=''
232if test x$with_ijs != xno; then
233    AC_MSG_CHECKING([for local ijs library source])
234    if test -d ijs; then
235        AC_MSG_RESULT([yes])
236        IJSDIR=ijs
237        IJSDEVS='$(DD)ijs.dev'
238    else
239        AC_MSG_RESULT([no])
240    fi
241fi
242AC_SUBST(IJSDIR)
243AC_SUBST(IJSDEVS)
244
245dnl look for gimp-print (stp) library implementation
246AC_ARG_WITH([gimp-print], AC_HELP_STRING([--with-gimp-print],
247	[build the gimp-print (stp) driver]))
248dnl set safe defaults
249    STPLIB=gimpprint
250    STPDEVS=''
251if test x$with_gimp_print != xno; then
252    AC_CHECK_LIB($STPLIB, stp_init, [
253       AC_CHECK_HEADER([gimp-print/gimp-print.h], [
254           STPDEVS='$(DD)stp.dev'
255       ])
256    ])
257fi
258AC_SUBST(STPLIB)
259AC_SUBST(STPDEVS)
260
261SOC_CFLAGS=""
262SOC_LIBS=""
263SOC_LOADER="dxmainc.c"
264
265AC_SUBST(SOC_CFLAGS)
266AC_SUBST(SOC_LIBS)
267AC_SUBST(SOC_LOADER)
268
269dnl optional X11 for display devices
270AC_PATH_XTRA
271
272X_LDFLAGS=""
273X_CFLAGS=""
274X_DEVS=""
275X_LIBS=""
276
277if test x$with_x != xno; then
278	if test "$x_libraries" = "/usr/lib"; then
279		echo "Ignoring X library directory \"$x_libraries\" requested by configure."
280		x_libraries="NONE"
281	fi
282	if test ! "$x_libraries" = "NONE" -a ! "$x_libraries" = ""; then
283		X_LDFLAGS="-L$x_libraries"
284		if test "$uname" = "SunOS"; then
285			X_LDFLAGS="$X_LDFLAGS -R$x_libraries"
286		fi
287	fi
288
289	if test "$x_includes" = "/usr/include"; then
290		echo "Ignoring X include directory \"$x_includes\" requested by configure."
291		x_includes="NONE"
292	fi
293	if test ! "$x_includes" = "NONE" -a ! "$x_includes" = ""; then
294		X_CFLAGS="-I$x_includes"
295	fi
296
297	SAVELIBS="$LIBS"
298	SAVELDFLAGS="$LDFLAGS"
299	LDFLAGS="$LDFLAGS $X_LDFLAGS"
300
301	AC_CHECK_LIB(X11,XOpenDisplay)
302	AC_CHECK_LIB(Xext,XdbeQueryExtension)
303	AC_CHECK_LIB(Xt,XtAppCreateShell)
304
305	LDFLAGS="$SAVELDFLAGS"
306	LIBS="$SAVELIBS"
307
308	if test "$ac_cv_lib_Xt_XtAppCreateShell" = yes; then
309		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"
310		X_DEVS=$X11DEVS
311		# the makefile wants a list of just the library names in X_LIBS
312		GS_SPLIT_LIBS([X_LIBS],
313			[-lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
314	fi
315fi
316
317AC_SUBST(X_LDFLAGS)
318AC_SUBST(X_CFLAGS)
319AC_SUBST(X_LIBS)
320AC_SUBST(X_DEVS)
321AC_SUBST(X11DEVS)
322AC_SUBST(XLIBS)
323
324dnl executible name
325AC_ARG_WITH(gs, AC_HELP_STRING([--with-gs=NAME],
326	[name of the ghostscript executible [[gs]]]),
327	[GS="$with_gs"],[GS='gs'])
328AC_SUBST(GS)
329
330dnl do we compile the postscript initialization files into Ghostscript?
331COMPILE_INITS="0"
332AC_ARG_ENABLE(compile-inits, AC_HELP_STRING([--enable-compile-inits],
333	[compile initialization files into Ghostscript]),[
334		if test x$enable_compile_inits = xyes; then
335			COMPILE_INITS="1"
336		fi])
337AC_SUBST(COMPILE_INITS)
338
339dnl Dynamic device support.
340DYNAMIC_CFLAGS=""
341DYNAMIC_DEVS=""
342DYNAMIC_FLAGS=""
343DYNAMIC_LDFLAGS=""
344DYNAMIC_LIBS=""
345INSTALL_SHARED=""
346
347AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
348    [Enable dynamically loaded drivers]),
349[
350	DYNAMIC_CFLAGS="-fPIC"
351	DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
352	DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
353	DYNAMIC_LDFLAGS="-fPIC -shared"
354	DYNAMIC_LIBS=""
355	X_DEVS=""
356])
357
358AC_SUBST(DYNAMIC_CFLAGS)
359AC_SUBST(DYNAMIC_DEVS)
360AC_SUBST(DYNAMIC_FLAGS)
361AC_SUBST(DYNAMIC_LDFLAGS)
362AC_SUBST(DYNAMIC_LIBS)
363AC_SUBST(INSTALL_SHARED)
364
365dnl --------------------------------------------------
366dnl Check for library functions
367dnl --------------------------------------------------
368
369AC_CHECK_FUNCS([mkstemp], [HAVE_MKSTEMP=-DHAVE_MKSTEMP])
370AC_SUBST(HAVE_MKSTEMP)
371
372AC_FUNC_FORK
373AC_PROG_GCC_TRADITIONAL
374AC_FUNC_MALLOC
375AC_FUNC_MEMCMP
376AC_TYPE_SIGNAL
377AC_FUNC_STAT
378AC_FUNC_VPRINTF
379AC_CHECK_FUNCS([bzero dup2 floor gettimeofday memchr memmove memset mkdir mkfifo modf pow putenv rint setenv sqrt strchr strerror strrchr strspn strstr])
380
381dnl --------------------------------------------------
382dnl Do substitutions
383dnl --------------------------------------------------
384
385AC_SUBST(OPT_CFLAGS)
386AC_SUBST(GCFLAGS)
387AC_OUTPUT(Makefile)
388