aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoropal hart <opal@wowana.me>2018-11-09 11:46:35 +0000
committeropal hart <opal@wowana.me>2018-11-09 11:46:35 +0000
commit29b2d3b9810a9c173e0801c0fa17cd0f969eb26c (patch)
tree5a76bbfecd5fe1dd5ba091223ef01b30bcecf028
parentfcd118a9aaa2e77779ae76d759bc5ca7c434ff9d (diff)
build: add build-related files
-rw-r--r--Makefile58
-rw-r--r--buildconf/check_func.c9
-rw-r--r--buildconf/deps.mk75
-rwxr-xr-xconfigure128
4 files changed, 270 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..33a21c4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,58 @@
+# use `./configure` to autodetect build target and set common options,
+# edit <./buildconf/custom.mk> directly for any additional make rules
+# that you want
+EXE := achlys
+SRC := $(wildcard src/*/*.c)
+OBJ := $(SRC:src/%.c=obj/%.o)
+
+INC := -Isrc/
+WARNINGS := -Wall -Wpedantic -Wextra
+WARNINGS += -Wno-variadic-macros
+
+# these can be appended to with `./configure` or <./custom.mk>
+CPPFLAGS := $(INC)
+CFLAGS := -g $(CPPFLAGS) $(WARNINGS)
+LDFLAGS := -ldl
+PHONY := all clean distclean depend
+
+all: $(EXE)
+
+include buildconf/config.mk
+-include buildconf/custom.mk
+-include buildconf/deps.mk
+
+.PHONY: $(PHONY)
+
+$(EXE): $(OBJ)
+ @-printf 'LD %s\n' "$@"
+ @ $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
+
+obj/client/client.so: $(wildcard obj/client/*.o)
+ @-printf 'LD %s\n' "$@"
+ @ $(CC) $(CFLAGS) $^ -shared -o $@ $(LDFLAGS)
+obj/irc/irc.so: $(wildcard obj/irc/*.o)
+ @-printf 'LD %s\n' "$@"
+ @ $(CC) $(CFLAGS) $^ -shared -o $@ $(LDFLAGS)
+obj/relayd/relayd.so: $(wildcard obj/relayd/*.o)
+ @-printf 'LD %s\n' "$@"
+ @ $(CC) $(CFLAGS) $^ -shared -o $@ $(LDFLAGS)
+
+obj/%.o: src/%.c
+ @-printf 'CC %s\n' "$@"
+ @ $(CC) $(DEFS) -c -o $@ $< $(CFLAGS)
+
+clean:
+ @-printf 'Removing object files...'
+ @-$(RM) -f $(EXE) obj/*/*.o
+ @-printf 'done.\n'
+
+distclean: clean
+ @-printf 'Removing configuration...'
+ @-$(RM) -f buildconf/config.mk buildconf/custom.mk buildconf/deps.mk
+ @-printf 'done.\n'
+
+depend:
+ @echo '# This file is automatically generated by `make depend`' \
+ > buildconf/deps.mk
+ makedepend -Y -f- -- $(CFLAGS) -- $(SRC) 2>/dev/null \
+ | sed 's-^src/-obj/-' >> buildconf/deps.mk
diff --git a/buildconf/check_func.c b/buildconf/check_func.c
new file mode 100644
index 0000000..d1e4d8e
--- /dev/null
+++ b/buildconf/check_func.c
@@ -0,0 +1,9 @@
+/* Used by <./configure> to test for presence of functions */
+
+void TEST_FN();
+
+int main ()
+{
+ TEST_FN();
+ return 0;
+}
diff --git a/buildconf/deps.mk b/buildconf/deps.mk
new file mode 100644
index 0000000..2e8c6e0
--- /dev/null
+++ b/buildconf/deps.mk
@@ -0,0 +1,75 @@
+# This file is automatically generated by `make depend`
+# DO NOT DELETE
+
+obj/relayd/relayd.o: src/relayd/relayd.h src/core/chat.h src/core/common.h
+obj/relayd/relayd.o: src/core/config.h src/core/str.h src/core/array.h
+obj/relayd/relayd.o: src/core/str.h src/core/hook.h src/core/module.h
+obj/client/prompt.o: src/client/prompt.h src/core/common.h src/core/config.h
+obj/client/prompt.o: src/core/str.h src/core/array.h src/core/str.h
+obj/client/prompt.o: src/core/achlys.h src/core/event.h src/core/hook.h
+obj/client/prompt.o: src/client/conf.h src/client/disp.h src/core/interp.h
+obj/client/sub.o: src/client/sub.h src/core/str.h src/core/common.h
+obj/client/sub.o: src/core/config.h src/core/str.h src/core/array.h
+obj/client/sub.o: src/core/parse.h src/core/interp.h
+obj/client/disp.o: src/client/disp.h src/core/str.h src/core/common.h
+obj/client/disp.o: src/core/config.h src/core/str.h src/core/array.h
+obj/client/disp.o: src/core/hook.h src/client/conf.h src/core/interp.h
+obj/client/disp.o: src/client/prompt.h
+obj/client/client.o: src/core/common.h src/core/config.h src/core/str.h
+obj/client/client.o: src/core/array.h src/core/str.h src/core/module.h
+obj/client/client.o: src/client/conf.h src/client/disp.h src/client/prompt.h
+obj/client/client.o: src/client/sub.h
+obj/client/conf.o: src/client/conf.h src/core/str.h src/core/common.h
+obj/client/conf.o: src/core/config.h src/core/str.h src/core/array.h
+obj/client/conf.o: src/core/hook.h src/core/parse.h src/client/disp.h
+obj/client/conf.o: src/core/interp.h
+obj/irc/irc.o: src/irc/irc.h src/core/chat.h src/irc/line.h src/core/str.h
+obj/irc/irc.o: src/irc/parse.h src/core/array.h src/core/common.h
+obj/irc/irc.o: src/core/config.h src/core/str.h src/core/array.h
+obj/irc/irc.o: src/core/event.h src/core/hook.h src/core/interp.h
+obj/irc/irc.o: src/core/module.h src/core/net.h src/core/parse.h
+obj/irc/irc.o: src/irc/cmd.h src/irc/user.h
+obj/irc/line.o: src/irc/irc.h src/core/chat.h src/irc/line.h src/core/str.h
+obj/irc/line.o: src/irc/parse.h src/core/array.h src/core/common.h
+obj/irc/line.o: src/core/config.h src/core/str.h src/core/array.h
+obj/irc/cmd.o: src/irc/cmd.h src/irc/irc.h src/core/chat.h src/irc/line.h
+obj/irc/cmd.o: src/core/str.h src/irc/parse.h src/core/array.h
+obj/irc/cmd.o: src/core/common.h src/core/config.h src/core/str.h
+obj/irc/cmd.o: src/core/array.h src/core/hook.h src/irc/channel.h
+obj/irc/cmd.o: src/irc/user.h
+obj/irc/parse.o: src/irc/parse.h src/core/array.h src/core/str.h
+obj/irc/parse.o: src/core/common.h src/core/config.h src/core/str.h
+obj/irc/parse.o: src/core/array.h
+obj/irc/channel.o: src/irc/channel.h src/irc/irc.h src/core/chat.h
+obj/irc/channel.o: src/irc/line.h src/core/str.h src/irc/parse.h
+obj/irc/channel.o: src/core/array.h src/core/common.h src/core/config.h
+obj/irc/channel.o: src/core/str.h src/core/array.h src/irc/user.h
+obj/irc/user.o: src/irc/user.h src/core/str.h src/irc/irc.h src/core/chat.h
+obj/irc/user.o: src/irc/line.h src/irc/parse.h src/core/array.h
+obj/irc/user.o: src/core/common.h src/core/config.h src/core/str.h
+obj/irc/user.o: src/core/array.h src/irc/channel.h
+obj/core/array.o: src/core/array.h src/core/str.h src/core/common.h
+obj/core/array.o: src/core/config.h src/core/str.h src/core/array.h
+obj/core/memmem.o: src/core/memmem.h src/core/common.h src/core/config.h
+obj/core/memmem.o: src/core/str.h src/core/array.h src/core/str.h
+obj/core/achlys.o: src/core/achlys.h src/core/common.h src/core/config.h
+obj/core/achlys.o: src/core/str.h src/core/array.h src/core/str.h
+obj/core/achlys.o: src/core/event.h src/core/hook.h src/core/module.h
+obj/core/achlys.o: src/core/interp.h
+obj/core/parse.o: src/core/common.h src/core/config.h src/core/str.h
+obj/core/parse.o: src/core/array.h src/core/str.h src/core/parse.h
+obj/core/interp.o: src/core/interp.h src/core/str.h src/core/common.h
+obj/core/interp.o: src/core/config.h src/core/str.h src/core/array.h
+obj/core/interp.o: src/core/achlys.h src/core/parse.h src/client/disp.h
+obj/core/module.o: src/core/module.h src/core/str.h src/core/common.h
+obj/core/module.o: src/core/config.h src/core/str.h src/core/array.h
+obj/core/module.o: src/core/module_static.c.inc src/core/module_static.h
+obj/core/str.o: src/core/str.h src/core/common.h src/core/config.h
+obj/core/str.o: src/core/str.h src/core/array.h src/core/memmem.h
+obj/core/hook.o: src/core/hook.h src/core/str.h src/core/common.h
+obj/core/hook.o: src/core/config.h src/core/str.h src/core/array.h
+obj/core/net.o: src/core/net.h src/core/event.h src/core/str.h
+obj/core/net.o: src/core/common.h src/core/config.h src/core/str.h
+obj/core/net.o: src/core/array.h src/core/parse.h
+obj/core/event_epoll.o: src/core/event.h src/core/common.h src/core/config.h
+obj/core/event_epoll.o: src/core/str.h src/core/array.h src/core/str.h
diff --git a/configure b/configure
new file mode 100755
index 0000000..54a011e
--- /dev/null
+++ b/configure
@@ -0,0 +1,128 @@
+#!/bin/sh
+: "${CC:=c99}"
+unset PREFERRED_EVENTLIB
+
+envvars='CC CFLAGS LDFLAGS LIBS CPPFLAGS'
+
+echo() { printf '%s\n' "$*"; }
+perror() { echo "E: $*" >&2; }
+write_mk() { echo "$*" >>buildconf/config.mk; }
+configure_help() {
+ cat <<-EOF
+ Usage: ${0} [OPTION]... [VAR[+]=VALUE]...
+ where OPTION can be:
+ -h --help:
+ Display this help
+ --prefix=/usr/local
+ Configure base install path
+ --static-modules
+ Statically link modules (by default, they are dynamically
+ linked)
+ --event-lib=epoll
+ Override event library. By default, the configure script
+ detects the best implementation that is available on your
+ system. Check <src/core/event_*.c> for compatible event
+ libraries.
+ and VAR=VALUE can be any variable definition that will be passed to
+ make. VAR+=VALUE will cause VALUE to be appended to the current
+ value of VAR.
+ Some influential environment variables:
+ ${envvars}
+ Please note that unrecognised VARs will be defined as well.
+EOF
+ exit 0
+}
+configure_unknown_opt() {
+ perror "Unrecognised option '$*'"
+ exit 1
+}
+
+cd "$(dirname "${0}")" || { perror "Can't cd to ${0}"; exit 1; }
+
+## Prep <./buildconf/config.mk>
+
+(
+ echo '# This file is automatically generated by `./configure`'
+ echo
+) > buildconf/config.mk
+
+## Add version information based on git tag and commit
+ACHLYS_VERSION="$(git describe)"
+
+## Read args
+
+while getopts 'h-:' OPT; do
+ if test x"$OPT" = x-; then
+ k="${OPTARG%%=*}"
+ v="${OPTARG#*=}"
+ case "${k}" in
+ help) configure_help;;
+ prefix) write_mk "PREFIX=${v}";;
+ event-lib)
+ # if user prefers a specific event library, we blindly
+ # set it. if it doesn't exist, code fails to compile
+ # later, that simple.
+ case "${v}" in
+ kevent) ;;
+ epoll) ;;
+ poll) ;;
+ select) ;;
+ *) perror "Unknown event-lib '${v}'"; exit 1;;
+ esac
+ PREFERRED_EVENTLIB="${v}"
+ CPPFLAGS="${CPPFLAGS} -DUSE_$(tr a-z A-Z "${v}") "
+ ;;
+ *) configure_unknown_opt "--${k}";;
+ esac
+ fi
+ case "${OPT}" in
+ h) configure_help;;
+ *) configure_unknown_opt "-${OPT}";;
+ esac
+done
+shift $(( OPTIND-1 ))
+
+## Write VAR=VALUE and VAR+=VALUE pairs to <./buildconf/config.mk>
+
+for envvar in $envvars; do
+ : # TODO
+done
+for pair in "$@"; do
+ if ! echo "${pair}" | grep -q =; then
+ configure_unknown_opt "${pair}"
+ fi
+ write_mk "${pair} "
+done
+
+## Check what this system supports
+# check_func() adapted by a public-domain script "check_cflags.sh",
+# written by Daniel 'q66' Kolesa. Thanks for letting me avoid
+# GNU autoconf.
+
+supported_funcs=''
+
+check_func() {
+ printf "Checking whether %s() exists... " "${1}"
+ if \
+ "${CC}" buildconf/check_func.c -DTEST_FN="${1}" \
+ -o buildconf/.check_func 2>/dev/null
+ then
+ echo "found."
+ supported_funcs="${supported_funcs}-D${2} "
+ return 0
+ else
+ echo "not found."
+ return 1
+ fi
+}
+
+if test x"${PREFERRED_EVENTLIB}" = x''; then
+ # user doesn't care, let's pick what we think is best
+ check_func kevent USE_KQUEUE ||
+ check_func epoll_create USE_EPOLL ||
+ check_func poll USE_POLL ||
+ supported_funcs="${supported_funcs}-DUSE_SELECT "
+ # or fall back to select() if all else fails
+fi
+write_mk "DEFS := ${supported_funcs}"
+rm -f buildconf/.check_func