diff --git a/Makefile b/Makefile index b7a248dd..28d8e5b0 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,8 @@ else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux else ifeq ($(REPORTED_PLATFORM), Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) +PLATFORM=netbsd else $(error Unsupported platform (uname reported "$(REPORTED_PLATFORM)")) endif @@ -99,6 +101,10 @@ else ifeq ($(PLATFORM),linux) PLATFORM=linux CC=gcc LIBROSIE_DYLIB=librosie.so +else ifeq ($(PLATFORM),netbsd) +PLATFORM=bsd +CC=cc +LIBROSIE_DYLIB=librosie.so endif # ----------------------------------------------------------------------------- @@ -211,10 +217,10 @@ $(ROSIEBIN): $(LIBROSIE_DIR)/binaries/rosie VERSION # MacOS, since it ships with readline. .PHONY: readlinetest readlinetest: cctest - @(bash -c 'printf "#include \n#include \nint main() { }\n"' | \ - $(CC) -std=c99 -lreadline -o /dev/null -xc -) && \ - echo 'libreadline and readline.h appear to be installed' || \ - (echo '**'; echo '** readline TEST: Missing readline library or readline.h'; echo '**' && false) +# @(bash -c 'printf "#include \n#include \nint main() { }\n"' | \ +# $(CC) -std=c99 -lreadline -o /dev/null -xc -) && \ +# echo 'libreadline and readline.h appear to be installed' || \ +# (echo '**'; echo '** readline TEST: Missing readline library or readline.h'; echo '**' && false) .PHONY: cctest cctest: diff --git a/rosie b/rosie index 3f17e6d1..998f96d4 100755 --- a/rosie +++ b/rosie @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # The rosie executable dynamically loads librosie.so (librosie.dylib # on MacOS). By default, the operating system will look in the diff --git a/src/build_info.sh b/src/build_info.sh index 3d909e0c..0d96b424 100755 --- a/src/build_info.sh +++ b/src/build_info.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$#" -ne 3 ]; then echo Usage: $0 component_name build_directory compiler_name diff --git a/src/librosie/Makefile b/src/librosie/Makefile index ff209d7b..7c6ba58a 100644 --- a/src/librosie/Makefile +++ b/src/librosie/Makefile @@ -47,11 +47,18 @@ debugger_flag=-O0 -g ndebug_flag= endif +# OSX ships with libedit, which will link with -lreadline but doesn't have +# exactly the same API. Set USE_LIBEDIT to false (or undefine it) to use GNU +# libreadline on OSX. +USE_LIBEDIT=true + REPORTED_PLATFORM=$(shell (uname -o || uname -s) 2> /dev/null) ifeq ($(REPORTED_PLATFORM), Darwin) PLATFORM=macosx else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) + PLATFORM=netbsd else PLATFORM=none endif @@ -67,6 +74,12 @@ ifeq ($(PLATFORM),macosx) SYSLDFLAGS=-dynamiclib CFLAGS += -std=c99 ROSIE_DYLIB=lib$(ROSIE_DYLIB_NAME).dylib +else ifeq ($(PLATFORM),netbsd) + CC=cc + SYSCFLAGS=-DLUA_USE_POSIX -std=c99 -fPIC + SYSLDFLAGS=-shared + SYSLIBS=-lpthread -lm + ROSIE_DYLIB=lib$(ROSIE_DYLIB_NAME).so else CC=gcc SYSCFLAGS=-DLUA_USE_LINUX -std=c99 -D_GNU_SOURCE=1 -fPIC @@ -82,6 +95,14 @@ MYLDFLAGS= MYLIBS= MYOBJS= +ifeq ($(USE_LIBEDIT),true) +ifeq ($(PLATFORM),netbsd) +MYLIBS += -ledit +endif +else +MYLIBS += -lreadline +endif + CFLAGS= -O2 -Wall -Wextra -pthread -DMULTIPLE_THREADS -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= $(SYSLIBS) $(MYLIBS) @@ -131,7 +152,7 @@ $(BINDIR)/librosie.o: librosie.c librosie.h logging.c registry.c rosiestring.c | $(CC) $(ASAN_OPT) -fvisibility=hidden -o $@ -c librosie.c $(CFLAGS) -I$(RPEG_INCLUDE_DIR) $(BINDIR)/librosie.so: $(BINDIR)/librosie.o $(dependent_objs) | $(BINDIR) liblua - $(CC) -o $@ $< $(dependent_objs) $(LIBS) $(LDFLAGS) $(ASAN_OPT) -lreadline $(HOME)/submodules/lua-readline/src/*.o + $(CC) -o $@ $< $(dependent_objs) $(LIBS) $(LDFLAGS) $(ASAN_OPT) $(HOME)/submodules/lua-readline/src/*.o $(BINDIR)/librosie.dylib: $(BINDIR)/librosie.o $(dependent_objs) | $(BINDIR) liblua $(CC) -o $@ $< $(dependent_objs) $(LIBS) $(LDFLAGS) $(ASAN_OPT) -lreadline $(HOME)/submodules/lua-readline/src/*.o @@ -144,7 +165,7 @@ $(BINDIR)/rosie.o: rosie.c librosie.c librosie.h lua_repl.h $(BINDIR)/$(ROSIE_DY $(CC) -o $@ -c rosie.c $(ASAN_OPT) $(CFLAGS) -I$(RPEG_INCLUDE_DIR) $(BINDIR)/rosie: $(BINDIR)/rosie.o $(dependent_objs) liblua | $(BINDIR) - $(CC) -o $@ $< $(ASAN_OPT) $(dependent_objs) $(LIBS) -lreadline + $(CC) -o $@ $< $(ASAN_OPT) $(dependent_objs) $(LIBS) $(RUNTIME_DIR)/*.o: $(MAKE) -C $(RUNTIME_DIR) diff --git a/src/rpeg/compiler/Makefile b/src/rpeg/compiler/Makefile index 57634b08..4580d0ce 100644 --- a/src/rpeg/compiler/Makefile +++ b/src/rpeg/compiler/Makefile @@ -16,6 +16,8 @@ ifeq ($(REPORTED_PLATFORM), Darwin) PLATFORM=macosx else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) +PLATFORM=netbsd else PLATFORM=none endif @@ -39,6 +41,10 @@ ifeq ($(PLATFORM), macosx) CC= cc Cstd= c99 DLLFLAGS = -bundle -undefined dynamic_lookup +else ifeq ($(PLATFORM), netbsd) +CC= cc +Cstd= c99 +DLLFLAGS = -shared -fPIC else CC= gcc Cstd= c99 diff --git a/src/rpeg/compiler/lptree.c b/src/rpeg/compiler/lptree.c index 4cac2b6d..8ce0e305 100644 --- a/src/rpeg/compiler/lptree.c +++ b/src/rpeg/compiler/lptree.c @@ -9,7 +9,6 @@ #endif #include -#include #include #include #include diff --git a/src/rpeg/runtime/Makefile b/src/rpeg/runtime/Makefile index 2c9fd2af..f6da6026 100644 --- a/src/rpeg/runtime/Makefile +++ b/src/rpeg/runtime/Makefile @@ -16,6 +16,8 @@ ifeq ($(REPORTED_PLATFORM), Darwin) PLATFORM=macosx else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) +PLATFORM=netbsd else PLATFORM=none endif diff --git a/src/rpeg/runtime/ktable.c b/src/rpeg/runtime/ktable.c index ef0eea5f..499be971 100644 --- a/src/rpeg/runtime/ktable.c +++ b/src/rpeg/runtime/ktable.c @@ -73,6 +73,10 @@ #define _GNU_SOURCE #endif +#if defined(__NetBSD__) +#include "qsort_r.c" +#endif + #if defined(__linux__) #define qsort_r_common(base, n, sz, context, compare) qsort_r((base), (n), (sz), (compare), (context)) #else diff --git a/src/rpeg/test/Makefile b/src/rpeg/test/Makefile index c39d4ab4..239afb7a 100644 --- a/src/rpeg/test/Makefile +++ b/src/rpeg/test/Makefile @@ -16,6 +16,8 @@ ifeq ($(REPORTED_PLATFORM), Darwin) PLATFORM=macosx else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) +PLATFORM=netbsd else PLATFORM=none endif diff --git a/src/rpeg/util/Makefile b/src/rpeg/util/Makefile index 66146292..2e8dd20c 100644 --- a/src/rpeg/util/Makefile +++ b/src/rpeg/util/Makefile @@ -18,6 +18,8 @@ ifeq ($(REPORTED_PLATFORM), Darwin) PLATFORM=macosx else ifeq ($(REPORTED_PLATFORM), GNU/Linux) PLATFORM=linux +else ifeq ($(REPORTED_PLATFORM), NetBSD) +PLATFORM=netbsd else PLATFORM=none endif diff --git a/submodules/lua-readline b/submodules/lua-readline --- a/submodules/lua-readline +++ b/submodules/lua-readline @@ -1 +1 @@ -Subproject commit 4aedcbdb991055d00505752dca86f57fff90bd95 +Subproject commit 4aedcbdb991055d00505752dca86f57fff90bd95-dirty