]> git.mdlowis.com Git - projs/tide.git/commitdiff
added fancy compiler wrapper script inspired by plan9port 9l script. Hard codes some...
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 1 Feb 2019 15:30:39 +0000 (10:30 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 1 Feb 2019 15:30:39 +0000 (10:30 -0500)
Makefile
acc [new file with mode: 0755]
config.mk
inc/x11.h
src/lib/buf.c
src/lib/job.c
src/lib/utf8.c
src/term.c
src/tide.c
tests/lib/buf.c

index f0bc54f8d11cf7795da8e42757ab9e08641105ba..0c7384f157f02b3038902cc4709deef74609c3c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+CC = ./acc
 INCS = -Iinc/
 BINS = bin/tide bin/registrar bin/edit bin/fetch bin/pick
 MAN1 = docs/tide.1
diff --git a/acc b/acc
new file mode 100755 (executable)
index 0000000..da9c0d6
--- /dev/null
+++ b/acc
@@ -0,0 +1,44 @@
+#!/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}"
index 4be11ae84961818aa5669dc3897194d895b0cc52..5c6e7d64e0088e9751613dcb8328a78aa81d5b55 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -16,16 +16,13 @@ LIBS += -L/usr/X11/lib
 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
index 131670f970df0445cc7734bf8b8d6979175d8522..79e351376ce86aa761c864519d33aef80721ce45 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -1,3 +1,9 @@
+/* library dependencies */
+AUTOLIB(X11)
+AUTOLIB(Xinerama)
+AUTOLIB(Xft)
+AUTOLIB(fontconfig)
+
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/Xft/Xft.h>
index a774a522edec0b4ee18f59ef3c7b9ca73bf8e42d..2bbc6d04f554fc7474e16beab0c001851a22b20c 100644 (file)
@@ -1,4 +1,3 @@
-#define _POSIX_C_SOURCE 200809L
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
index 1f7e000554515bafce6290522c75ebb3c5af1158..12ff10504ca9e0d3d9980f52b4fab287af6cadf6 100644 (file)
@@ -1,4 +1,3 @@
-#define _POSIX_C_SOURCE 200809L
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
index b20b9f4357288cc6d50b909287cc37523235cc21..19dd5edba2163a1c2f54f3c8c8a47b46c1cd5c43 100644 (file)
@@ -1,7 +1,6 @@
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
-#define __USE_XOPEN
 #include <wchar.h>
 #include <ctype.h>
 #include "config.h"
index 6b27d9c513160bf1af77d410d2dcbe8cb2c903b7..6b952565d4980e07fab27fb309e3e0c55cad078c 100644 (file)
@@ -1,7 +1,3 @@
-#define _DEFAULT_SOURCE
-#define _BSD_SOURCE
-#define _XOPEN_SOURCE 700
-#define _POSIX_C_SOURCE 20080
 #define XINERAMA
 
 /* See LICENSE for license details. */
index 51579b60bc1c3de189d8109ba8f76764dc278e1d..3e92f25226391b6a07301ddcf5b464c7b708b8f8 100644 (file)
@@ -1,5 +1,3 @@
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 700
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
index dafb918620638152675fdfa69bb6489963a7e62d..13481e5376a4bc64e8d290df79c2b6f94cccac81 100644 (file)
@@ -1,5 +1,3 @@
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 700
 #include <atf.h>
 #include <stdc.h>
 #include <utf.h>