#!/bin/sh # Try and be like autotools configure, but without autotools VERSION=0.26 # Ensure that we do not inherit these from env OS= BUILD= HOST= TARGET= DEBUG= BUILD_TESTS= BUILD_API_DOCS= BUILD_STATIC= SILENT=yes HAVE_VISIBILITY=no usage() { cat <<_EOF \`configure' configures XBPS to adapt to many kinds of systems. By default, \`make install' will install all the files in \`/usr/local/sbin', \`/usr/local/lib' etc. You can specify an installation prefix other than \`/usr/local' using \`--prefix', for instance \`--prefix=\$HOME'. --prefix=DIR Install architecture-independent files in PREFIX --exec-prefix=DIR Install architecture-dependent files in EPREFIX --sbindir=DIR System admin executables [PREFIX/sbin] --libdir=DIR Object code libraries [PREFIX/lib] --includedir=DIR C header files [EPREFIX/include] --mandir=DIR Man documentation [EPREFIX/share/man] --datadir=DIR Read-only architecture-independent data [EPREFIX/share] --sysconfdir=DIR Configuration files directory [PREFIX/etc] --pkgconfigdir=DIR pkg-config directory [EPREFIX/lib/pkgconfig] --testsdir=DIR Test suite directory [EPREFIX/tests] --verbose Disable silent build to see compilation details --enable-api-docs Install XBPS API Library documentation (default disabled) --enable-debug Build with debugging code and symbols (default disabled) --enable-static Build XBPS static utils (default disabled) --enable-tests Build and install Kyua tests (default disabled) Needs atf >= 0.15 (http://code.google.com/p/kyua) _EOF exit 1 } for x; do opt=${x%%=*} var=${x#*=} case "$opt" in --enable-debug) DEBUG=yes;; --prefix) PREFIX=$var;; --exec-prefix) EPREFIX=$var;; --sbindir) SBINDIR=$var;; --mandir) MANDIR=$var;; --datadir) SHAREDIR=$var;; --build) BUILD=$var;; --host) HOST=$var;; --target) TARGET=$var;; --includedir) INCLUDEDIR=$var;; --sysconfdir) ETCDIR=$var;; --libdir) LIBDIR=$var;; --datadir|--infodir) ;; # ignore autotools --enable-api-docs) BUILD_API_DOCS=$var;; --verbose) unset SILENT;; --pkgconfigdir) PKGCONFIGDIR=$var;; --enable-tests) BUILD_TESTS=yes;; --enable-static) BUILD_STATIC=yes;; --testsdir) TESTSDIR=$var;; --help) usage;; *) echo "$0: WARNING: unknown option $opt" >&2;; esac done : ${SED:=sed} : ${PREFIX:=/usr/local} : ${EPREFIX:=${PREFIX}} : ${SYSCONFDIR:=${PREFIX}/etc} : ${SBINDIR:=${PREFIX}/sbin} : ${LIBDIR:=${EPREFIX}/lib} : ${SHAREDIR:=${EPREFIX}/share} : ${MANDIR:=${EPREFIX}/share/man} : ${INCLUDEDIR:=${EPREFIX}/include} : ${ETCDIR:=${PREFIX}/etc} : ${PKGCONFIGDIR:=${LIBDIR}/pkgconfig} : ${TESTSDIR:=${EPREFIX}/tests} : ${TOPDIR:=..} _which() { x="$(which "$1" 2>/dev/null)" if [ -n "$x" ]; then echo "$x" return 0 fi for x in /sbin/"$1" /usr/sbin/"$1" \ /usr/pkg/sbin/"$1" /usr/local/sbin/"$1" do if [ -e "$x" ]; then echo "$x" return 0 fi done return 1 } CONFIG_H=config.h CONFIG_MK=config.mk if [ -z "$BUILD" ]; then BUILD=`uname -m`-unknown-`uname -s | tr '[:upper:]' '[:lower:]'` fi if [ -z "$HOST" ]; then [ -z "$TARGET" ] && TARGET=$BUILD HOST=$TARGET fi if [ -z "$TARGET" ]; then [ -z "$HOST" ] && HOST=$BUILD TARGET=$HOST fi if [ -z "$OS" ]; then # Derive OS from cpu-manufacturer-os-kernel CPU=${TARGET%%-*} REST=${TARGET#*-} MANU=${REST%%-*} REST=${REST#*-} OS=${REST%%-*} REST=${REST#*-} KERNEL=${REST%%-*} fi echo "Configuring xbps for ... $OS" rm -f $CONFIG_H $CONFIG_MK echo "# Common vars used by XBPS on $OS." >$CONFIG_MK echo "/* $OS */" >$CONFIG_H echo "VERSION = $VERSION" >>$CONFIG_MK echo "TOPDIR ?= $TOPDIR" >>$CONFIG_MK echo "PREFIX ?= $PREFIX" >>$CONFIG_MK echo "EPREFIX ?= $EPREFIX" >>$CONFIG_MK echo "SBINDIR ?= $SBINDIR" >>$CONFIG_MK echo "INCLUDEDIR ?= $INCLUDEDIR" >>$CONFIG_MK echo "LIBDIR ?= $LIBDIR" >>$CONFIG_MK echo "MANDIR ?= $MANDIR" >>$CONFIG_MK echo "SHAREDIR ?= $SHAREDIR" >>$CONFIG_MK echo "PKGCONFIGDIR ?= $PKGCONFIGDIR" >>$CONFIG_MK echo "TESTSDIR ?= $TESTSDIR" >>$CONFIG_MK ETCDIR="${ETCDIR}/xbps" echo "ETCDIR ?= $ETCDIR" >>$CONFIG_MK [ -z "$DEBUG" ] && DEBUG=no if [ -z "$CC" ]; then printf "Looking for compiler ... " for b in $TARGET- ""; do for cc in gcc pcc icc cc clang; do if type $b$cc >/dev/null 2>&1; then CC=$b$cc echo "$CC" break fi done [ -n "$CC" ] && break done if [ -z "$CC" ]; then echo echo "no suitable compiler found - aborting" >&2 exit 1 fi else echo "Using compiler $CC" fi echo "CC = $CC" >>$CONFIG_MK echo "CFLAGS = -O2 -pthread" >>$CONFIG_MK if [ -n "$CFLAGS" ]; then echo "CFLAGS += $CFLAGS" >>$CONFIG_MK fi echo "LDFLAGS = -L\$(TOPDIR)/lib" >>$CONFIG_MK if [ -n "$LDFLAGS" ]; then echo "LDFLAGS += $LDFLAGS" >>$CONFIG_MK fi echo "CPPFLAGS = -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK echo "CPPFLAGS += -DHAVE_CONFIG_H" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_VERSION=\\\"${VERSION}\\\"" >>$CONFIG_MK if [ -d .git ]; then _gitrev=$(git rev-parse master) echo "CPPFLAGS += -DXBPS_GIT=\\\"${_gitrev}\\\"" >>$CONFIG_MK fi if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then echo "Building with debugging symbols." echo "INSTALL_STRIPPED =" >>$CONFIG_MK echo "CFLAGS += -g" >>$CONFIG_MK echo "CPPFLAGS += -DDEBUG" >>$CONFIG_MK else echo "INSTALL_STRIPPED = -s" >>$CONFIG_MK fi case "$OS" in linux) echo "CPPFLAGS += -D_XOPEN_SOURCE=700" >>$CONFIG_MK echo "CPPFLAGS += -D_FILE_OFFSET_BITS=64" >> $CONFIG_MK ;; *) ;; esac # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features XCC="$CC $CFLAGS $CPPFLAGS $LDFLAGS" # Make sure to disable --as-needed for CC tests. XCC="$XCC -Wl,--no-as-needed" check_compiler_flag() { local flag="$1" local mode="$2" local var="$3" local rv=0 [ -z "$var" ] && var="CFLAGS" printf "Checking if $CC supports -${mode}${flag} ... " cat <_ccflag.c #include int main(void) { return 0; } EOF if $XCC -${mode}${flag} _ccflag.c -o _ccflag 2>_ccflag.err; then if ! test -s _ccflag.err; then if [ "$mode" = "W" -a -z "$var" ]; then echo "CPPFLAGS += -${mode}${flag}" >>$CONFIG_MK else echo "$var += -${mode}${flag}" >>$CONFIG_MK fi echo "yes." else rv=1 echo "no." fi else rv=1 echo "no." fi rm -f _ccflag.c _ccflag _ccflag.err return $rv } # # Check for some compiler warning flags. # for f in all extra error shadow "format=2" missing-prototypes \ missing-declarations nested-externs vla no-overlength-strings \ unsafe-loop-optimizations undef sign-compare \ missing-include-dirs old-style-definition \ init-self redundant-decls float-equal missing-noreturn \ cast-align cast-qual pointer-arith comment \ declaration-after-statement write-strings stack-protector; do check_compiler_flag ${f} W done # # Check for some compiler flags. # check_compiler_flag PIC f CFLAGS check_compiler_flag stack-protector-all f CFLAGS if [ $? -eq 0 ]; then if [ "$CC" = "gcc" ]; then check_compiler_flag "param ssp-buffer-size=1" - CFLAGS fi fi if [ $? -eq 0 ]; then echo "CPPFLAGS += -D_FORTIFY_SOURCE=2" >>$CONFIG_MK fi check_compiler_flag "visibility=default" f SHAREDLIB_CFLAGS if [ $? -eq 0 ]; then HAVE_VISIBILITY=yes echo "CPPFLAGS += -DHAVE_VISIBILITY=1" >>$CONFIG_MK echo "HAVE_VISIBILITY = 1" >>$CONFIG_MK fi # # Check for -Wl,--export-dynamic and if it fails, try -rdynamic. # check_compiler_flag "l,--export-dynamic" W LIBXBPS_LDFLAGS if [ $? -ne 0 ]; then check_compiler_flag dynamic r LIBXBPS_LDFLAGS fi # # Check for -Wl,-z,relro,-z,now check_compiler_flag "l,-z,relro,-z,now" W LDFLAGS # # Check if -fPIE and -pie are supported if --build-pie is set. # check_compiler_flag PIE f PROG_CFLAGS if [ $? -eq 0 ]; then check_compiler_flag pie "" PROG_LDFLAGS fi if [ $? -eq 0 ]; then BUILD_PIE_VALUE=yes else BUILD_PIE_VALUE=no fi # libfetch echo "CPPFLAGS += -I\$(TOPDIR)/lib/fetch" >>$CONFIG_MK echo "LDFLAGS += -lssl" >>$CONFIG_MK echo "STATIC_LIBS = \$(TOPDIR)/lib/libxbps.a" >>$CONFIG_MK # proplib echo "CPPFLAGS += -I\$(TOPDIR)/lib/portableproplib" >>$CONFIG_MK echo "CPPFLAGS += -I\$(TOPDIR)/lib/portableproplib/prop" >>$CONFIG_MK echo "LDFLAGS += -lpthread" >>$CONFIG_MK echo "STATIC_LIBS += -lpthread" >>$CONFIG_MK # # Check for vasprintf(). # func=vasprintf printf "Checking for $func() ... " cat <_$func.c #include int main(void) { vasprintf(NULL, NULL, NULL); return 0; } EOF if $XCC -D_GNU_SOURCE _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_VASPRINTF" >> $CONFIG_MK else echo no. echo "COMPAT_SRCS+= compat/vasprintf.o" >>$CONFIG_MK echo "#include \"compat.h\"" >>$CONFIG_H fi rm -f _$func.c _$func # # Check for strcasestr(). # func=strcasestr printf "Checking for $func() ... " cat <_$func.c #define _GNU_SOURCE #include int main(void) { const char *h = "NEEDCOFEE"; const char *n = "IneedCoffee"; strcasestr(n, h); return 0; } EOF if $XCC _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_STRCASESTR" >>$CONFIG_MK else echo no. echo "COMPAT_SRCS += compat/strcasestr.o" >>$CONFIG_MK echo "#include \"compat.h\"" >>$CONFIG_H fi rm -f _$func _$func.c # # Check for strlcpy(). # func=strlcpy printf "Checking for $func() ... " cat <_$func.c #include int main(void) { const char s1[] = "foo"; char s2[10]; strlcpy(s2, s1, sizeof(s2)); return 0; } EOF if $XCC _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_STRLCPY" >> $CONFIG_MK else echo no. echo "COMPAT_SRCS += compat/strlcpy.o" >>$CONFIG_MK echo "#include \"compat.h\"" >>$CONFIG_H fi rm -f _$func.c _$func # # Check for strlcat(). func=strlcat printf "Checking for $func() ... " cat < _$func.c #include int main(void) { const char src[] = "foo"; char dst[10]; strlcat(dst, src, sizeof(dst)); return 0; } EOF if $XCC _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_STRLCAT" >>$CONFIG_MK else echo no. echo "COMPAT_SRCS += compat/strlcat.o" >>$CONFIG_MK echo "#include \"compat.h\"" >>$CONFIG_H fi rm -f _$func.c _$func # # Check for humanize_number(). func=humanize_number printf "Checking for $func() ... " cat < _$func.c #include #include int main(void) { humanize_number(NULL, 0, 0, NULL, 0, 0); return 0; } EOF if $XCC -lutil _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS+= -DHAVE_HUMANIZE_NUMBER" >>$CONFIG_MK else echo no. echo "COMPAT_SRCS+= compat/humanize_number.o" >>$CONFIG_MK echo "#include \"compat.h\"" >>$CONFIG_H fi rm -f _$func.c _$func # # Check for rbtree_ininit(). # func=rb_tree_init printf "Checking for $func() ... " cat < _$func.c #include int main(void) { rb_tree_init(NULL, NULL); return 0; } EOF if $XCC _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_RBTREE" >>$CONFIG_MK else echo no. echo "LIBPROP_OBJS += portableproplib/rb.o" >>$CONFIG_MK fi rm -f _$func.c _$func # # Check for fdatasync(). # func=fdatasync printf "Checking for $func() ... " cat < _$func.c #include int main(void) { fdatasync(0); return 0; } EOF if $XCC _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_FDATASYNC" >>$CONFIG_MK else echo no. fi rm -f _$func.c _$func # # Check for clock_gettime(3). # func=clock_gettime printf "Checking for $func() ... " cat < _$func.c #include int main(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return 0; } EOF if $XCC -lrt _$func.c -o _$func 2>/dev/null; then echo yes. echo "CPPFLAGS += -DHAVE_CLOCK_GETTIME" >>$CONFIG_MK echo "LDFLAGS += -lrt" >>$CONFIG_MK echo "STATIC_LIBS += -lrt" >>$CONFIG_MK else echo no. fi rm -f _$func.c _$func # # zlib is required. # func=InflateInit2 printf "Checking for $func() ... " cat < _$func.c #include int main(void) { z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; inflateInit2(&strm, 15+16); return 0; } EOF if $XCC -lz _$func.c -o _$func 2>/dev/null; then echo yes. echo "LDFLAGS += -lz" >>$CONFIG_MK echo "STATIC_LIBS += -lz" >>$CONFIG_MK else ZLIB=no fi rm -f _$func.c _$func if [ "$ZLIB" = "no" ]; then echo "Failed to link with your system's zlib, can't continue..." exit 1 fi # # If building API library documentation, doxygen and graphviz are required. # if [ -n "$BUILD_API_DOCS" ]; then echo "Building API documentation via doxygen and graphviz." printf "Checking for doxygen ..." DOXYGEN_BIN=$(_which doxygen) if [ -z "$DOXYGEN_BIN" ]; then echo "not found, exiting." exit 1 else echo yes fi printf "Checking for graphviz ... " DOT_BIN=$(_which dot) if [ -z "$DOT_BIN" ]; then echo "dot(1) command not found, exiting." exit 1 else echo yes fi echo "BUILD_API_DOCS= yes" >> $CONFIG_MK BUILD_API_DOCS_VALUE=yes else BUILD_API_DOCS_VALUE=no fi # # pkg-config is required to know dependencies for static linking. # printf "Checking for pkg-config ... " PKGCONFIG_BIN=$(_which pkg-config) if [ -z "$PKGCONFIG_BIN" ]; then echo "not found, exiting." exit 1 else echo yes fi # # libarchive >= 2.8.0 with pkg-config support is required. # printf "Checking for libarchive >= 2.8.0 via pkg-config ... " if ! $PKGCONFIG_BIN --atleast-version=2.8.0 libarchive; then echo "libarchive.pc file not found, exiting." exit 1 else echo "found version $($PKGCONFIG_BIN --modversion libarchive)." echo "CFLAGS += $($PKGCONFIG_BIN --cflags libarchive)" >>$CONFIG_MK echo "LDFLAGS += $($PKGCONFIG_BIN --libs libarchive)" >>$CONFIG_MK echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libarchive)" \ >>$CONFIG_MK fi # # confuse >= 2.7 with pkg-config support is required. # printf "Checking for confuse via pkg-config ..." if ! $PKGCONFIG_BIN --exists libconfuse; then echo "libconfuse.pc not found, exiting." exit 1 else echo "found version $($PKGCONFIG_BIN --modversion libconfuse)." echo "CFLAGS += $($PKGCONFIG_BIN --cflags libconfuse)" >>$CONFIG_MK echo "LDFLAGS += $($PKGCONFIG_BIN --libs libconfuse)" >>$CONFIG_MK echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libconfuse)" \ >>$CONFIG_MK fi # # OpenSSL libssl with pkg-config support is required when building # the static binaries. # if [ "$BUILD_STATIC" = "yes" ]; then printf "Checking for OpenSSL via pkg-config ... " if ! $PKGCONFIG_BIN --exists libssl; then echo "libssl.pc file not found, exiting." exit 1 else echo "found version $($PKGCONFIG_BIN --modversion libssl)." echo "CFLAGS += $($PKGCONFIG_BIN --cflags libssl)" >>$CONFIG_MK echo "LDFLAGS += $($PKGCONFIG_BIN --libs libssl)" >>$CONFIG_MK echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libssl)" \ >>$CONFIG_MK fi else func=SHA256 printf "Checking for OpenSSL $func() ... " cat < _$func.c #include int main(void) { SHA256(NULL, NULL, 0); return 0; } EOF if $XCC -lcrypto _$func.c -o _$func 2>/dev/null; then echo yes. echo "LDFLAGS += -lcrypto" >>$CONFIG_MK else CRYPTO_SHA256=no fi rm -f _$func.c _$func if [ "$CRYPTO_SHA256" = "no" ]; then echo "Failed to link with your system's OpenSSL library, can't continue..." exit 1 fi fi # # If --with-static enabled, build static binaries. # if [ "$BUILD_STATIC" = "yes" ]; then echo "BUILD_STATIC = yes" >>$CONFIG_MK BUILD_STATIC_VALUE=yes else BUILD_STATIC_VALUE=no fi # # If --with-tests enabled, check for ATF >= 0.15 via pkg-config. # if [ "$BUILD_TESTS" = "yes" ]; then printf "Checking for ATF via pkg-config ... " if ! $PKGCONFIG_BIN --atleast-version=0.15 atf-c; then echo "ATF >= 0.15 not found in PKG_CONFIG_LIBDIR, exiting." exit 1 fi echo "found version $($PKGCONFIG_BIN --modversion atf-c)." echo "TEST_CFLAGS += $($PKGCONFIG_BIN --cflags atf-c)" >>$CONFIG_MK echo "TEST_LDFLAGS += $($PKGCONFIG_BIN --libs atf-c)" >>$CONFIG_MK echo "BUILD_TESTS = yes" >>$CONFIG_MK BUILD_TESTS_VALUE=yes else BUILD_TESTS_VALUE=no fi if [ -n "$SILENT" ]; then echo "SILENT = @" >>$CONFIG_MK else echo "SILENT =" >>$CONFIG_MK fi echo echo " XBPS has been configured with the following options:" echo echo " PREFIX = $PREFIX" echo " EPREFIX = $EPREFIX" echo " SBINDIR = $SBINDIR" echo " LIBDIR = $LIBDIR" echo " INCLUDEDIR = $INCLUDEDIR" echo " SHAREDIR = $SHAREDIR" echo " MANDIR = $MANDIR" echo " ETCDIR = $ETCDIR" if [ -n "$CFLAGS" ]; then echo " CFLAGS = $CFLAGS" fi if [ -n "$LDFLAGS" ]; then echo " LDFLAGS = $LDFLAGS" fi echo echo " Build API documentation = $BUILD_API_DOCS_VALUE" echo " Build Kyua test suite = $BUILD_TESTS_VALUE" echo " Build programs as PIE = $BUILD_PIE_VALUE" echo " Build static programs = $BUILD_STATIC_VALUE" echo " Build with debug = $DEBUG" if [ -n "$HAVE_VISIBILITY" ]; then echo " Symbol visibility = $HAVE_VISIBILITY" fi echo echo " You can now run make && make install clean." echo exit 0