Improved portability in ./configure to add detection for various smaller items, such as headers necessary for openpty(3), et cetera; improve overall script structure
159 lines
2.7 KiB
Bash
Executable file
159 lines
2.7 KiB
Bash
Executable file
#! /bin/sh
|
|
|
|
OS=`uname -s`
|
|
DEBUG=0
|
|
PREFIX=/usr/local
|
|
|
|
config_h_append_generic_endian() {
|
|
cat <<EOF >> "$1"
|
|
|
|
/*
|
|
* Generic compatibility
|
|
*/
|
|
#include <endian.h>
|
|
EOF
|
|
}
|
|
|
|
config_h_append_darwin_endian() {
|
|
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
|
|
#define _CONFIG_H
|
|
EOF
|
|
|
|
if [ "$OS" = "Darwin" ]; then
|
|
config_h_append_darwin_endian "$1"
|
|
else
|
|
config_h_append_generic_endian "$1"
|
|
fi
|
|
|
|
if [ "$OS" = "Linux" ]; then
|
|
config_h_append_linux_pty "$1"
|
|
else
|
|
config_h_append_bsd_pty "$1"
|
|
fi
|
|
|
|
cat <<EOF >> "$1"
|
|
|
|
#endif /* _CONFIG_H */
|
|
EOF
|
|
}
|
|
|
|
build_mk_append_generic() {
|
|
cat <<'EOF' >> "$1"
|
|
LLFLAGS = -shared -Wl,-soname=$(SONAME)
|
|
|
|
STATIC = lib$(LIBNAME).a
|
|
|
|
SONAME_SHORT = lib$(LIBNAME).so
|
|
SONAME = $(SONAME_SHORT).$(VERSION_MAJOR)
|
|
SONAME_FULL = $(SONAME_SHORT).$(VERSION)
|
|
|
|
EOF
|
|
|
|
cat <<EOF >> mk/build.mk
|
|
PREFIX = $PREFIX
|
|
EOF
|
|
}
|
|
|
|
build_mk_append_darwin() {
|
|
build_mk_create_common $@
|
|
|
|
cat <<'EOF' >> mk/build.mk
|
|
LLFLAGS = -dynamiclib -current_version $(VERSION)
|
|
|
|
STATIC = lib$(LIBNAME).a
|
|
|
|
SONAME_SHORT = lib$(LIBNAME).dylib
|
|
SONAME = lib$(LIBNAME).$(VERSION_MAJOR).dylib
|
|
SONAME_FULL = lib$(LIBNAME).$(VERSION).dylib
|
|
|
|
EOF
|
|
|
|
cat <<EOF >> mk/build.mk
|
|
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
|
|
|
|
cat <<'EOF' >> mk/build.mk
|
|
CWFLAGS = -Wall
|
|
COFLAGS = -O2
|
|
CFLAGS = $(CGFLAGS) $(CWFLAGS) $(COFLAGS)
|
|
EOF
|
|
}
|
|
|
|
for arg in $@; do
|
|
case $arg in
|
|
"--enable-debug")
|
|
DEBUG=1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ ! -d "mk" ]; then
|
|
mkdir -m 0755 mk
|
|
fi
|
|
|
|
config_h_create "src/config.h"
|
|
build_mk_create "src/build.mk"
|