diff options
| author | Jakob Kaivo <jkk@ung.org> | 2019-02-23 19:11:08 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2019-02-23 19:11:08 -0500 |
| commit | 6ea8e22adb6132a1087b97f33fce7d4ab6ffbcd2 (patch) | |
| tree | e88c6e73d4aecb51f5f6faeb14dfca35deb3e1b8 | |
| parent | 97c618077e99f4bf02d9e7016f45d036e616b5d8 (diff) | |
new configure script to replace manually editing config.mk
| -rw-r--r-- | Makefile | 35 | ||||
| -rw-r--r-- | config.mk | 10 | ||||
| -rw-r--r-- | config/architecture | 1 | ||||
| -rw-r--r-- | config/c | 5 | ||||
| -rw-r--r-- | config/posix | 6 | ||||
| -rw-r--r-- | config/wordsize | 2 | ||||
| -rw-r--r-- | config/xopen | 5 | ||||
| -rwxr-xr-x | configure | 128 |
8 files changed, 125 insertions, 67 deletions
@@ -1,10 +1,18 @@ .POSIX: -.DEFAULT:; $(MAKE) all -.SILENT: all headers include -include config.mk +.DEFAULT:;$(MAKE) all + +ARCHITECTURE=x86 +WORDSIZE= +SRCDIR=./src +INCDIR=./include +OBJDIR=/home/jkk/c/obj + +CC=c99 +CFLAGS=-D_XOPEN_SOURCE=700 all: .deps.mk include - $(MAKE) -f .deps.mk $@ + @mkdir -p $(OBJDIR) + $(MAKE) -f .deps.mk deps: .headers.mk .deps.mk @@ -20,25 +28,6 @@ headers include: .headers.mk mkh.sh ctags: ctags $$(find src -name \*.c) -C_1: .deps.mk ; $(MAKE) -f .deps.mk $@ -C_199409: C_1 ; $(MAKE) -f .deps.mk $@ -C_199901: C_199409 ; $(MAKE) -f .deps.mk $@ -C_201112: C_199901 ; $(MAKE) -f .deps.mk $@ -C_201710: C_201112 ; $(MAKE) -f .deps.mk $@ - -POSIX_1: C_1 ; $(MAKE) -f .deps.mk $@ -POSIX_2: POSIX_1 ; $(MAKE) -f .deps.mk $@ -POSIX_199309: POSIX_1 ; $(MAKE) -f .deps.mk $@ -POSIX_199506: POSIX_199309 ; $(MAKE) -f .deps.mk $@ -POSIX_200112: POSIX_199506 C_199901 ; $(MAKE) -f .deps.mk $@ -POSIX_200809: POSIX_200112 ; $(MAKE) -f .deps.mk $@ - -XOPEN_4: POSIX_2 POSIX_1 ; $(MAKE) -f .deps.mk $@ -XOPEN_400: XOPEN_4 ; $(MAKE) -f .deps.mk $@ -XOPEN_500: XOPEN_400 POSIX_199506 ; $(MAKE) -f .deps.mk $@ -XOPEN_600: XOPEN_500 POSIX_200112 ; $(MAKE) -f .deps.mk $@ -XOPEN_700: XOPEN_600 POSIX_200809 ; $(MAKE) -f .deps.mk $@ - clean: rm -rf $(OBJDIR) *.a diff --git a/config.mk b/config.mk deleted file mode 100644 index cb62aa6f..00000000 --- a/config.mk +++ /dev/null @@ -1,10 +0,0 @@ -.POSIX: - -SRCDIR=src -OBJDIR=obj -INCDIR=include -ARCH=x86 -WORDSIZE=64 - -CC=c99 -CFLAGS=-DNDEBUG diff --git a/config/architecture b/config/architecture new file mode 100644 index 00000000..e41c7a05 --- /dev/null +++ b/config/architecture @@ -0,0 +1 @@ +x86 Intel x86 diff --git a/config/c b/config/c new file mode 100644 index 00000000..5e7740a9 --- /dev/null +++ b/config/c @@ -0,0 +1,5 @@ +1 ISO/IEC 9899:1990, AKA ANSI X3.159-1989, ANSI C, ISO C, C89, C90 +199409 ISO/IEC 9899:1990/AMD1:1995, AKA C94, C95 +199901 ISO/IEC 9899:1999, AKA C99 +201112 ISO/IEC 9899:2011, AKA C11 +201710 ISO/IEC 9899:2018, AKA C18 diff --git a/config/posix b/config/posix new file mode 100644 index 00000000..415a0458 --- /dev/null +++ b/config/posix @@ -0,0 +1,6 @@ +1 POSIX.1-1990 (includes POSIX.1-1988, implies C89) +2 POSIX.1-1990 plus POSIX.2-1992 +199309 POSIX.1b-1993 (includes POSIX.1-1990) +199506 POSIX.1-1996 +200112 POSIX.1-2001 (implies C99) +200809 POSIX.1-2008 (implies C99) diff --git a/config/wordsize b/config/wordsize new file mode 100644 index 00000000..08fdc23a --- /dev/null +++ b/config/wordsize @@ -0,0 +1,2 @@ +32 32-bit +64 64-bit diff --git a/config/xopen b/config/xopen new file mode 100644 index 00000000..32748b73 --- /dev/null +++ b/config/xopen @@ -0,0 +1,5 @@ +400 Single Unix Specification, version 1 + (includes POSIX.1-1990 and POSIX.2-1992) +500 Single Unix Specification, version 2 (includes POSIX.1-1995) +600 Single Unix Specification, version 3 (includes POSIX.1-2001) +700 Single Unix Specification, version 4 (includes POSIX.1-2008) @@ -1,67 +1,68 @@ #!/bin/sh +set -e + CONFIGDIR="$(dirname $0)/config" show_help() { cat <<-EOF - usage: ./configure [-c version] [-p version | -x version] + usage: ./configure [options...] Options: - -c version Specify the version of ISO/IEC 9899 to conform to - -p version Specify the version of IEEE 1003.1/ISO/IED 9945-1 to - conform to - -x version Specify the version of the Single Unix Specification - (aka X/Open System Interface) to conform to + -a arch Choose the underlying architecture to build for: + $(awk '{ printf("\t%s\n", $0); }' ${CONFIGDIR}/architecture) + + -c version Conform to: + $(awk '{ printf("\t%s\n", $0); }' ${CONFIGDIR}/versions.c) - Valid options for -c are: - $(cat ${CONFIGDIR}/versions.c) + -p version Conform to: + $(awk '{ printf("\t%s\n", $0); }' ${CONFIGDIR}/versions.posix) - Valid options for -p are: - $(cat ${CONFIGDIR}/versions.posix) + -w wordsize Choose a word size for the architecuture: + $(awk '{ printf("\t%s\n", $0); }' ${CONFIGDIR}/wordsize) + + -x version Conform to: + $(awk '{ printf("\t%s\n", $0); }' ${CONFIGDIR}/versions.xopen) - Valid options for -x are: - $(cat ${CONFIGDIR}/versions.xopen) EOF } -validate_version() { - versfile="${CONFIGDIR}/versions.$1" +validate_option() { + option="${CONFIGDIR}/$1" - for ver in $(awk '/^[0-9]/ { print $1 }' "${versfile}"); do - if [ "$2" = "${ver}" ]; then - echo $2 + for opt in $(awk '/^[0-9]/ { print $1 }' "${option}"); do + if [ "$2" = "${opt}" ]; then + echo "$2" return 0 fi done - echo 0 -} - -double_check_version() { - if [ "$2" = "0" ]; then - printf 'Invalid version "%s". Valid versions are:\n' $3 - cat "${CONFIGDIR}/versions.$1" - exit 1 - fi + printf 'Invalid option '%s'. Valid options are:\n' "$2" >&2 + cat "${option}" >&2 + exit 1 } option= + +architecture=x86 +wordsize=64 + standard_c= posix= xopen= while getopts hc:p:x: option; do case ${option} in - c) standard_c=$(validate_version c ${OPTARG}) - double_check_version c ${standard_c} ${OPTARG} + a) architecture=$(validate_option architecture ${OPTARG}) + ;; + + c) standard_c=$(validate_option c ${OPTARG}) ;; - p) posix=$(validate_version posix ${OPTARG}) - double_check_version posix ${posix} ${OPTARG} + p) posix=$(validate_option posix ${OPTARG}) ;; - x) xopen=$(validate_version xopen ${OPTARG}) - double_check_version xopen ${xopen} ${OPTARG} + x) xopen=$(validate_option xopen ${OPTARG}) ;; h) show_help @@ -108,7 +109,66 @@ if [ ${posix:-0} -ge 200112 ] && [ $standard_c -lt 199901 ]; then exit 1 fi +printf 'C library configured to conform to the following standards:\n' printf 'ISO C: %d\n' ${standard_c} -printf 'POSIX: %d\n' ${posix} -printf 'X/OPEN: %d\n' ${xopen} +test -n "${posix}" && printf 'POSIX: %d\n' ${posix} +test -n "${xopen}" && printf 'X/OPEN: %d\n' ${xopen} + +printf 'Building for %d-bit %s architecture\n' "${wordsize}" "${architecture}" + +exec > Makefile + +cat <<-EOF + .POSIX: + .DEFAULT:;\$(MAKE) all + + ARCHITECTURE=${architecture} + WORDSIZE=${WORDSIZE} + SRCDIR=$(dirname $0)/src + INCDIR=$(dirname $0)/include + OBJDIR=$(pwd)/obj + +EOF + +if [ ${standard_c:-1} -lt 199901 ]; then + printf 'CC=c89\n' +else + printf 'CC=c%02d\n' $(( (standard_c / 100) % 100 )) +fi + +if [ -n "${xopen}" ]; then + if [ $xopen -eq 400 ]; then + printf 'CFLAGS=-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1\n' + else + printf 'CFLAGS=-D_XOPEN_SOURCE=%d\n' "${xopen}" + fi +elif [ -n "${posix}" ]; then + printf 'CFLAGS=-D_POSIX_C_SOURCE=%d\n' "${posix}" +fi + +cat <<EOF + +all: .deps.mk include + @mkdir -p \$(OBJDIR) + \$(MAKE) -f .deps.mk $@ + +deps: .headers.mk .deps.mk + +.deps.mk: mk.sh + sh -c '. ./mk.sh; make_deps_mk' + +.headers.mk: mk.sh + sh -c '. ./mk.sh; make_headers_mk' + +headers include: .headers.mk mkh.sh + \$(MAKE) -f .headers.mk headers + +ctags: + ctags \$\$(find src -name \*.c) + +clean: + rm -rf \$(OBJDIR) *.a +extra-clean: clean + rm -rf .deps .*.mk \$(INCDIR) +EOF |
