configure.ac 11 KB
Newer Older
1 2 3 4 5 6 7
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([libcap], [0.1])
AC_CONFIG_SRCDIR([src/common/cptr_cache.c])
AC_CONFIG_AUX_DIR(autoconf)
8
AC_CONFIG_HEADERS([config.h])
9 10 11 12 13

LT_INIT
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([subdir-objects foreign])

14 15 16 17 18 19
# --------------------------------------------------
# Host check
# --------------------------------------------------

AC_CANONICAL_HOST

20 21
AC_MSG_CHECKING([for OS X host])
AS_CASE([$host],
22

23
    [-*-*-darwin*],
24
    [
25
        AC_MSG_RESULT([yes])
26 27
        AC_DEFINE(CAP_OS_DARWIN, 1, [Build for OS X host])
        AC_SUBST(CAP_OS_DARWIN)
28 29 30 31 32
    ],

    [*],
    [
        AC_MSG_RESULT([no])
33 34
    ])

35

36
# --------------------------------------------------
37
# libcap features, packages, and config
38 39
# --------------------------------------------------

40
# Platform = user xor kernel
41
AC_ARG_VAR([PLATFORM],
42 43 44
    [The platform to build for @{:@user|kernel@:}@ (default=user)])
AS_CASE([$PLATFORM],
    [user],
45
    [PLATFORM_DIR=platform/user],
46
    [kernel],
47
    [PLATFORM_DIR=platform/kernel],
48 49 50 51 52
    [*],
    [
        AC_MSG_NOTICE([PLATFORM (val=$PLATFORM) unset or invalid.])
        AC_MSG_NOTICE([Defaulting to PLATFORM=user.])
        PLATFORM=user
53
        PLATFORM_DIR=platform/user
54
    ])
55
AC_MSG_NOTICE([Building for PLATFORM=$PLATFORM.])
56
AC_SUBST(PLATFORM)
57
AC_SUBST(PLATFORM_DIR)
58

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
# CSpace depth. We use bits to enforce that the depth is a power of 2.
AC_ARG_VAR([CSPACE_DEPTH_BITS],
    [Set CSPACE depth to 2^CSPACE_DEPTH_BITS (default=2, default depth=4)])
AS_IF([test "x$CSPACE_DEPTH_BITS" = "x"],
    [CSPACE_DEPTH_BITS="2"]) # default
AS_CASE([$CSPACE_DEPTH_BITS],

    [@<:@0-8@:>@],
    [CAP_CSPACE_DEPTH_BITS=$CSPACE_DEPTH_BITS],

    [*],
    [
        AC_MSG_ERROR([CSpace depth bits (val=$CSPACE_DEPTH_BITS) invalid. Please choose a value between 0 and 8.])
    ])
AC_MSG_NOTICE([CSpace depth bits = $CAP_CSPACE_DEPTH_BITS.])
74
AC_SUBST(CAP_CSPACE_DEPTH_BITS)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

# CNode table size. Again, we use bits to enforce that it's a power of 2.
AC_ARG_VAR([CSPACE_CNODE_TABLE_BITS],
    [CNode tables have 2^CSPACE_CNODE_TABLE_BITS total slots (default=6, default size=64)])
AS_IF([test "x$CSPACE_CNODE_TABLE_BITS" = "x"],
    [CSPACE_CNODE_TABLE_BITS="6"]) # default
AS_CASE([$CSPACE_CNODE_TABLE_BITS],

    [@<:@1-9@:>@],
    [CAP_CSPACE_CNODE_TABLE_BITS=$CSPACE_CNODE_TABLE_BITS],

    [*],
    [
        AC_MSG_ERROR([CSpace cnode table bits (val=$CSPACE_CNODE_TABLE_BITS) invalid. Please choose a value between 1 and 9.])
    ])
AC_MSG_NOTICE([CNode table bits = $CAP_CSPACE_CNODE_TABLE_BITS.])
91
AC_SUBST(CAP_CSPACE_CNODE_TABLE_BITS)
92

93 94 95 96 97 98 99 100 101 102
# Allow global capability types?
AC_ARG_ENABLE([global_cap_types],
    [AS_HELP_STRING([--enable-global-cap-types],
        [(for backward compatability) Allow cspaces to share one global capability type system (default=yes)])],
    [],
    [enable_global_cap_types="yes"])
AS_IF([test "x$enable_global_cap_types" = "xyes"],
    [
        AC_DEFINE([CAP_ENABLE_GLOBAL_TYPES], 1,
            [Allow cspaces to use one global type system.])
103 104 105 106 107
        # Using cat instead of AC_SUBST_FILE. (If you AC_SUBST_FILE a
        # variable in one case and AC_SUBST it in another, autoconf
        # gets confused.)
        CAP_INCLUDE_GLOBAL_TYPES=`cat $srcdir/src/include/global_cap_types.h`
        AC_SUBST([CAP_INCLUDE_GLOBAL_TYPES])
108 109 110 111 112 113 114 115
        AC_MSG_NOTICE([Allowing global capability type system.])
    ],
    [
        CAP_INCLUDE_GLOBAL_TYPES=
        AC_SUBST([CAP_INCLUDE_GLOBAL_TYPES])
        AC_MSG_NOTICE([Disallowing global capability type system.])
    ])

116 117
AM_SUBST_NOTMAKE(CAP_INCLUDE_GLOBAL_TYPES)

118
# Kernel module build?
119
AS_IF([test "x$PLATFORM" = "xkernel"],
120 121

    [
122
        # Build libcap as kernel module, in addition to static lib.a
123 124
        AC_ARG_ENABLE([kernel_module],
            [AS_HELP_STRING([--disable-kernel-module],
125 126 127
                [Disable kernel module build (default=no)])],
            [],
            [enable_kernel_module="yes"])
128 129 130
        AM_CONDITIONAL(ENABLE_KERNEL_MODULE, 
            [test "x$enable_kernel_module" = "xyes"])

131 132 133 134
        AM_COND_IF([ENABLE_KERNEL_MODULE],
            [AC_MSG_NOTICE([Building kernel module.])],
            [AC_MSG_NOTICE([Not building kernel module.])])

135 136 137 138 139 140
    ],

    [

        AM_CONDITIONAL(ENABLE_KERNEL_MODULE, 
            [false])
141 142 143

    ])

144
# Build tests?
145
AC_ARG_ENABLE([test_build],
146 147 148 149
    [AS_HELP_STRING([--enable-test-build],
        [Enable building test applications (default=no)])],
    [],
    [enable_test_build="no"])
150 151
AM_CONDITIONAL(ENABLE_TEST_BUILD, 
    [test "x$enable_test_build" = "xyes"])
152 153 154 155
AM_COND_IF([ENABLE_TEST_BUILD],
    [AC_MSG_NOTICE([Building tests.])],
    [AC_MSG_NOTICE([Not building tests.])])

156

157
# --------------------------------------------------
158
# Checks for programs.
159 160
# --------------------------------------------------

161 162 163 164 165 166 167
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_LN_S
AC_PROG_MKDIR_P
AC_PROG_INSTALL
168
AC_PROG_AWK # for a calculation below
169
AC_PROG_MKDIR_P
170

171
# --------------------------------------------------
172
# Checks for libraries.
173 174 175
# --------------------------------------------------

# Check for pthreads
176
AS_IF([test "x$PLATFORM" = "xuser"],
177 178 179
    [AC_CHECK_LIB([pthread], [pthread_create])])

# Check glib (the gangsta lib)
180
AS_IF([test "x$PLATFORM" = "xuser"],
181 182 183 184 185 186 187 188 189 190 191

    [
        GLIB=/usr # default prefix
        AC_ARG_WITH([glib],
            [AS_HELP_STRING([--with-glib=DIRECTORY],
                [find glib install in DIRECTORY])],
            [MAYBE_GLIB="$with_glib"])

        # Set up vars for the glib check
        old_CFLAGS=$CFLAGS
        old_LDFLAGS=$LDFLAGS
192 193 194 195 196 197
        old_PKG_CONFIG_PATH=$PKG_CONFIG_PATH

        # (It's tricky to try to locate the .pc file, so we don't
        # try to do the absolute path with the call to pkg-config)
        GLIB_INCLUDES=`pkg-config --cflags glib-2.0`
        GLIB_LIBS=`pkg-config --libs glib-2.0`
198 199 200 201 202 203 204
        CFLAGS="${GLIB_INCLUDES} $CFLAGS"
        LDFLAGS="${GLIB_LIBS} $LDFLAGS"
    
        AC_CHECK_TYPE(gpointer,
            [],
            [AC_MSG_ERROR([Your glib includes seem wrong!])],
            [[#include <glib.h>]])
205

206 207 208 209 210 211 212 213
        AC_CHECK_LIB(glib-2.0,
            g_slice_alloc0,
            [],
            [AC_MSG_ERROR(Your glib does not have g_slice_alloc0; upgrade to 2.10+)])

        # Restore vars
        CFLAGS="$old_CFLAGS"
        LDFLAGS="$old_LDFLAGS"
214
        PKG_CONFIG_PATH="$old_PKG_CONFIG_PATH"
215

216 217 218 219 220 221
        AC_SUBST(GLIB_INCLUDES)
        AC_SUBST(GLIB_LIBS)

    ])

# Check for kernel build system
222
AS_IF([test "x$PLATFORM" = "xkernel"],
223 224 225 226 227 228 229

    [
        KDIR=/lib/modules/`uname -r`/build # default location of build system

        AC_ARG_WITH([kernel-headers],
            [AS_HELP_STRING([--with-kernel-headers=DIRECTORY],
                [find Linux kernel build stuff in DIRECTORY])],
230
            [KDIR="$with_kernel_headers"])
231 232 233 234

        # Sanity check it (in the future, we could maybe check the
        # kernel version in the top of the kernel Makefile)
        AC_CHECK_FILE($KDIR/Makefile,
235 236 237
            [AC_MSG_NOTICE([Found kernel Makefile in $KDIR])],
            [AC_MSG_ERROR([Could not find kernel Makefile in $KDIR!])])

238

239 240
        AC_SUBST(KDIR)

241 242 243
    ])

# --------------------------------------------------
244
# Checks for header files.
245 246
# --------------------------------------------------

247 248
AC_CHECK_HEADERS([stdint.h stdlib.h string.h unistd.h])

249 250 251 252
# --------------------------------------------------
# Checks for types
# --------------------------------------------------

253 254 255
AC_CHECK_HEADER_STDBOOL
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T
256
AC_CHECK_SIZEOF([unsigned long])
257

258 259 260
# Sanity check cspace depth and cnode table size, now that we
# have the size of an unsigned long.
AC_MSG_CHECKING([that cspace config is sane])
261 262
cptr_size=`$AWK -v cap_cspace_depth_bits=$CAP_CSPACE_DEPTH_BITS -v cap_cspace_cnode_table_bits=$CAP_CSPACE_CNODE_TABLE_BITS -f $srcdir/scripts/cptr_size.awk`
long_size=`$AWK -v bytes_in_an_unsigned_long=$ac_cv_sizeof_unsigned_long -f $srcdir/scripts/ulong_size.awk`
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
AS_IF([test "$cptr_size" -gt "$long_size"],
    [
        AC_MSG_RESULT([no])
        AC_MSG_NOTICE([The cspace configuration you chose won't work.])
        AC_MSG_NOTICE([Your choice must fulfill this:])
        AC_MSG_NOTICE([  let a = 2^cspace depth bits])
        AC_MSG_NOTICE([  let b = a * (table bits - 1) + cspace depth bits])
        AC_MSG_NOTICE([  let c = bits in an unsigned long])
        AC_MSG_NOTICE([  require: b <= c])
        AC_MSG_NOTICE([(This has to do with packing bits into an unsigned long for cptr's.)])
        AC_MSG_NOTICE([FYI - The default (depth bits = 2, table bits = 6) should work on 64- and 32-bit.])
        AC_MSG_ERROR([Please re-configure with different cspace settings.])
    ])
AC_MSG_RESULT([yes])

278 279 280
# --------------------------------------------------
# Checks for structures
# --------------------------------------------------
281

282 283 284 285 286 287 288
# --------------------------------------------------
# Checks for compiler characteristics
# --------------------------------------------------

AC_C_INLINE

# --------------------------------------------------
289
# Checks for library functions.
290 291
# --------------------------------------------------

292 293 294
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset strdup])

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
# --------------------------------------------------
# Set up cptr cache definitions and accessors
# --------------------------------------------------

# These are computed with awk scripts instead of the CPP
# since the CPP is limited with respect to loops/recursion,
# exponentiation, and so on. Awk seems like it will be available on most build
# systems (no? including Windows? I'm guessing yes if they have
# support to do autoconf crap, installed gnu autotools or something).
CAP_CPTR_CACHE_BMAP_DEFS=`$AWK -v cap_cspace_depth_bits=$CAP_CSPACE_DEPTH_BITS -v cap_cspace_cnode_table_bits=$CAP_CSPACE_CNODE_TABLE_BITS -f $srcdir/scripts/cptr_cache_bmap_defs.awk`
CAP_CPTR_CACHE_BMAP_FOR_LEVEL=`$AWK -v cap_cspace_depth_bits=$CAP_CSPACE_DEPTH_BITS -f $srcdir/scripts/cptr_cache_bmap_for_level.awk`

AC_SUBST(CAP_CPTR_CACHE_BMAP_DEFS)
AC_SUBST(CAP_CPTR_CACHE_BMAP_FOR_LEVEL)

# Don't subst these in makefile's, or else the makefiles will break
AM_SUBST_NOTMAKE(CAP_CPTR_CACHE_BMAP_DEFS)
AM_SUBST_NOTMAKE(CAP_CPTR_CACHE_BMAP_FOR_LEVEL)

# --------------------------------------------------
# Misc
# --------------------------------------------------

# I can't remember if there is a standard way to do this
CAP_AUTOCONF_NOTICE="This file was autogenerated by configure."
AC_SUBST(CAP_AUTOCONF_NOTICE)

322 323 324
# --------------------------------------------------
# Config files
# --------------------------------------------------
325 326 327

AC_CONFIG_FILES(
  Makefile
328

329
  src/Makefile
330
  src/common/Makefile
331

332
  src/include/Makefile
333
  src/include/libcap_config.h
334 335
  src/include/libcap_types.h
  src/include/libcap.h
336 337 338 339

  src/platform/Makefile
  src/platform/kernel/Makefile
  src/platform/kernel/src/Makefile
340 341 342
  src/platform/kernel/module/Makefile
  src/platform/kernel/module/Kbuild
  src/platform/kernel/Kbuild
343
  src/platform/kernel/include/Makefile
344
  src/platform/kernel/test/Makefile
345 346 347 348

  src/platform/user/Makefile
  src/platform/user/src/Makefile
  src/platform/user/include/Makefile
349
  src/platform/user/test/Makefile
350 351
)
AC_OUTPUT
352