summaryrefslogtreecommitdiff
path: root/configure.ac
blob: b8e97bc10b90340e1ffea4ea587442c24dd3d0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
dnl Process this file with autoconf to produce a configure script.

AC_INIT()
AC_PREREQ(2.52)

AC_MSG_NOTICE([Configuring ccache])

AC_CONFIG_HEADER(config.h)

AC_SUBST(extra_deps)
AC_SUBST(include_dev_mk)
AC_SUBST(test_suites)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_CHECK_TOOL(AR, ar)
if test -z "$ac_ct_AR"; then
    AC_MSG_ERROR(cannot find ar)
fi

m4_include(m4/feature_macros.m4)

# If GCC, turn on warnings.
if test "x$GCC" = "xyes"; then
    CFLAGS="$CFLAGS -Wall -W"
else
    CFLAGS="$CFLAGS -O"
fi

AC_HEADER_DIRENT
AC_HEADER_TIME
AC_HEADER_STDBOOL
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(ctype.h pwd.h stdlib.h string.h strings.h sys/time.h sys/mman.h)
AC_CHECK_HEADERS(termios.h)

AC_CHECK_FUNCS(asprintf)
AC_CHECK_FUNCS(gethostname)
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getpwuid)
AC_CHECK_FUNCS(gettimeofday)
AC_CHECK_FUNCS(mkstemp)
AC_CHECK_FUNCS(realpath)
AC_CHECK_FUNCS(snprintf)
AC_CHECK_FUNCS(strndup)
AC_CHECK_FUNCS(utimes)
AC_CHECK_FUNCS(vasprintf)
AC_CHECK_FUNCS(vsnprintf)

AC_CACHE_CHECK([for compar_fn_t in stdlib.h],ccache_cv_COMPAR_FN_T, [
    AC_TRY_COMPILE(
        [#include <stdlib.h>],
        [void test_fn(void) { qsort(NULL, 0, 0, (__compar_fn_t)NULL); }],
        ccache_cv_COMPAR_FN_T=yes,
        ccache_cv_COMPAR_FN_T=no)])
if test x"$ccache_cv_COMPAR_FN_T" = x"yes"; then
   AC_DEFINE(HAVE_COMPAR_FN_T, 1,
             Define to 1 if you have the `__compar_fn_t' typedef.)
fi

AC_CACHE_CHECK([for C99 vsnprintf],ccache_cv_HAVE_C99_VSNPRINTF,[
AC_TRY_RUN([
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
void foo(const char *format, ...) {
    va_list ap;
    int len;
    char buf[5];

    va_start(ap, format);
    len = vsnprintf(0, 0, format, ap);
    va_end(ap);
    if (len != 5) exit(1);

    if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);

    exit(0);
}
main() { foo("hello"); }
],
ccache_cv_HAVE_C99_VSNPRINTF=yes,
ccache_cv_HAVE_C99_VSNPRINTF=no,
ccache_cv_HAVE_C99_VSNPRINTF=cross)])
if test x"$ccache_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
    AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
              Define to 1 if you have the `vsnprintf' function.)
fi

dnl Check for zlib.
AC_CACHE_CHECK(
    [for zlib >= 1.2.3],
    [ccache_cv_zlib_1_2_3],
    AC_TRY_COMPILE(
        [#include <zlib.h>],
        [
        #if (ZLIB_VERNUM >= 0x1230)
        #else
        #error "ZLIB_VERNUM < 0x1230"
        #endif
        ],
        [ccache_cv_zlib_1_2_3=yes],
        [ccache_cv_zlib_1_2_3=no]))
AC_CHECK_LIB(z, gzdopen, true)
if test $ccache_cv_zlib_1_2_3 = yes && test $ac_cv_lib_z_gzdopen = yes; then
    use_bundled_zlib=no
else
    use_bundled_zlib=yes
    extra_deps="zlib/libz.a"
    CPPFLAGS="$CPPFLAGS -I\$(srcdir)/zlib"
    LIBS="-Lzlib $LIBS"
    mkdir -p zlib
fi

AC_C_INLINE

dnl Check for "extern inline".
AC_CACHE_CHECK(
    for extern inline,
    ac_cv_c_extern_inline,
    [
    ac_cv_c_extern_inline=no
    AC_TRY_COMPILE(
        [
        extern $ac_cv_c_inline double foo(double x);
        extern $ac_cv_c_inline double foo(double x) { return x+1.0; };
        double foo (double x) { return x + 1.0; };
        ],
        [foo(1.0)],
        [ac_cv_c_extern_inline="yes"])])
if test "$ac_cv_c_extern_inline" != no ; then
    AC_DEFINE(HAVE_EXTERN_INLINE, 1,
              Define to 1 if your compiler supports extern inline)
fi

dnl Enable developer mode if dev.mk.in exists.
if test -f $srcdir/dev.mk.in && test "$RUN_FROM_BUILD_FARM" != yes; then
    AC_MSG_NOTICE(Enabling developer mode)
    AC_CONFIG_FILES([dev.mk])
    include_dev_mk='include dev.mk'
    version=`(git describe --dirty 2>/dev/null || echo vunknown) | sed -e 's/v//' -e 's/-/+/' -e 's/-/_/g'`
    echo "const char CCACHE_VERSION@<:@@:>@ = \"$version\";" >version.c
elif test ! -f $srcdir/version.c; then
    AC_MSG_WARN(unable to determine ccache version)
    echo "const char CCACHE_VERSION@<:@@:>@ = \"unknown\";" >version.c
fi

dnl Find test suite files.
test_suites=""
for x in $srcdir/test/test_*.c; do
    test_suites="$test_suites $x"
done

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

cat <<EOF >config.h.tmp
#ifndef CCACHE_CONFIG_H
#define CCACHE_CONFIG_H
EOF
cat config.h >>config.h.tmp
echo '#endif' >>config.h.tmp
mv config.h.tmp config.h

mkdir -p .deps test

if test x$use_bundled_zlib = xyes; then
   AC_MSG_WARN(using bundled zlib)
fi

AC_MSG_NOTICE(now build ccache by running make)