Skip to content

Instantly share code, notes, and snippets.

@mdkcore0
Last active February 2, 2016 19:24
Show Gist options
  • Save mdkcore0/be291bb6c0e63d5523a9 to your computer and use it in GitHub Desktop.
Save mdkcore0/be291bb6c0e63d5523a9 to your computer and use it in GitHub Desktop.
st on OSX X (with XQuartz)
From c8ddc4f1e53a037fea13b877b6f20641f841fdd7 Mon Sep 17 00:00:00 2001
From: Rodrigo Oliveira <[email protected]>
Date: Fri, 9 Oct 2015 13:49:09 -0300
Subject: [PATCH 1/2] Compiling on OSX
Signed-off-by: Rodrigo Oliveira <[email protected]>
---
config.mk | 10 +++++-----
st.c | 22 +++++++++++++++++++++-
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/config.mk b/config.mk
index 81e3e47..b381581 100644
--- a/config.mk
+++ b/config.mk
@@ -4,17 +4,17 @@ VERSION = 0.6
# Customize below to fit your system
# paths
-PREFIX = /usr/local
+PREFIX = /opt/local
MANPREFIX = ${PREFIX}/share/man
-X11INC = /usr/X11R6/include
-X11LIB = /usr/X11R6/lib
+X11INC = /opt/X11/include
+X11LIB = /opt/X11/lib
# includes and libs
-INCS = -I. -I/usr/include -I${X11INC} \
+INCS = -I. -I/opt/local/include -I${X11INC} \
`pkg-config --cflags fontconfig` \
`pkg-config --cflags freetype2`
-LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L/opt/local/lib -lc -L${X11LIB} -lX11 -lutil -lXext -lXft \
`pkg-config --libs fontconfig` \
`pkg-config --libs freetype2`
diff --git a/st.c b/st.c
index 0536b6f..3119993 100644
--- a/st.c
+++ b/st.c
@@ -18,7 +18,6 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
-#include <time.h>
#include <unistd.h>
#include <libgen.h>
#include <X11/Xatom.h>
@@ -35,6 +34,27 @@
char *argv0;
+#ifdef __MACH__
+ #include <mach/mach_time.h>
+
+ #define CLOCK_REALTIME 0
+ #define CLOCK_MONOTONIC 0
+
+ int clock_gettime(int clk_id, struct timespec *t) {
+ mach_timebase_info_data_t timebase;
+ mach_timebase_info(&timebase);
+ uint64_t time;
+ time = mach_absolute_time();
+ double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom);
+ double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9);
+ t->tv_sec = seconds;
+ t->tv_nsec = nseconds;
+ return 0;
+ }
+#else
+ #include <time.h>
+#endif
+
#define Glyph Glyph_
#define Font Font_
--
2.7.0
From b41a969a4264f7f9f0f230478af12f482d85cce6 Mon Sep 17 00:00:00 2001
From: Rodrigo Oliveira <[email protected]>
Date: Wed, 21 Oct 2015 10:05:51 -0200
Subject: [PATCH 2/2] Adjusting config.mk to compile st for new XQuartz version
(2.7.8)
---
config.mk | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config.mk b/config.mk
index b381581..d28aadd 100644
--- a/config.mk
+++ b/config.mk
@@ -11,10 +11,10 @@ X11INC = /opt/X11/include
X11LIB = /opt/X11/lib
# includes and libs
-INCS = -I. -I/opt/local/include -I${X11INC} \
+INCS = -I. -I${X11INC} -I/opt/local/include \
`pkg-config --cflags fontconfig` \
`pkg-config --cflags freetype2`
-LIBS = -L/opt/local/lib -lc -L${X11LIB} -lX11 -lutil -lXext -lXft \
+LIBS = -L${X11LIB} -L/opt/local/lib -lc -lX11 -lutil -lXext -lXft \
`pkg-config --libs fontconfig` \
`pkg-config --libs freetype2`
--
2.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment