commit: 6fa683f7c4cf7db53c3f7b143bdf3a181556cc9e
parent: eb2e0676cd162af963a3cb2fad48ba3f458b4c4c
author: Geoff Nixon <geoff@geoff.codes>
date: Mon, 18 Jan 2016 10:30:20 -0800
Add Darwin/Mac OS X support.
5 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/GNUmakefile b/GNUmakefile
@@ -25,7 +25,7 @@ ifeq ($(UNAME_S),Linux)
GROUP = root
OBJS += portable/common/reallocarray.o portable/linux/setmode.o \
portable/linux/signame.o portable/linux/strlcat.o \
- portable/linux/strlcpy.o portable/linux/strtonum.o
+ portable/linux/strlcpy.o portable/common/strtonum.o
else ifeq ($(UNAME_S),FreeBSD)
GROUP = bin
OBJS += portable/common/reallocarray.o
@@ -35,21 +35,39 @@ OBJS += portable/common/reallocarray.o
else ifeq ($(UNAME_S),NetBSD)
GROUP = bin
OBJS += portable/common/reallocarray.o
+else ifeq ($(UNAME_S),Darwin)
+GROUP = bin
+OBJS += portable/common/reallocarray.o portable/common/strtonum.o
endif
#
# Only update /etc/shells at install time, not during update
#
+ifneq ($(UNAME_S),Darwin)
UPDATE := `grep -w ${PREFIX}/bin/${PROG} /etc/shells > /dev/null;\
[ $$? -ne 0] && echo "${PREFIX}/bin/${PROG}" >> /etc/shells`
+endif
+ifneq ($(UNAME_S),Darwin)
all: ${OBJS}
${CC} -o ${PROG} ${OBJS}
+else
+all: oksh
+
+oksh: ${OBJS}
+ ${CC} ${CFLAGS} ${LDFLAGS} -o ${PROG} ${OBJS}
+endif
install: all
+ifneq ($(UNAME_S),Darwin)
${INSTALL} -c -s -o root -g ${GROUP} -m 555 ${PROG} ${PREFIX}/bin
${INSTALL} -c -s -o root -g ${GROUP} -m 444 oksh.1 ${MANDIR}/man1/${PROG}.1
echo ${UPDATE}
+else
+ @mkdir -p ${PREFIX}/bin ${MANDIR}/man1
+ ${INSTALL} -m 755 ${PROG} ${PREFIX}/bin
+ ${INSTALL} -m 644 ${PROG}.1 ${MANDIR}/man1
+endif
clean:
rm -f ${PROG} ${OBJS}
diff --git a/README.md b/README.md
@@ -9,6 +9,7 @@ Originally a port of ksh to FreeBSD. The default FreeBSD shell is tcsh.
No one likes tcsh. DragonFly BSD should also just work.
Later NetBSD support was added. NetBSD also has a ksh variant so it might be less useful there.
Linux support, tested on Slackware and Ubuntu, exists.
+Darwin (Mac OS X) supported as well.
Other operating system support welcome and appreciated.
License
diff --git a/portable/linux/strtonum.c b/portable/common/strtonum.c
rename portable/linux/strtonum.c → portable/common/strtonum.c
diff --git a/portable/darwin/darwin.h b/portable/darwin/darwin.h
@@ -0,0 +1,14 @@
+/*
+ * Mac OS X support.
+ */
+
+ /* Includes */
+#include <sys/param.h>
+
+/* Defines */
+#define _PW_NAME_LEN MAXLOGNAME - 1
+#define srand_deterministic(x) srand(x)
+
+/* Not really sure on these two, but it seems to work ok. */
+#define setresgid(x, y, z) setgid(x); setegid(y); setgid(z)
+#define setresuid(x, y, z) setuid(x); seteuid(y); setuid(z)
diff --git a/sh.h b/sh.h
@@ -38,6 +38,9 @@
#ifdef __NetBSD__
#include "portable/netbsd/netbsd.h"
#endif
+#ifdef __APPLE__
+#include "portable/darwin/darwin.h"
+#endif
/* Find a integer type that is at least 32 bits (or die) - SIZEOF_* defined
* by autoconf (assumes an 8 bit byte, but I'm not concerned).