Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
First cut of a cross-compilation process so we can build for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewd committed Apr 23, 2008
1 parent 02a2b51 commit 1524e73
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 13 deletions.
124 changes: 124 additions & 0 deletions MINGW32.mk
@@ -0,0 +1,124 @@
# -*- Mode: makefile -*-
#
#
# Based on patch submitted to mozilla.dev.tech.js-engine by 'Andy':
# http://groups.google.com/group/mozilla.dev.tech.js-engine/browse_thread/thread/16972946bf7df82e
#
#
# ***** 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 Mingw (copy and modified from Linux)
#

AR = i586-mingw32msvc-ar
CC = i586-mingw32msvc-gcc
LD = i586-mingw32msvc-ld
CCC = i586-mingw32msvc-g++

CFLAGS += -Wall -Wno-format
#OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DEXPORT_JS_API
OS_CFLAGS = -D_X86_=1 -DXP_WIN -DXP_WIN32 -DWIN32 -D_WINDOWS -D_WIN32 $(WIN_CFLAGS) -DEXPORT_JS_API
JSDLL_CFLAGS = -DEXPORT_JS_API # not work, dunno why?
SO_SUFFIX = dll
# libgcc.a:__divdi3 kernel32:DebugBreak,GetSystemTimeAsFileTime
# winmm:timeBeginPeriod,timeEndPeriod
WINLIBS = -lmsvcrt -lm -lkernel32 -lwinmm /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/libgcc.a
#LDFLAGS += $(WINLIBS) # dont work. rewrite by Makefile.ref
OTHER_LIBS += $(WINLIBS)

RANLIB = echo
MKSHLIB = $(LD) -shared $(XMKSHLIBOPTS)

# These don't work :(
LIBRARY = $(OBJDIR)/js32.lib
SHARED_LIBRARY = $(OBJDIR)/js32.dll
PROGRAM = $(OBJDIR)/js.exe

#.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 -lc

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_EDITLINE = 1 // not support by Mingw

ifeq ($(CPU_ARCH),x86_64)
# Use VA_COPY() standard macro on x86-64
# FIXME: better use it everywhere
OS_CFLAGS += -DHAVE_VA_COPY
endif

ifeq ($(CPU_ARCH),x86_64)
# We need PIC code for shared libraries
# FIXME: better patch rules.mk & fdlibm/Makefile*
OS_CFLAGS += -DPIC -fPIC
endif
39 changes: 31 additions & 8 deletions Rakefile
Expand Up @@ -33,27 +33,50 @@ end
Rake::Task[:test].prerequisites << :extensions
Rake::Task[:check_manifest].prerequisites << GENERATED_NODE

task :build => :extensions

# gem depends on the native extension actually building
Rake::Task[:gem].prerequisites << :extensions

desc "Our johnson requires extensions."
task :extensions => [:submodules, "lib/johnson/spidermonkey.#{kind}"]
task :extensions => ["lib/johnson/spidermonkey.#{kind}"]

task :spidermonkey => :submodules do
if ENV['CROSS']
Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref OS_CONFIG=#{ENV['CROSS']}" }
else
Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref" }
end
end
task :spidermonkey => "vendor/spidermonkey/config/#{ENV['CROSS']}.mk" if ENV['CROSS']

file "vendor/spidermonkey/config/MINGW32.mk" => "MINGW32.mk" do |t|
File.copy(t.prerequisites.first, t.name)
end

task :submodules do
sh "git submodule init && git submodule update"
end

# for testing, we toss the SpiderMonkey extension in lib/johnson
file "lib/johnson/spidermonkey.#{kind}" =>
FileList["ext/spidermonkey/Makefile", "ext/spidermonkey/*.{c,h}"] do
file "ext/spidermonkey/spidermonkey.#{kind}" =>
["ext/spidermonkey/Makefile"] + FileList["ext/spidermonkey/*.{c,h}"].to_a do

Dir.chdir("ext/spidermonkey") { sh "make" }
sh "cp ext/spidermonkey/spidermonkey.#{kind} lib/johnson/spidermonkey.#{kind}"
end

# for testing, we toss the SpiderMonkey extension in lib/johnson
file "lib/johnson/spidermonkey.#{kind}" =>
"ext/spidermonkey/spidermonkey.#{kind}" do |t|

File.copy(t.prerequisites.first, t.name)
end

file "ext/spidermonkey/Makefile" =>
[GENERATED_NODE, "ext/spidermonkey/extconf.rb"] do
Dir.chdir("ext/spidermonkey") { ruby "extconf.rb" }
[:spidermonkey, GENERATED_NODE, "ext/spidermonkey/extconf.rb"] do

dirs = (ENV['CROSS'] ? [ENV["CROSSLIB"]] : []) + $:
command = ["ruby"] + dirs.map{|dir| "-I#{File.expand_path dir}"} + ["extconf.rb"]
Dir.chdir("ext/spidermonkey") { sh *command }
end

def jsops
Expand Down Expand Up @@ -81,7 +104,7 @@ def tokens
toks.uniq
end

file GENERATED_NODE => "ext/spidermonkey/immutable_node.c.erb" do |t|
file GENERATED_NODE => ["ext/spidermonkey/immutable_node.c.erb", "vendor/spidermonkey/jsopcode.tbl", "vendor/spidermonkey/jsscan.h"] do |t|
template = ERB.new(File.open(t.prerequisites.first, 'rb') { |x| x.read })
File.open(GENERATED_NODE, 'wb') { |f|
f.write template.result(binding)
Expand Down
31 changes: 31 additions & 0 deletions cross-compile.txt
@@ -0,0 +1,31 @@

CROSS-COMPILING FOR WINDOWS

Based on http://eigenclass.org/hiki.rb?cross+compiling+rcovrt


*) Download & extract a ruby tar.gz

*) Double the backslashes in the ALT_SEPARATOR definition in Makefile.in

*) Build & install it:

env ac_cv_func_getpgrp_void=no \
ac_cv_func_setpgrp_void=yes \
rb_cv_negative_time_t=no \
ac_cv_func_memcmp_working=yes \
rb_cv_binary_elf=no \
./configure \
--host=i586-mingw32msvc \
--target=i386-mingw32 \
--build=i686-linux \
--prefix=~/ruby-mingw32

make ruby

make install

*) Build the extension (rake will build spidermonkey for you)

rake build CROSS=MINGW32 CROSSLIB=~/ruby-mingw32/lib/ruby/1.8/i386-mingw32

12 changes: 7 additions & 5 deletions ext/spidermonkey/extconf.rb
Expand Up @@ -3,14 +3,16 @@

require "mkmf"

$CFLAGS << " -g -DXP_UNIX"
if Config::CONFIG['target_os'] == 'mingw32'
$libs = append_library($libs, "winmm")
$CFLAGS << " -DXP_WIN -DXP_WIN32"
else
$CFLAGS << " -g -DXP_UNIX"
end

spidermonkey_base_dir = "../../vendor/spidermonkey"

# we can't even run the extconf unless Spidermonkey has built
Dir.chdir(spidermonkey_base_dir) { system "make -f Makefile.ref" }

spidermonkey_obj_dir = Dir[spidermonkey_base_dir + "/*.OBJ"].first
spidermonkey_obj_dir = Dir[spidermonkey_base_dir + "/#{ENV['CROSS'] || ''}*.OBJ"].first

dir_config("johnson/spidermonkey")

Expand Down

0 comments on commit 1524e73

Please sign in to comment.