Add Apache License version 2.0.
[pbc.git] / configure.ac
blob79f564a17d3908ece4bce868441c6552397adc63
1 #-*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 AC_PREREQ(2.59)
5 AC_INIT([pbc], [0.5.14], [blynn@cs.stanford.edu])
6 AM_INIT_AUTOMAKE
7 AC_CONFIG_HEADERS(config.h)
8 AC_CONFIG_MACRO_DIR([m4])
9 AC_CONFIG_SRCDIR([./])
10 LT_INIT
11 #AC_CANONICAL_HOST
13 CFLAGS=
14 default_fink_path=/sw
15 case $host_os in
16      darwin*) 
17               dnl fink installation
18               AC_MSG_CHECKING([for a fink installation at $default_fink_path])
19               if test -d $default_fink_path; then 
20                  AC_MSG_RESULT([found it!])
21                  AC_MSG_NOTICE([Adding -I$default_fink_path/include to CPPFLAGS])
22                  CPPFLAGS="-I$default_fink_path/include $CPPFLAGS"
23                  AC_MSG_NOTICE([Adding -L$default_fink_path/lib to LDFLAGS])
24                  LDFLAGS="-L$default_fink_path/lib $LDFLAGS"
25               else
26                 AC_MSG_RESULT(none)
27                 AC_MSG_NOTICE([You may need to add set CPPFLAGS and LDFLAGS for gmp, etc.])
28               fi
29               ;;
30 esac
32 ############################
33 # Configs for Windows DLLs.
34 # Framework for the below was extracted and
35 # modeled after the libgmp configure script.
37 AC_LIBTOOL_WIN32_DLL
38 AC_SUBST(LIBPBC_DLL,0)
40 case $host in
41   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
42     if test -z "$enable_shared"; then
43       enable_shared=no
44     fi
45     # Don't allow both static and DLL.
46     if test "$enable_shared" != no && test "$enable_static" != no; then
47       AC_MSG_ERROR([cannot build both static and DLL, since gmp.h is different for each.
48 Use "--disable-static --enable-shared" to build just a DLL.])
49     fi
51     # "-no-undefined" is required when building a DLL, see documentation on
52     # AC_LIBTOOL_WIN32_DLL.  Also, -no-undefined needs a version number
53     # or it will complain about not having a nonnegative integer.
54     if test "$enable_shared" = yes; then
55       PBC_LDFLAGS="$PBC_LDFLAGS -no-undefined 0 -Wl,--export-all-symbols"
56       LIBPBC_LDFLAGS="$LIBPBC_LDFLAGS -Wl,--output-def,.libs/libpbc.dll.def"
57       LIBPBC_DLL=1
58     fi
59     ;;
60 esac
61 case $host in
62   *-*-mingw*)
63     gcc_cflags_optlist="$gcc_cflags_optlist nocygwin"
64     gcc_cflags_nocygwin="-mno-cygwin"
65     ;;
66 esac
68 AC_SUBST(PBC_LDFLAGS)
69 AC_SUBST(LIBPBC_LDFLAGS)
70 ############################
72 # Checks for programs.
73 AC_PROG_CC
74 AM_PROG_CC_C_O
75 AC_PROG_CPP
76 AC_PROG_INSTALL
77 AC_PROG_LN_S
78 AC_PROG_MAKE_SET
80 AC_PROG_LEX
81 if test "x$LEX" != xflex; then
82   echo "************************"
83   echo "flex not found"
84   echo "************************"
85   exit -1
88 AC_PROG_YACC
89 if test "x$YACC" != "xbison -y"; then
90   echo "************************"
91   echo "bison not found"
92   echo "************************"
93   exit -1
96 # Checks for libraries.
97 lib_err_msg="add its path to LDFLAGS\nsee ./configure --help"
98 AC_CHECK_LIB( [m], [pow], [],[
99               echo "************************"
100               echo "m library not found"
101               echo -e $lib_err_msg
102               echo "************************"
103               exit -1
104               ])
105 AC_CHECK_LIB( [gmp], [__gmpz_init], [],[
106               echo "************************"
107               echo "gmp library not found"
108               echo -e $lib_err_msg
109               echo "************************"
110               exit -1
111               ])
112 dnl Reset libs because most programs do not need to link against all of these libs.
113 LIBS=
115 # Checks for header files.
116 AC_FUNC_ALLOCA
117 AC_HEADER_STDC
118 AC_CHECK_HEADERS([stdlib.h string.h sys/time.h])
120 # Checks for typedefs, structures, and compiler characteristics.
121 AC_C_CONST
122 AC_C_INLINE
123 AC_TYPE_SIZE_T
124 AC_HEADER_TIME
126 dnl setup CFLAGS
127 with_enable_optimized="no"
128 AC_ARG_ENABLE( optimized, 
129               [AS_HELP_STRING([--enable-optimized],
130                               [Enable optimized build])],
131               [with_enable_optimized="$withval"],
132               [with_enable_optimized="no"])
135 with_safe_clean=n
136 AC_ARG_ENABLE( safe-clean,
137               [AS_HELP_STRING([--enable-safe-clean],
138                               [When free any PBC element or GMP mpz_t, fill internal memory inside the element by zero])],
139               [with_safe_clean=y],
140               [with_safe_clean=n])
142 with_debug=n
143 AC_ARG_ENABLE( debug,
144               [AS_HELP_STRING([--enable-debug],
145                               [Add extra debugging information. Forbid compiling optimization.])],
146                               [with_debug=y],
147                               [with_debug=n])
149 CFLAGS="$CFLAGS -Wall -W -Wfloat-equal -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wredundant-decls \
150 -Wendif-labels -Wshadow -pipe -ffast-math -U__STRICT_ANSI__ -std=gnu99"
151 if test "$with_debug" == "y"; then
152     CFLAGS="$CFLAGS -g3 -O0"
153 elif test "$with_enable_optimized" != "no"; then
154         CFLAGS="$CFLAGS -g -O2"
155 else
156         CFLAGS="$CFLAGS -fomit-frame-pointer -O3"
159 if test "$with_safe_clean" != "n"; then
160   CFLAGS="$CFLAGS -DSAFE_CLEAN"
163 # Checks for library functions.
164 AC_FUNC_MALLOC
165 AC_FUNC_REALLOC
166 AC_CHECK_FUNCS([floor gettimeofday memmove memset pow sqrt strchr strdup])
168 AC_CONFIG_FILES([Makefile example/Makefile gen/Makefile])
169 AC_OUTPUT
171 echo -ne "\n"
172 echo "global build variables"
173 echo "-----------------------------------------"
174 echo `date`
175 echo "host info:        $host"
176 echo "optimized build:  $with_enable_optimized"
177 echo "compiler (CC):    $CC"
178 echo "LDFLAGS:          $LDFLAGS"
179 echo "CPPFLAGS:         $CPPFLAGS"
180 echo "CFLAGS:           $CFLAGS"
181 echo "LEX:              $LEX"
182 echo "AM_LFLAGS:        $AM_LFLAGS"
183 echo "LFLAGS:           $LFLAGS"
184 echo "YACC:             $YACC"
185 echo "AM_YFLAGS:        $AM_YFLAGS"
186 echo "YFLAGS:           $YFLAGS"
187 echo "-----------------------------------------"
188 echo -ne "\n"
190 syscmd(bison -d -b pbc/parser pbc/parser.y)
191 syscmd(flex -o pbc/lex.yy.c --header-file=pbc/lex.yy.h pbc/parser.lex)