Files
vlibc/configure.ac

198 lines
8.6 KiB
Plaintext

# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#
# vlibc — build configuration (see building/C.md and layouts/C.md).
AC_PREREQ([2.71])
AC_INIT([vlibc],
[0.1.0],
[https://vox.dev/vlibc],
[vlibc],
[https://vox.dev/])
AC_CONFIG_SRCDIR([include/vlibc.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign subdir-objects])
# ---- Language / compiler -------------------------------------------------
# vlibc is implemented in C. Exactly one compiler is selected, with no fallback
# to another (building/C.md): GCC.
#
# Note: AC_PROG_CC sets $GCC to "yes" for any __GNUC__-compatible compiler
# (including clang), so it cannot be used to enforce the single-compiler rule.
# Verify the compiler is genuinely GCC, not a compatible one.
AC_PROG_CC
# AM_PROG_AS: library sources include raw x86_64 assembly (the setjmp family
# in src/setjmp/x86_64/*.s), which automake compiles through CCAS/CCASFLAGS.
AM_PROG_AS
AC_MSG_CHECKING([whether the compiler is GCC])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || defined(__clang__)
#error "vlibc requires GCC"
#endif
])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([vlibc must be built with GCC (building/C.md). The active compiler is not GCC; re-run with CC=gcc. No fallback to another compiler is provided.])])
# Enable standard library extensions / POSIX declarations in the host toolchain.
AC_USE_SYSTEM_EXTENSIONS
# ---- C standard ----------------------------------------------------------
# The latest stable C standard is used by default (C23). C2y (C29) is opt-in
# until it is ratified (languages/C.md).
AC_ARG_ENABLE([c29],
[AS_HELP_STRING([--enable-c29],
[Enable experimental C2y (C29) mode, incl. defer statements (default: C23)])])
vlibc_cstd=c23
AS_IF([test "x$enable_c29" = "xyes"], [vlibc_cstd=c2y])
AC_MSG_CHECKING([whether $CC supports -std=$vlibc_cstd])
vlibc_save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -std=$vlibc_cstd"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([$CC does not support -std=$vlibc_cstd])])
CFLAGS=$vlibc_save_CFLAGS
# -fno-stack-protector: distro GCC builds enable -fstack-protector-strong by
# default, which would make library objects reference __stack_chk_fail — a
# symbol vlibc does not provide yet. Every make-check test binary and every
# -nostdlib -static consumer links against the plain archive, and one
# undefined __stack_chk_fail in it breaks the whole self-hosting link. A
# bootstrap libc must build its own objects without the protector (the stack
# protector runtime lands with the hardening work, after which this flag is
# revisited). Tests compile with the same flag (tests/Makefile.am wiring in
# Makefile.am).
AC_SUBST([VLIBC_CFLAGS], ["-std=$vlibc_cstd -Wall -Wextra -fno-stack-protector"])
# ---- Compatibility profile ----------------------------------------------
# Exactly one of the five profiles is active. They are mutually exclusive;
# the default is "vlibc" (glibc-extended, but without the spoofing layer).
#
# 1 --enable-onlyposix pure POSIX, nothing more
# 2 --enable-muslmimic musl-like, light
# 3 --enable-muslext musl-extended
# 4 --enable-spoof glibc replica (drop-in compatibility)
# 5 (default) vlibc (glibc-extended)
AC_ARG_ENABLE([onlyposix],
[AS_HELP_STRING([--enable-onlyposix],
[Build the lightest vlibc: pure POSIX, nothing more])])
AC_ARG_ENABLE([muslmimic],
[AS_HELP_STRING([--enable-muslmimic],
[Build a musl-like vlibc: light, musl-compatible])])
AC_ARG_ENABLE([muslext],
[AS_HELP_STRING([--enable-muslext],
[Build musl-extended vlibc: musl plus more])])
AC_ARG_ENABLE([spoof],
[AS_HELP_STRING([--enable-spoof],
[Build a glibc replica: drop-in glibc compatibility])])
vlibc_profile=vlibc
vlibc_profiles=0
AS_IF([test "x$enable_onlyposix" = "xyes"],
[vlibc_profile=onlyposix; vlibc_profiles=$((vlibc_profiles + 1))])
AS_IF([test "x$enable_muslmimic" = "xyes"],
[vlibc_profile=muslmimic; vlibc_profiles=$((vlibc_profiles + 1))])
AS_IF([test "x$enable_muslext" = "xyes"],
[vlibc_profile=muslext; vlibc_profiles=$((vlibc_profiles + 1))])
AS_IF([test "x$enable_spoof" = "xyes"],
[vlibc_profile=spoof; vlibc_profiles=$((vlibc_profiles + 1))])
AS_IF([test "$vlibc_profiles" -gt 1],
[AC_MSG_ERROR([--enable-onlyposix, --enable-muslmimic, --enable-muslext and --enable-spoof are mutually exclusive])])
case "$vlibc_profile" in
onlyposix) vlibc_level=1 ;;
muslmimic) vlibc_level=2 ;;
muslext) vlibc_level=3 ;;
spoof) vlibc_level=4 ;;
vlibc) vlibc_level=5 ;;
esac
AC_DEFINE_UNQUOTED([VLIBC_PROFILE], ["$vlibc_profile"],
[Active compatibility profile name])
AC_DEFINE_UNQUOTED([VLIBC_LEVEL], [$vlibc_level],
[Active compatibility level (1..5)])
AS_CASE([$vlibc_profile],
[onlyposix], [AC_DEFINE([VLIBC_PROFILE_ONLYPOSIX], [1], [Pure POSIX profile])],
[muslmimic], [AC_DEFINE([VLIBC_PROFILE_MUSLMIMIC], [1], [musl-like profile])],
[muslext], [AC_DEFINE([VLIBC_PROFILE_MUSLEXT], [1], [musl-extended profile])],
[spoof], [AC_DEFINE([VLIBC_PROFILE_SPOOF], [1], [glibc spoof profile])],
[vlibc], [AC_DEFINE([VLIBC_PROFILE_VLIBC], [1], [vlibc (glibc-ext) profile])])
AC_SUBST([vlibc_profile])
AC_SUBST([vlibc_level])
AM_CONDITIONAL([PROFILE_GE_2], [test "$vlibc_level" -ge 2])
AM_CONDITIONAL([PROFILE_GE_3], [test "$vlibc_level" -ge 3])
# ---- Install method ------------------------------------------------------
# "alongside" installs vlibc next to the system libc: headers and libraries go
# under a vlibc-specific tree, used via the vlibc-gcc / vlibc-clang drivers.
# "overwrite" replaces the system libc in place.
AC_ARG_WITH([install],
[AS_HELP_STRING([--with-install=@<:@alongside|overwrite@:>@],
[Install method: alongside (default) keeps the system libc; overwrite replaces it])],
[],
[with_install=alongside])
AS_CASE([$with_install],
[alongside|overwrite], [],
[AC_MSG_ERROR([--with-install must be 'alongside' or 'overwrite'])])
AC_DEFINE_UNQUOTED([VLIBC_INSTALL_MODE], ["$with_install"], [Install mode])
AM_CONDITIONAL([INSTALL_OVERWRITE], [test "x$with_install" = "xoverwrite"])
AC_SUBST([vlibc_install_mode], ["$with_install"])
# ---- Static linking ------------------------------------------------------
# Full static linking is a hard requirement for every profile except spoof
# (the spoofing layer needs dynamic facilities a static build cannot provide).
AS_IF([test "x$vlibc_profile" != "xspoof" && test "x$enable_static" = "xno"],
[AC_MSG_ERROR([the '$vlibc_profile' profile requires static linking; remove --disable-static])])
# ---- Reference libc for benchmarks --------------------------------------
# Benchmarks are built against the software vlibc replaces (musts/BENCHMARKING.md).
# By default they link against vlibc itself; --with-libc selects musl or glibc
# for the reference comparison.
AC_ARG_WITH([libc],
[AS_HELP_STRING([--with-libc=@<:@vlibc|musl|glibc@:>@],
[Select the libc that benchmark binaries link against (default: vlibc)])],
[],
[with_libc=vlibc])
AS_CASE([$with_libc],
[vlibc], [],
[glibc], [],
[musl],
[AC_CHECK_PROG([MUSL_CC], [musl-gcc], [musl-gcc], [])
AS_IF([test -z "$MUSL_CC"],
[AC_MSG_ERROR([--with-libc=musl requires musl-gcc to be in PATH])])],
[AC_MSG_ERROR([--with-libc must be 'vlibc', 'musl', or 'glibc'])])
AM_CONDITIONAL([BENCH_LINK_VLIBC], [test "x$with_libc" = "xvlibc"])
AM_CONDITIONAL([BENCH_LINK_MUSL], [test "x$with_libc" = "xmusl"])
# ---- Libtool -------------------------------------------------------------
LT_INIT
AC_CONFIG_FILES([Makefile
benchmarks/Makefile
include/vlibc/features.h
tools/vlibc-gcc
tools/vlibc-clang])
# Make the generated compiler drivers executable. This must run after the
# files are created, so it lives in AC_CONFIG_COMMANDS (not the AC_CONFIG_FILES
# trailing command, which runs before generation).
AC_CONFIG_COMMANDS([chmod-vlibc-drivers],
[chmod +x tools/vlibc-gcc tools/vlibc-clang])
AC_OUTPUT