xref: /plan9/sys/src/cmd/gs/src/configure.ac (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1dnl Copyright (C) 2002-2004 artofcode LLC. All rights reserved.
2
3dnl This software is provided AS-IS with no warranty, either express or
4dnl implied.
5
6dnl This software is distributed under license and may not be copied,
7dnl modified or distributed except as expressly authorized under the terms
8dnl of the license contained in the file LICENSE in this distribution.
9
10dnl For more information about licensing, please refer to
11dnl http://www.ghostscript.com/licensing/. For information on
12dnl commercial licensing, go to http://www.artifex.com/licensing/ or
13dnl contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14dnl San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
16dnl $Id: configure.ac,v 1.51 2005/07/15 05:23:42 giles Exp $
17
18dnl Process this file with autoconf to produce a configure script
19
20dnl ------------------------------------------------
21dnl Initialization and Versioning
22dnl ------------------------------------------------
23
24AC_INIT
25AC_PREREQ(2.52)
26AC_CONFIG_SRCDIR(src/gs.c)
27
28dnl --------------------------------------------------
29dnl Check for programs
30dnl --------------------------------------------------
31
32dnl AC_PROG_CC likes to add '-g -O2' to CFLAGS. however,
33dnl we ignore those flags and construct our own.
34save_cflags=$CFLAGS
35AC_PROG_CC
36AC_PROG_CPP
37CFLAGS=$save_cflags
38
39AC_PROG_RANLIB
40#AC_PROG_INSTALL
41
42dnl --------------------------------------------------
43dnl Set build flags based on environment
44dnl --------------------------------------------------
45
46#AC_CANONICAL_HOST
47
48if test $ac_cv_prog_gcc = yes; then
49    cflags_to_try="-Wall -Wstrict-prototypes \
50-Wmissing-declarations -Wmissing-prototypes \
51-Wcast-qual -Wwrite-strings \
52-fno-builtin -fno-common"
53    optflags_to_try="-O2"
54else
55    cflags_to_try=
56    optflags_to_try="-O"
57fi
58
59AC_MSG_CHECKING([supported compiler flags])
60old_cflags=$CFLAGS
61echo
62for flag in $optflags_to_try; do
63    CFLAGS="$CFLAGS $flag"
64    AC_TRY_COMPILE(, [return 0;], [
65	echo "   $flag"
66	OPT_CFLAGS="$OPT_CFLAGS $flag"
67    ])
68    CFLAGS=$old_cflags
69done
70for flag in $cflags_to_try; do
71	CFLAGS="$CFLAGS $flag"
72	AC_TRY_COMPILE(, [return 0;], [
73		echo "   $flag"
74		GCFLAGS="$GCFLAGS $flag"
75	])
76	CFLAGS=$old_cflags
77done
78AC_MSG_RESULT([ ...done.])
79
80dnl --------------------------------------------------
81dnl Check for headers
82dnl --------------------------------------------------
83
84AC_HEADER_DIRENT
85AC_HEADER_STDC
86AC_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])
87
88# for gdev3b1.c (AT&T terminal interface)
89AC_CHECK_HEADER([sys/window.h])
90
91dnl --------------------------------------------------
92dnl Check for typedefs, structures, etc
93dnl --------------------------------------------------
94
95AC_C_CONST
96AC_C_INLINE
97AC_TYPE_MODE_T
98AC_TYPE_OFF_T
99AC_TYPE_SIZE_T
100AC_STRUCT_ST_BLOCKS
101AC_HEADER_TIME
102AC_STRUCT_TM
103
104dnl see if we're on a system that puts the *int*_t types
105dnl from stdint.h in sys/types.h
106if test "x$ac_cv_header_stdint_h" != xyes; then
107    AC_CHECK_TYPES([int8_t, int16_t, int32_t, uint8_t, uint16_t, uint32_t],,,[#include <sys/types.h>])
108    if test "$ac_cv_type_uint8_t" = yes; then
109        AC_DEFINE([SYS_TYPES_HAS_STDINT_TYPES])
110	GCFLAGS="$GCFLAGS -DSYS_TYPES_HAS_STDINT_TYPES"
111    fi
112fi
113
114dnl we aren't interested in all of DEFS, so manually insert
115dnl the flags we care about
116if test "$ac_cv_c_const" != yes; then
117	GCFLAGS="$GCFLAGS -Dconst="
118fi
119if test "x$ac_cv_header_stdint_h" = xyes; then
120	GCFLAGS="$GCFLAGS -DHAVE_STDINT_H"
121fi
122
123dnl try to find a 64 bit type for devicen color index
124uint64_type="none"
125 AC_CHECK_SIZEOF(unsigned long int)
126 if test $ac_cv_sizeof_unsigned_long_int = 8; then
127	uint64_type="unsigned long int"
128 else
129  AC_CHECK_SIZEOF(unsigned long long)
130  if test $ac_cv_sizeof_unsigned_long_long = 8; then
131	uint64_type="unsigned long long"
132  else
133   AC_CHECK_SIZEOF(unsigned __int64)
134   if test $ac_cv_sizeof_unsigned___int64 = 8; then
135	uint64_type="unsigned __int64"
136   else
137    AC_CHECK_SIZEOF(u_int64_t)
138    if test $ac_cv_sizeof_u_int64_t = 8; then
139	uint64_type="u_int64_t"
140    fi
141   fi
142  fi
143 fi
144dnl we don't need to do anything if a 64-bit type wasn't found
145dnl the code falls back to a (probably 32-bit) default
146if test "$uint64_type" != "none"; then
147	GCFLAGS="$GCFLAGS -DGX_COLOR_INDEX_TYPE=\"$uint64_type\""
148fi
149
150
151dnl --------------------------------------------------
152dnl Check for libraries
153dnl --------------------------------------------------
154
155AC_CHECK_LIB(m, cos)
156dnl AC_CHECK_LIB(pthread, pthread_create)
157
158AC_MSG_CHECKING([for local jpeg library source])
159dnl At present, we give the local source priority over the shared
160dnl build, so that the D_MAX_BLOCKS_IN_MCU patch will be applied.
161dnl A more sophisticated approach would be to test the shared lib
162dnl to see whether it has already been patched.
163LIBJPEGDIR=src
164if test -f jpeg/jpeglib.h; then
165	AC_MSG_RESULT([jpeg])
166	SHARE_LIBJPEG=0
167	LIBJPEGDIR=jpeg
168elif test -f jpeg-6b/jpeglib.h; then
169	AC_MSG_RESULT([jpeg-6b])
170	SHARE_LIBJPEG=0
171	LIBJPEGDIR=jpeg-6b
172else
173	AC_MSG_RESULT([no])
174	AC_CHECK_LIB(jpeg, jpeg_set_defaults, [
175	  AC_CHECK_HEADERS([jpeglib.h], [SHARE_LIBJPEG=1])
176	])
177fi
178if test -z "$SHARE_LIBJPEG"; then
179  AC_MSG_ERROR([I wasn't able to find a copy
180  of the jpeg library. This is required for compiling
181  ghostscript. Please download a copy of the source,
182  e.g. from http://www.ijg.org/, unpack it at the
183  top level of the gs source tree, and rename
184  the directory to 'jpeg'.
185  ])
186fi
187AC_SUBST(SHARE_LIBJPEG)
188AC_SUBST(LIBJPEGDIR)
189dnl check for the internal jpeg memory header
190AC_MSG_CHECKING([for jmemsys.h])
191if test -r $LIBJPEGDIR/jmemsys.h; then
192  AC_MSG_RESULT([yes])
193else
194  AC_MSG_RESULT([no])
195  AC_DEFINE([DONT_HAVE_JMEMSYS_H], 1,
196    [define if the libjpeg memory system prototypes aren't available])
197fi
198
199dnl these are technically optional
200
201AC_MSG_CHECKING([for local zlib source])
202dnl zlib is needed for language level 3, and libpng
203# we must define ZLIBDIR regardless because libpng.mak does a -I$(ZLIBDIR)
204# this seems a harmless default
205ZLIBDIR=src
206if test -d zlib; then
207	AC_MSG_RESULT([yes])
208	SHARE_ZLIB=0
209	ZLIBDIR=zlib
210else
211	AC_MSG_RESULT([no])
212	AC_CHECK_LIB(z, deflate, [
213	  AC_CHECK_HEADERS(zlib.h, [SHARE_ZLIB=1])
214	])
215fi
216if test -z "$SHARE_ZLIB"; then
217  AC_MSG_ERROR([I did not find a copy of zlib on your system.
218  Please either install it, or unpack a copy of the source in a
219  local directory named 'zlib'. See http://www.gzip.org/zlib/
220  for more information.
221  ])
222fi
223AC_SUBST(SHARE_ZLIB)
224AC_SUBST(ZLIBDIR)
225
226dnl png for the png output device; it also requires zlib
227LIBPNGDIR=src
228PNGDEVS=''
229PNGDEVS_ALL='$(DD)png48.dev $(DD)png16m.dev $(DD)pnggray.dev $(DD)pngmono.dev $(DD)png256.dev $(DD)png16.dev $(DD)pngalpha.dev'
230AC_MSG_CHECKING([for local png library source])
231if test -f libpng/pngread.c; then
232	AC_MSG_RESULT([yes])
233	SHARE_LIBPNG=0
234	LIBPNGDIR=libpng
235	PNGDEVS="$PNGDEVS_ALL"
236else
237	AC_MSG_RESULT([no])
238	AC_CHECK_LIB(png, png_check_sig, [
239	  AC_CHECK_HEADERS(png.h, [
240		SHARE_LIBPNG=1
241		PNGDEVS="$PNGDEVS_ALL"
242	  ], [SHARE_LIBPNG=0])
243	], [SHARE_LIBPNG=0], [-lz])
244fi
245if test -z "$PNGDEVS"; then
246  AC_MSG_NOTICE([disabling png output devices])
247fi
248AC_SUBST(SHARE_LIBPNG)
249AC_SUBST(LIBPNGDIR)
250AC_SUBST(PNGDEVS)
251
252dnl look for IJS implementation
253AC_ARG_WITH(ijs, AC_HELP_STRING([--with-ijs],[include IJS driver support]))
254dnl set safe defaults
255    IJSDIR=src
256    IJSDEVS=''
257if test x$with_ijs != xno; then
258    AC_MSG_CHECKING([for local ijs library source])
259    if test -d ijs; then
260        AC_MSG_RESULT([yes])
261        IJSDIR=ijs
262        IJSDEVS='$(DD)ijs.dev'
263    else
264        AC_MSG_RESULT([no])
265    fi
266fi
267AC_SUBST(IJSDIR)
268AC_SUBST(IJSDEVS)
269
270dnl look for jbig2dec
271AC_ARG_WITH(jbig2dec, AC_HELP_STRING([--with-jbig2dec],[include JBIG2 decode support]))
272JBIG2DIR=src
273SHARE_JBIG2=0
274JBIG2DEVS=''
275if test x$with_jbig2dec != xno; then
276  AC_MSG_CHECKING([for local jbig2dec library source])
277  for d in jbig2dec jbig2dec-0.2 jbig2dec-0.3; do
278    test -d "$d" && JBIG2DIR=$d && break
279  done
280  if test "x$JBIG2DIR" != xsrc; then
281    AC_MSG_RESULT([$JBIG2DIR])
282  else
283    AC_MSG_RESULT([no])
284    AC_CHECK_LIB([jbig2dec], [jbig2_page_out], [
285	SHARE_JBIG2=1
286    ], [
287	AC_MSG_WARN([disabling support for JBIG2 files])
288        with_jbig2dec=no
289    ])
290  fi
291fi
292if test x$with_jbig2dec != xno; then
293  if test x$ac_cv_header_stdint_h != xyes; then
294    AC_MSG_WARN([JBIG2 support requires stdint types which do not seem to be available.])
295  else
296    JBIG2DEVS='$(PSD)jbig2.dev'
297  fi
298fi
299
300AC_SUBST(JBIG2DIR)
301AC_SUBST(SHARE_JBIG2)
302AC_SUBST(JBIG2DEVS)
303
304dnl look for the jasper JPEG 2000 library
305AC_ARG_WITH(jasper, AC_HELP_STRING([--with-jasper],[link to the JasPer library for JPEG 2000]))
306JASPERDIR=src
307SHARE_JASPER=0
308JPXDEVS=''
309if test x$with_jasper != xno; then
310  AC_MSG_CHECKING([for local jasper library source])
311  for d in jasper jasper-1.7*; do
312    test -d "$d" && JASPERDIR=$d && break
313  done
314  if test "x$JASPERDIR" != xsrc; then
315    AC_MSG_RESULT([$JASPERDIR])
316    AC_MSG_CHECKING([for local jasper configure script])
317    if test -x $JASPERDIR/configure; then
318      AC_MSG_RESULT([yes])
319      echo
320      echo "Running jasper configure script..."
321      olddir=`pwd`
322      cd $JASPERDIR && ./configure
323      cd $olddir
324      echo
325      echo "Continuing with Ghostscript configuration..."
326    else
327      AC_MSG_RESULT([no])
328      AC_MSG_CHECKING([for local jasper autogen.sh script])
329      if test -x $JASPERDIR/autogen.sh; then
330        AC_MSG_RESULT([yes])
331        echo
332        echo "Running jasper autogen script..."
333        olddir=`pwd`
334        cd $JASPERDIR && ./autogen.sh
335        cd $olddir
336        echo
337        echo "Continuing with Ghostscript configuration..."
338      else
339        AC_MSG_ERROR([
340Unable to find $JASPERDIR/src/libjasper/include/jas_config.h,
341or generate generate such a file for this system. You will
342have to build one by hand, or configure, build and install
343the jasper library separately.
344
345You can also pass --without-jasper to configure to disable
346JPEG 2000 PDF image support entirely.
347])
348      fi
349    fi
350  else
351    AC_MSG_RESULT([no])
352    AC_CHECK_LIB([jasper], [jas_image_create], [
353	SHARE_JASPER=1
354    ], [
355	AC_MSG_WARN([disabling support for JPEG 2000 images])
356        with_jasper=no
357    ])
358  fi
359fi
360if test x$with_jasper != xno; then
361  JPXDEVS='$(PSD)jpx.dev'
362fi
363
364AC_SUBST(JASPERDIR)
365AC_SUBST(SHARE_JASPER)
366AC_SUBST(JPXDEVS)
367
368dnl optional X11 for display devices
369AC_PATH_XTRA
370XLIBS=''
371if test x"$no_x" = x"yes"; then
372	AC_MSG_NOTICE([disabling X11 output devices])
373	X11DEVS=''
374else
375	# enable X11 output devices
376	X11DEVS='$(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev'
377	# the makefile wants a list of just the library names in XLIBS
378	for item in -lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS; do
379		stripped=`echo "$item" | sed -e 's/-l//'`
380		if test "x$stripped" != "x$item"; then
381			XLIBS="$XLIBS $stripped"
382		fi
383	done
384fi
385AC_SUBST(X11DEVS)
386AC_SUBST(XLIBS)
387
388dnl executible name
389AC_ARG_WITH(gs, AC_HELP_STRING([--with-gs=NAME],
390	[name of the ghostscript executible [[gs]]]),
391	[GS="$with_gs"],[GS='gs'])
392AC_SUBST(GS)
393
394dnl do we compile the postscript initialization files into Ghostscript?
395COMPILE_INITS="0"
396AC_ARG_ENABLE(compile-inits, AC_HELP_STRING([--enable-compile-inits],
397       [compile initialization files into Ghostscript]),[
398               if test x$enable_compile_inits = xyes; then
399                       COMPILE_INITS="1"
400               fi])
401AC_SUBST(COMPILE_INITS)
402
403dnl --------------------------------------------------
404dnl Check for library functions
405dnl --------------------------------------------------
406
407AC_CHECK_FUNCS([mkstemp], [HAVE_MKSTEMP=-DHAVE_MKSTEMP])
408AC_SUBST(HAVE_MKSTEMP)
409
410AC_CHECK_FUNCS([hypot], [HAVE_HYPOT=-DHAVE_HYPOT])
411AC_SUBST(HAVE_HYPOT)
412
413AC_FUNC_FORK
414AC_PROG_GCC_TRADITIONAL
415AC_FUNC_MALLOC
416AC_FUNC_MEMCMP
417AC_TYPE_SIGNAL
418AC_FUNC_STAT
419AC_FUNC_VPRINTF
420AC_CHECK_FUNCS([bzero dup2 floor gettimeofday memchr memmove memset mkdir mkfifo modf pow putenv rint setenv sqrt strchr strerror strrchr strspn strstr])
421
422dnl --------------------------------------------------
423dnl Do substitutions
424dnl --------------------------------------------------
425
426AC_SUBST(OPT_CFLAGS)
427AC_SUBST(GCFLAGS)
428AC_OUTPUT(Makefile)
429