forked from github/abduco
Add configure script to detect compiler flags and feature test macros
This is the same musl originated configure script as vis uses.
This commit is contained in:
parent
1f1c02a3b0
commit
66a17ed03d
46
Makefile
46
Makefile
|
|
@ -1,45 +1,37 @@
|
||||||
include config.mk
|
-include config.mk
|
||||||
|
|
||||||
|
VERSION = 0.6
|
||||||
|
|
||||||
|
CFLAGS_STD ?= -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG
|
||||||
|
CFLAGS_STD += -DVERSION=\"${VERSION}\"
|
||||||
|
|
||||||
|
LDFLAGS_STD ?= -lc -lutil
|
||||||
|
|
||||||
|
STRIP ?= strip
|
||||||
|
|
||||||
SRC = abduco.c
|
SRC = abduco.c
|
||||||
OBJ = ${SRC:.c=.o}
|
|
||||||
|
|
||||||
all: clean options abduco
|
all: abduco
|
||||||
|
|
||||||
options:
|
|
||||||
@echo abduco build options:
|
|
||||||
@echo "CFLAGS = ${CFLAGS}"
|
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
|
||||||
@echo "CC = ${CC}"
|
|
||||||
|
|
||||||
config.h:
|
config.h:
|
||||||
cp config.def.h config.h
|
cp config.def.h config.h
|
||||||
|
|
||||||
.c.o:
|
config.mk:
|
||||||
@echo CC $<
|
@touch $@
|
||||||
@${CC} -c ${CFLAGS} $<
|
|
||||||
|
|
||||||
${OBJ}: config.h config.mk
|
abduco: config.h config.mk *.c
|
||||||
|
${CC} ${CFLAGS} ${CFLAGS_STD} ${CFLAGS_AUTO} ${CFLAGS_EXTRA} ${SRC} ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
|
||||||
abduco: ${OBJ}
|
|
||||||
@echo CC -o $@
|
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
|
||||||
|
|
||||||
debug: clean
|
debug: clean
|
||||||
@make CFLAGS='${DEBUG_CFLAGS}'
|
make CFLAGS_EXTRA='${CFLAGS_DEBUG}'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
@rm -f abduco ${OBJ} abduco-${VERSION}.tar.gz
|
@rm -f abduco abduco-*.tar.gz
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
@echo creating dist tarball
|
||||||
@mkdir -p abduco-${VERSION}
|
@git archive --prefix=abduco-${VERSION}/ -o abduco-${VERSION}.tar.gz HEAD
|
||||||
@cp -R LICENSE Makefile README.md testsuite.sh config.def.h config.mk \
|
|
||||||
${SRC} debug.c client.c server.c forkpty-aix.c forkpty-sunos.c \
|
|
||||||
abduco.1 abduco-${VERSION}
|
|
||||||
@tar -cf abduco-${VERSION}.tar abduco-${VERSION}
|
|
||||||
@gzip abduco-${VERSION}.tar
|
|
||||||
@rm -rf abduco-${VERSION}
|
|
||||||
|
|
||||||
install: abduco
|
install: abduco
|
||||||
@echo stripping executable
|
@echo stripping executable
|
||||||
|
|
@ -59,4 +51,4 @@ uninstall:
|
||||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
@rm -f ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
||||||
|
|
||||||
.PHONY: all options clean dist install uninstall debug
|
.PHONY: all clean dist install uninstall debug
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ with sha1sum
|
||||||
|
|
||||||
compile and install it
|
compile and install it
|
||||||
|
|
||||||
$EDITOR config.mk && make && sudo make install
|
./configure && make && sudo make install
|
||||||
|
|
||||||
or use one of the distribution provided binary packages:
|
or use one of the distribution provided binary packages:
|
||||||
|
|
||||||
|
|
|
||||||
19
config.mk
19
config.mk
|
|
@ -1,19 +0,0 @@
|
||||||
# abduco version
|
|
||||||
VERSION = 0.6
|
|
||||||
|
|
||||||
# Customize below to fit your system
|
|
||||||
|
|
||||||
PREFIX ?= /usr/local
|
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
|
||||||
|
|
||||||
INCS = -I.
|
|
||||||
LIBS = -lc -lutil
|
|
||||||
|
|
||||||
CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
|
|
||||||
CFLAGS += -std=c99 -pedantic -Wall ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG ${CPPFLAGS}
|
|
||||||
LDFLAGS += ${LIBS}
|
|
||||||
|
|
||||||
DEBUG_CFLAGS = ${CFLAGS} -UNDEBUG -O0 -g -ggdb
|
|
||||||
|
|
||||||
CC ?= cc
|
|
||||||
STRIP ?= strip
|
|
||||||
|
|
@ -0,0 +1,244 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Based on the configure script from musl libc, MIT licensed
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
|
To assign environment variables (e.g., CC, CFLAGS...), specify them as
|
||||||
|
VAR=VALUE. See below for descriptions of some of the useful variables.
|
||||||
|
|
||||||
|
Defaults for the options are specified in brackets.
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
--srcdir=DIR source directory [detected]
|
||||||
|
|
||||||
|
Installation directories:
|
||||||
|
--prefix=PREFIX main installation prefix [/usr/local]
|
||||||
|
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
|
||||||
|
|
||||||
|
Fine tuning of the installation directories:
|
||||||
|
--bindir=DIR user executables [EPREFIX/bin]
|
||||||
|
--sharedir=DIR share directories [PREFIX/share]
|
||||||
|
--docdir=DIR misc. documentation [PREFIX/share/doc]
|
||||||
|
--mandir=DIR man pages [PREFIX/share/man]
|
||||||
|
|
||||||
|
Some influential environment variables:
|
||||||
|
CC C compiler command [detected]
|
||||||
|
CFLAGS C compiler flags [-Os -pipe ...]
|
||||||
|
LDFLAGS Linker flags
|
||||||
|
|
||||||
|
Use these variables to override the choices made by configure.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
|
||||||
|
quote () {
|
||||||
|
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
|
||||||
|
$1
|
||||||
|
EOF
|
||||||
|
printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
|
||||||
|
}
|
||||||
|
echo () { printf "%s\n" "$*" ; }
|
||||||
|
fail () { echo "$*" ; exit 1 ; }
|
||||||
|
fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
|
||||||
|
cmdexists () { type "$1" >/dev/null 2>&1 ; }
|
||||||
|
trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
|
||||||
|
|
||||||
|
stripdir () {
|
||||||
|
while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
|
||||||
|
}
|
||||||
|
|
||||||
|
trycppif () {
|
||||||
|
printf "checking preprocessor condition %s... " "$1"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
echo "#if $1" >> "$tmpc"
|
||||||
|
echo "#error yes" >> "$tmpc"
|
||||||
|
echo "#endif" >> "$tmpc"
|
||||||
|
if $CC $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "false\n"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
printf "true\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
tryflag () {
|
||||||
|
printf "checking whether compiler accepts %s... " "$2"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "yes\n"
|
||||||
|
eval "$1=\"\${$1} \$2\""
|
||||||
|
eval "$1=\${$1# }"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
printf "no\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
tryldflag () {
|
||||||
|
printf "checking whether linker accepts %s... " "$2"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "yes\n"
|
||||||
|
eval "$1=\"\${$1} \$2\""
|
||||||
|
eval "$1=\${$1# }"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
printf "no\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Beginning of actual script
|
||||||
|
|
||||||
|
CFLAGS_AUTO=
|
||||||
|
CFLAGS_TRY=
|
||||||
|
LDFLAGS_AUTO=
|
||||||
|
LDFLAGS_TRY=
|
||||||
|
SRCDIR=
|
||||||
|
PREFIX=/usr/local
|
||||||
|
EXEC_PREFIX='$(PREFIX)'
|
||||||
|
BINDIR='$(EXEC_PREFIX)/bin'
|
||||||
|
MANDIR='$(PREFIX)/share/man'
|
||||||
|
|
||||||
|
for arg ; do
|
||||||
|
case "$arg" in
|
||||||
|
--help|-h) usage ;;
|
||||||
|
--srcdir=*) SRCDIR=${arg#*=} ;;
|
||||||
|
--prefix=*) PREFIX=${arg#*=} ;;
|
||||||
|
--exec-prefix=*) EXEC_PREFIX=${arg#*=} ;;
|
||||||
|
--bindir=*) BINDIR=${arg#*=} ;;
|
||||||
|
--sharedir=*) SHAREDIR=${arg#*=} ;;
|
||||||
|
--docdir=*) DOCDIR=${arg#*=} ;;
|
||||||
|
--mandir=*) MANDIR=${arg#*=} ;;
|
||||||
|
--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
|
||||||
|
-* ) echo "$0: unknown option $arg" ;;
|
||||||
|
CC=*) CC=${arg#*=} ;;
|
||||||
|
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
||||||
|
CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
|
||||||
|
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
||||||
|
*=*) ;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in SRCDIR PREFIX EXEC_PREFIX BINDIR MANDIR ; do
|
||||||
|
stripdir $i
|
||||||
|
done
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get the source dir for out-of-tree builds
|
||||||
|
#
|
||||||
|
if test -z "$SRCDIR" ; then
|
||||||
|
SRCDIR="${0%/configure}"
|
||||||
|
stripdir SRCDIR
|
||||||
|
fi
|
||||||
|
abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
|
||||||
|
abs_srcdir="$(cd $SRCDIR && pwd)" || fail "$0: invalid source directory $SRCDIR"
|
||||||
|
test "$abs_srcdir" = "$abs_builddir" && SRCDIR=.
|
||||||
|
test "$SRCDIR" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get a temp filename we can use
|
||||||
|
#
|
||||||
|
i=0
|
||||||
|
set -C
|
||||||
|
while : ; do i=$(($i+1))
|
||||||
|
tmpc="./conf$$-$PPID-$i.c"
|
||||||
|
tmpo="./conf$$-$PPID-$i.o"
|
||||||
|
2>|/dev/null > "$tmpc" && break
|
||||||
|
test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
|
||||||
|
done
|
||||||
|
set +C
|
||||||
|
trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
|
||||||
|
|
||||||
|
#
|
||||||
|
# Find a C compiler to use
|
||||||
|
#
|
||||||
|
printf "checking for C compiler... "
|
||||||
|
trycc cc
|
||||||
|
trycc gcc
|
||||||
|
trycc clang
|
||||||
|
printf "%s\n" "$CC"
|
||||||
|
test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
|
||||||
|
|
||||||
|
printf "checking whether C compiler works... "
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if output=$($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
|
||||||
|
printf "yes\n"
|
||||||
|
else
|
||||||
|
printf "no; compiler output follows:\n%s\n" "$output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Figure out options to force errors on unknown flags.
|
||||||
|
#
|
||||||
|
tryflag CFLAGS_TRY -Werror=unknown-warning-option
|
||||||
|
tryflag CFLAGS_TRY -Werror=unused-command-line-argument
|
||||||
|
tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
|
||||||
|
tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
|
||||||
|
|
||||||
|
CFLAGS_STD="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
|
||||||
|
LDFLAGS_STD="-lc -lutil"
|
||||||
|
|
||||||
|
OS=$(uname)
|
||||||
|
|
||||||
|
case "$OS" in
|
||||||
|
FreeBSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
|
||||||
|
*BSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE" ;;
|
||||||
|
Darwin) CFLAGS_STD="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
|
||||||
|
AIX) CFLAGS_STD="$CFLAGS_STD -D_ALL_SOURCE" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
tryflag CFLAGS -pipe
|
||||||
|
|
||||||
|
# Try flags to optimize binary size
|
||||||
|
tryflag CFLAGS -Os
|
||||||
|
tryflag CFLAGS -ffunction-sections
|
||||||
|
tryflag CFLAGS -fdata-sections
|
||||||
|
tryldflag LDFLAGS_AUTO -Wl,--gc-sections
|
||||||
|
|
||||||
|
# Try hardening flags
|
||||||
|
tryflag CFLAGS -fPIE
|
||||||
|
tryflag CFLAGS_AUTO -fstack-protector-all
|
||||||
|
tryldflag LDFLAGS -Wl,-z,now
|
||||||
|
tryldflag LDFLAGS -Wl,-z,relro
|
||||||
|
tryldflag LDFLAGS_AUTO -pie
|
||||||
|
|
||||||
|
printf "creating config.mk... "
|
||||||
|
|
||||||
|
cmdline=$(quote "$0")
|
||||||
|
for i ; do cmdline="$cmdline $(quote "$i")" ; done
|
||||||
|
|
||||||
|
exec 3>&1 1>config.mk
|
||||||
|
|
||||||
|
cat << EOF
|
||||||
|
# This version of config.mk was generated by:
|
||||||
|
# $cmdline
|
||||||
|
# Any changes made here will be lost if configure is re-run
|
||||||
|
SRCDIR = $SRCDIR
|
||||||
|
PREFIX = $PREFIX
|
||||||
|
EXEC_PREFIX = $EXEC_PREFIX
|
||||||
|
BINDIR = $BINDIR
|
||||||
|
MANPREFIX = $MANDIR
|
||||||
|
CC = $CC
|
||||||
|
CFLAGS = $CFLAGS
|
||||||
|
LDFLAGS = $LDFLAGS
|
||||||
|
CFLAGS_STD = $CFLAGS_STD
|
||||||
|
LDFLAGS_STD = $LDFLAGS_STD
|
||||||
|
CFLAGS_AUTO = $CFLAGS_AUTO
|
||||||
|
LDFLAGS_AUTO = $LDFLAGS_AUTO
|
||||||
|
CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-sign-compare
|
||||||
|
EOF
|
||||||
|
exec 1>&3 3>&-
|
||||||
|
|
||||||
|
printf "done\n"
|
||||||
|
|
||||||
|
test "$SRCDIR" = "." || ln -sf $SRCDIR/Makefile .
|
||||||
Loading…
Reference in New Issue