Skip to content

Commit

Permalink
Add BSD support to erlang_js
Browse files Browse the repository at this point in the history
This patch adds .mk files for FreeBSD, NetBSD, OpenBSD and DragonFlyBSD.
It also patches some nspr files so that nspr builds correctly for the
BSDs as well.

To workaround the hardcoded invocation of 'make' in rebar.config, the
Makefile has been renamed GNUmakefile and a new BSD compatible stub
Makefile has been added. Additionally, instead of using make -C, a new
Makefile target has been added to both Makefiles, 'c_src' which does the
directory change as part of the make rule. This fixes issues where BSD
make does not support the -C option.

$(MAKE) was not used, because we can not gurantee that the user built
the top-level repo (eg riak) by using (g)make instead of calling rebar
compile. Also, its unclear if rebar even supports the use of $(MAKE) in
hook commands.
  • Loading branch information
Vagabond committed Oct 5, 2011
1 parent 6691d52 commit e1e0a76
Show file tree
Hide file tree
Showing 13 changed files with 834 additions and 22 deletions.
30 changes: 30 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

all:
$(REBAR) compile

verbose:
$(REBAR) compile verbose=1

clean: c_src_clean
rm -rf tests_ebin docs
$(REBAR) clean

c_src:
cd c_src; $(MAKE)

c_src_clean:
cd c_src; $(MAKE) clean

test: all
@mkdir -p tests_ebin
@cd tests;erl -make
@erl -noshell -boot start_sasl -pa ebin -pa tests_ebin -s erlang_js -eval 'test_suite:test().' -s init stop
@rm -f ebin/test_* ebin/*_tests.erl

docs: all
@mkdir -p docs
@./build_docs.sh

.PHONY: c_src docs

include rebar.mk
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# This is a stub Makefile that invokes GNU make which will read the GNUmakefile
# instead of this file. This provides compatability on systems where GNU make is
# not the system 'make' (eg. most non-linux UNIXes).

all:
$(REBAR) compile
@gmake all

verbose:
$(REBAR) compile verbose=1
@gmake verbose

clean:
rm -rf tests_ebin docs
$(REBAR) clean
cd c_src; $(MAKE) clean

test: all
@mkdir -p tests_ebin
@cd tests;erl -make
@erl -noshell -boot start_sasl -pa ebin -pa tests_ebin -s erlang_js -eval 'test_suite:test().' -s init stop
@rm -f ebin/test_* ebin/*_tests.erl
test:
@gmake test

docs: all
@mkdir -p docs
@./build_docs.sh
docs:
@gmake docs

include rebar.mk
c_src: FORCE
@gmake c_src
FORCE:

c_src_clean:
@gmake c_src_clean

clean:
@gmake clean
12 changes: 11 additions & 1 deletion c_src/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# This Makefile builds the dependencies (libjs and libnspr) needed by
# spidermonkey_drv.so

UNAME := $(shell uname -s)
TAR ?= tar
GUNZIP ?= gunzip
SMONKEY_VER := 1.8.0-rc1
NSPR_VER := 4.8

ifeq ($(UNAME),SunOS)
PATCH ?= gpatch
else
PATCH ?= patch
endif

SYSTEM_DIR := $(CURDIR)/system
LIB_DIR := $(SYSTEM_DIR)/lib
INC_DIR := $(SYSTEM_DIR)/include
Expand All @@ -20,7 +27,7 @@ js: $(LIB_DIR)/libjs.a
$(LIB_DIR)/libjs.a: $(LIB_DIR)/libnspr4.a
$(GUNZIP) -c js-$(SMONKEY_VER).tar.gz | $(TAR) xf -
@for I in patches/js-*.patch; do \
(patch -p1 < $${I} || echo "Skipping patch"); \
($(PATCH) -p1 < $${I} || echo "Skipping patch"); \
done
@$(MAKE) -C $(JS_DIR)/src BUILD_OPT=1 JS_DIST=$(SYSTEM_DIR) \
JS_THREADSAFE=1 \
Expand All @@ -35,6 +42,9 @@ $(LIB_DIR)/libjs.a: $(LIB_DIR)/libnspr4.a

$(LIB_DIR)/libnspr4.a:
$(GUNZIP) -c nsprpub-$(NSPR_VER).tar.gz | $(TAR) xf -
@for I in patches/nspr-*.patch; do \
($(PATCH) -p1 < $${I} || echo "Skipping patch"); \
done
(cd $(NSPR_DIR) && \
./configure --disable-debug --enable-optimize \
--prefix=$(SYSTEM_DIR) $(NSPR_SIXTYFOUR) && \
Expand Down
97 changes: 97 additions & 0 deletions c_src/patches/js-src-config-DragonFly.mk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
--- c_src/js.orig/src/config/Dragonfly.mk 1969-12-31 19:00:00.000000000 -0500
+++ c_src/js/src/config/DragonFly.mk 2011-03-30 20:50:05.000000000 -0400
@@ -0,0 +1,94 @@
+# -*- Mode: makefile -*-
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is Mozilla Communicator client code, released
+# March 31, 1998.
+#
+# The Initial Developer of the Original Code is
+# Netscape Communications Corporation.
+# Portions created by the Initial Developer are Copyright (C) 1998
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+#
+# Config for FreeBSD/NetBSD/OpenBSD.
+#
+
+#CC = gcc
+#CCC = g++
+CFLAGS+= -Wall -Wno-format
+OS_CFLAGS= -DXP_UNIX -DSVR4
+OS_CFLAGS+= -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE # -DHAVE_LOCALTIME_R
+INTERP_CFLAGS+= `pkg-config --cflags-only-I nspr`
+
+RANLIB = echo
+MKSHLIB = $(LD) -lm `pkg-config --libs nspr` -shared $(LDFLAGS) $(XMKSHLIBOPTS)
+
+#.c.o:
+# $(CC) -c -MD $*.d $(CFLAGS) $<
+
+CPU_ARCH = $(shell uname -m)
+# don't filter in x86-64 architecture
+ifneq (amd64,$(CPU_ARCH))
+ifeq (86,$(findstring 86,$(CPU_ARCH)))
+CPU_ARCH = x86
+OS_CFLAGS+= -DX86_LINUX
+
+ifeq (gcc, $(CC))
+# if using gcc on x86, check version for opt bug
+# (http://bugzilla.mozilla.org/show_bug.cgi?id=24892)
+GCC_VERSION := $(shell gcc -v 2>&1 | grep version | awk '{ print $$3 }')
+GCC_LIST:=$(sort 2.91.66 $(GCC_VERSION) )
+ifeq (2.91.66, $(firstword $(GCC_LIST)))
+CFLAGS+= -DGCC_OPT_BUG
+endif
+endif
+endif
+endif
+
+GFX_ARCH = x
+
+OS_LIBS = -lm $(LDFLAGS)
+
+ASFLAGS += -x assembler-with-cpp
+
+
+ifeq ($(CPU_ARCH),alpha)
+
+# Ask the C compiler on alpha linux to let us work with denormalized
+# double values, which are required by the ECMA spec.
+
+OS_CFLAGS += -mieee
+endif
+
+JS_EDITLINE = 1
+
+OS_CFLAGS += -DHAVE_VA_COPY -DVA_COPY=va_copy
+OS_CFLAGS += -DPIC -fPIC -DJS_HAVE_LONG_LONG -DHAVE_INTTYPES_H
102 changes: 102 additions & 0 deletions c_src/patches/js-src-config-FreeBSD.mk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
--- c_src.orig/js/src/config/FreeBSD.mk 1969-12-31 19:00:00.000000000 -0500
+++ c_src/js/src/config/FreeBSD.mk 2011-03-30 20:12:51.000000000 -0400
@@ -0,0 +1,99 @@
+# -*- Mode: makefile -*-
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is Mozilla Communicator client code, released
+# March 31, 1998.
+#
+# The Initial Developer of the Original Code is
+# Netscape Communications Corporation.
+# Portions created by the Initial Developer are Copyright (C) 1998
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+#
+# Config for all versions of Linux
+#
+
+CC ?= gcc
+CCC ?= g++
+CFLAGS += -Wall -Wno-format
+OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R
+
+RANLIB = echo
+MKSHLIB = $(LD) -shared $(XMKSHLIBOPTS)
+
+#.c.o:
+# $(CC) -c -MD $*.d $(CFLAGS) $<
+
+CPU_ARCH = $(shell uname -m)
+# don't filter in x86-64 architecture
+ifneq (x86_64,$(CPU_ARCH))
+ifeq (86,$(findstring 86,$(CPU_ARCH)))
+CPU_ARCH = x86
+OS_CFLAGS+= -DX86_LINUX
+
+ifeq (gcc, $(CC))
+# if using gcc on x86, check version for opt bug
+# (http://bugzilla.mozilla.org/show_bug.cgi?id=24892)
+GCC_VERSION := $(shell gcc -v 2>&1 | grep version | awk '{ print $$3 }')
+GCC_LIST:=$(sort 2.91.66 $(GCC_VERSION) )
+
+ifeq (2.91.66, $(firstword $(GCC_LIST)))
+CFLAGS+= -DGCC_OPT_BUG
+endif
+endif
+endif
+endif
+
+GFX_ARCH = x
+
+OS_LIBS = -lm
+
+ASFLAGS += -x assembler-with-cpp
+
+
+ifeq ($(CPU_ARCH),alpha)
+
+# Ask the C compiler on alpha linux to let us work with denormalized
+# double values, which are required by the ECMA spec.
+
+OS_CFLAGS += -mieee
+endif
+
+# Use the editline library to provide line-editing support.
+JS_READLINE = 1
+
+OS_CFLAGS += -DHAVE_VA_COPY -DVA_COPY=va_copy
+
+ifeq ($(CPU_ARCH),sparc64)
+OS_CFLAGS += -DPIC -fPIC
+else
+OS_CFLAGS += -DPIC -fpic
+endif
Loading

0 comments on commit e1e0a76

Please sign in to comment.