From 751fca09e1a8b48b21cdaf552c19be9cb8a01a4c Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 25 Jan 2024 21:12:12 +1300 Subject: [PATCH] switch to modular configure-based buildsystem --- .gitignore | 1 + Makefile | 13 +++---- README.md | 1 + configure | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index 69f4dfa..e973dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ luac *.o *.so +config.mk include/ diff --git a/Makefile b/Makefile index de4c59d..0ec102e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,11 @@ +include config.mk + PREFIX = /usr/local MANPREFIX = ${PREFIX}/man -CC = cc -CFLAGS = -std=c99 -pedantic -fpic -O2 -Iexternal/lua -Wall -Wextra -CPPFLAGS = -D_DEFAULT_SOURCE -LDFLAGS = -lm - -# Enable readline -#CPPFLAGS += -DLUA_USE_READLINE -#LDFLAGS += -lreadline +CC = ${_CC} +CFLAGS = -std=c99 ${_CFLAGS} -pedantic -Iexternal/lua -Wall -Wextra -D_DEFAULT_SOURCE +LDFLAGS = -lm ${_LDFLAGS} OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o lprocess.o util.o LIBS = libcallisto.a liblua.a diff --git a/README.md b/README.md index a11c70b..debb754 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Untar it then enter the directory with Callisto's source code. After that, run + ./configure make to compile Callisto and all its dependencies. diff --git a/configure b/configure new file mode 100755 index 0000000..f2e23fc --- /dev/null +++ b/configure @@ -0,0 +1,112 @@ +#!/usr/bin/env sh +# simple and flexible configure script for people who don't like to waste time +# licensed to the public domain + +set -e + +mkf=config.mk + +# utility functions + +present () { + command -v "$1" 1>/dev/null 2>/dev/null +} +using () { + printf "using $1\n" +} +error () { + >&2 printf "$(basename $0): $1\n" + exit 1 +} + +# generators + +## C compiler +gen_CC () { + if ! [ -z "$cc" ]; then + using "$cc" + return 0 + fi + if present clang; then + cc=clang + elif present cc; then + cc=cc + elif present gcc; then + cc=gcc + else + error "C compiler not found, please acquire a copy of LLVM Clang or the GNU C compiler" + fi + + using "$cc" +} + +## flags used in the compilation step +gen_CFLAGS () { + if [ -z "$debug" ]; then + cflags="-O2" + else + cflags="-O0 -g" + fi + + for flag in $cflags; do + using "$flag" + done +} + +## flags used in the linking step +gen_LDFLAGS () { + if pkg-config readline; then + ldflags="$(pkg-config --libs readline)" + fi + if present ld.lld; then + ldflags="$ldflags -fuse-ld=lld" + elif present ld.gold; then + ldflags="$ldflags -fuse-ld=gold" + fi + [ -z "$debug" ] && ldflags="$ldflags -Wl,--gc-sections" + + for flag in $ldflags; do + using "$flag" + done +} + +# command line interface + +while getopts c:dhr ch; do + case "$ch" in + c) cc="$OPTARG" ;; + d) debug=1 ;; + r) unset debug ;; + h) + cat <"$mkf"