--- /dev/null
+#!/usr/bin/env bash
+
+# predeclare our variables
+declare -a objects
+declare -a libpaths
+compile=false
+runtime='
+#define _POSIX_C_SOURCE 200809L
+#define _XOPEN_SOURCE 700
+#define AUTOLIB(n) \
+ int __autolib_##n __attribute__ ((weak));'
+
+# scan the rest of the options for lib paths, libs and objects
+for i do
+ case "$i" in
+ *.[ao]) # Add objects and static libs to object list
+ objects+=("$i") ;;
+
+ -L*) # Add libpaths to the search list
+ libpaths+=("${i#-L}") ;;
+
+ -c) # Mark this as compilation only
+ compile=true ;;
+ esac
+done
+
+# if we're compiling, generate the header, compile, and exit
+if $compile; then
+ genfile=$(mktemp)
+ printf '%s\n' "$runtime" > "$genfile"
+ cc -isystem "${genfile%/*}" -include "${genfile##*/}" --std=c99 -pedantic -Wall -Wextra -Werror "$@"
+ status=$?
+ rm "$genfile"
+ exit "$status"
+fi
+
+# scan objects/libs for referenced libraries
+scan_for_libs(){
+ [[ $# -ne 0 ]] && nm "$@" | sed -n '/__autolib/ s/.*_\+autolib_// p' | sort -u
+}
+
+# if we made it here, we must be linking. scan for dependencies
+mapfile -t libraries < <(scan_for_libs "${objects[@]}")
+cc "$@" "${libraries[@]/#/-l}"
INCS += -I/usr/include/freetype2
# Compiler Setup
-CC = cc
-CFLAGS = -g -MMD $(INCS)
-CFLAGS += --std=c99 -pedantic
-CFLAGS += -Wall -Wextra
-CFLAGS += -Werror
+CC = ./acc
+CFLAGS = -MMD $(INCS)
CFLAGS += -Wno-missing-field-initializers -Wno-implicit-fallthrough
# Linker Setup
LD = $(CC)
-LDFLAGS = $(LIBS) -lX11 -lXft -lfontconfig -lXinerama -lutil -lm
+LDFLAGS = $(LIBS)
# Archive Setup
AR = ar
-#define _DEFAULT_SOURCE
-#define _BSD_SOURCE
-#define _XOPEN_SOURCE 700
-#define _POSIX_C_SOURCE 20080
#define XINERAMA
/* See LICENSE for license details. */