Provide a better ./configure script

This commit is contained in:
XANTRONIX Development 2020-09-22 10:12:30 -05:00
parent c676a32460
commit 9d2e42dab2

207
configure vendored
View file

@ -2,51 +2,89 @@
OS=`uname -s` OS=`uname -s`
DEBUG=0 DEBUG=0
PREFIX=/usr/local
create_linux_config_h() { config_h_append_generic_endian() {
cat <<EOF > src/config.h cat <<EOF >> "$1"
#ifndef _CONFIG_H
#define _CONFIG_H /*
* Generic compatibility
*/
#include <endian.h> #include <endian.h>
#endif /* _CONFIG_H */
EOF EOF
} }
create_darwin_config_h() { config_h_append_darwin_endian() {
cat <<EOF > src/config.h cat <<EOF >> "$1"
/*
* Darwin compatibility
*/
#include <libkern/OSByteOrder.h>
#define htobe16(n) OSSwapHostToBigInt16(n)
#define htole16(n) OSSwapHostToLittleInt16(n)
#define be16toh(n) OSSwapBigToHostInt16(n)
#define le16toh(n) OSSwapLittleToHostInt16(n)
#define htobe32(n) OSSwapHostToBigInt32(n)
#define htole32(n) OSSwapHostToLittleInt32(n)
#define be32toh(n) OSSwapBigToHostInt32(n)
#define le32toh(n) OSSwapLittleToHostInt32(n)
#define htobe64(n) OSSwapHostToBigInt64(n)
#define htole64(n) OSSwapHostToLittleInt64(n)
#define be64toh(n) OSSwapBigToHostInt64(n)
#define le64toh(n) OSSwapLittleToHostInt64(n)
EOF
}
config_h_append_bsd_pty() {
cat <<EOF >> "$1"
/*
* BSD openpty(3) compatibility
*/
#include <util.h>
EOF
}
config_h_append_linux_pty() {
cat <<EOF >> "$1"
/*
* Linux openpty(3) compatibility
*/
#include <pty.h>
EOF
}
config_h_create() {
cat <<EOF > "$1"
#ifndef _CONFIG_H #ifndef _CONFIG_H
#define _CONFIG_H #define _CONFIG_H
#include <architecture/byte_order.h> EOF
#ifdef __LITTLE_ENDIAN__ if [ "$OS" = "Darwin" ]; then
#define __DO_SWAP_BYTES config_h_append_darwin_endian "$1"
#endif /* _DO_SWAP_BYTES */ else
#endif /* _CONFIG_H */ config_h_append_generic_endian "$1"
EOF
}
create_common_build_mk() {
if [ "$DEBUG" = 1 ]; then
cat <<'EOF' > mk/build.mk
CGFLAGS = -g -fno-inline
EOF
else
cat <<'EOF' > mk/build.mk
CGFLAGS =
EOF
fi fi
cat <<'EOF' >> mk/build.mk if [ "$OS" = "Linux" ]; then
CWFLAGS = -Wall config_h_append_linux_pty "$1"
COFLAGS = -O2 else
CFLAGS = $(CGFLAGS) $(CWFLAGS) $(COFLAGS) config_h_append_bsd_pty "$1"
fi
cat <<EOF >> "$1"
#endif /* _CONFIG_H */
EOF EOF
} }
create_linux_build_mk() { build_mk_append_generic() {
create_common_build_mk $@ cat <<'EOF' >> "$1"
cat <<'EOF' >> mk/build.mk
LLFLAGS = -shared -Wl,-soname=$(SONAME) LLFLAGS = -shared -Wl,-soname=$(SONAME)
STATIC = lib$(LIBNAME).a STATIC = lib$(LIBNAME).a
@ -55,14 +93,33 @@ SONAME_SHORT = lib$(LIBNAME).so
SONAME = $(SONAME_SHORT).$(VERSION_MAJOR) SONAME = $(SONAME_SHORT).$(VERSION_MAJOR)
SONAME_FULL = $(SONAME_SHORT).$(VERSION) SONAME_FULL = $(SONAME_SHORT).$(VERSION)
PREFIX = /usr/local EOF
cat <<EOF >> "$1"
PREFIX = $PREFIX
EOF EOF
} }
create_darwin_build_mk() { build_mk_append_man_generic() {
create_common_build_mk $@ cat <<'EOF' >> "$1"
MANDIR = $(PREFIX)/share/man
EOF
}
cat <<'EOF' >> mk/build.mk build_mk_append_man_bsd() {
if [ "$PREFIX" = "/usr" ]; then
local mandir='$(PREFIX)/share/man'
else
local mandir='$(PREFIX)/man'
fi
cat <<EOF >> "$1"
MANDIR = $mandir
EOF
}
build_mk_append_darwin() {
cat <<'EOF' >> "$1"
LLFLAGS = -dynamiclib -current_version $(VERSION) LLFLAGS = -dynamiclib -current_version $(VERSION)
STATIC = lib$(LIBNAME).a STATIC = lib$(LIBNAME).a
@ -71,15 +128,76 @@ SONAME_SHORT = lib$(LIBNAME).dylib
SONAME = lib$(LIBNAME).$(VERSION_MAJOR).dylib SONAME = lib$(LIBNAME).$(VERSION_MAJOR).dylib
SONAME_FULL = lib$(LIBNAME).$(VERSION).dylib SONAME_FULL = lib$(LIBNAME).$(VERSION).dylib
PREFIX = /usr/local
EOF EOF
cat <<EOF >> "$1"
PREFIX = $PREFIX
EOF
}
build_mk_create() {
if [ "$DEBUG" = 1 ]; then
cat <<'EOF' > "$1"
CGFLAGS = -g -fno-inline
EOF
else
cat <<'EOF' > "$1"
CGFLAGS =
EOF
fi
if [ "$OS" = "Darwin" ]; then
build_mk_append_darwin "$1"
else
build_mk_append_generic "$1"
fi
case $OS in
FreeBSD|NetBSD|OpenBSD)
build_mk_append_man_bsd "$1"
;;
*)
build_mk_append_man_generic "$1"
;;
esac
cat <<'EOF' >> "$1"
CWFLAGS = -Wall
COFLAGS = -O2
CFLAGS = $(CGFLAGS) $(CWFLAGS) $(COFLAGS)
AR = $(CROSS)ar
RANLIB = $(CROSS)ranlib
RM = /bin/rm
LN = /bin/ln
RMDIR = /bin/rmdir
INSTALL = /usr/bin/install
EOF
}
parse_opt() {
local _IFS="$IFS"
IFS="="
set -- $1
echo $2
IFS="$_IFS"
} }
for arg in $@; do for arg in $@; do
case $arg in case $arg in
"--enable-debug") --enable-debug)
DEBUG=1 DEBUG=1
;; ;;
--prefix=*)
PREFIX="`parse_opt "$arg"`"
;;
esac esac
done done
@ -87,14 +205,5 @@ if [ ! -d "mk" ]; then
mkdir -m 0755 mk mkdir -m 0755 mk
fi fi
case $OS in config_h_create "src/config.h"
Linux) build_mk_create "mk/build.mk"
create_linux_config_h
create_linux_build_mk
;;
Darwin)
create_darwin_config_h
create_darwin_build_mk
;;
esac