This allows Jato to be built on x86-64 as a 32-bit executable:

$ make ARCH=i386

One might also have to supply a suitable LIBS so the linker can locate
the various binutils 32-bit libraries.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro>
---
 Makefile               |   43 ++++++++++++++++++++++++++++---------------
 monoburg/Makefile      |   18 +++++++++---------
 scripts/build/test.mk  |   10 +++++-----
 test/arch-x86/Makefile |    6 +++---
 4 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/Makefile b/Makefile
index 96bf4c2..340b8f2 100644
--- a/Makefile
+++ b/Makefile
@@ -6,13 +6,24 @@ CLASSPATH_INSTALL_DIR ?= $(shell ./tools/classpath-config)
 GLIBJ          = $(CLASSPATH_INSTALL_DIR)/share/classpath/glibj.zip
 BOOTCLASSPATH  = lib/classes.zip:$(GLIBJ)
 
-JAMVM_ARCH     := $(shell uname -m | sed -e s/i.86/i386/ | sed -e 
s/ppc/powerpc/)
-ARCH           := $(shell uname -m | sed -e s/i.86/i386/)
+BUILD_ARCH     := $(shell uname -m | sed -e s/i.86/i386/)
+ARCH           := $(BUILD_ARCH)
+JAMVM_ARCH     := $(shell echo "$(ARCH)" | sed -e s/ppc/powerpc/)
 OS             := $(shell uname -s | tr "[:upper:]" "[:lower:]")
 
+ifneq ($(ARCH),$(BUILD_ARCH))
+TEST           =
+else
+TEST           = test
+endif
+
 ifeq ($(ARCH),i386)
 override ARCH  = x86
 ARCH_POSTFIX   = _32
+ifeq ($(BUILD_ARCH),x86_64)
+ARCH_CFLAGS    += -m32
+TEST           = test
+endif
 endif
 
 ifeq ($(ARCH),x86_64)
@@ -25,6 +36,8 @@ override ARCH = ppc
 ARCH_POSTFIX   = _32
 endif
 
+export ARCH_CFLAGS
+
 ARCH_CONFIG=arch/$(ARCH)/include/arch/config$(ARCH_POSTFIX).h
 
 # Make the build silent by default
@@ -121,25 +134,25 @@ CC                := gcc
 MONOBURG       := ./monoburg/monoburg
 JAVAC          := ecj
 
-CFLAGS         += -g -Wall -rdynamic -std=gnu99
+DEFAULT_CFLAGS += $(ARCH_CFLAGS) -g -Wall -rdynamic -std=gnu99
 
 WARNINGS       = -Wsign-compare -Wundef
-CFLAGS         += $(WARNINGS)
+DEFAULT_CFLAGS += $(WARNINGS)
 
 OPTIMIZATIONS  += -Os
-CFLAGS         += $(OPTIMIZATIONS)
+DEFAULT_CFLAGS += $(OPTIMIZATIONS)
 
 INCLUDES       = -Iinclude -Iarch/$(ARCH)/include -Ijit -Ijamvm -Ijit/glib 
-include $(ARCH_CONFIG)
-CFLAGS         += $(INCLUDES)
+DEFAULT_CFLAGS += $(INCLUDES)
 
 DEFINES = -DINSTALL_DIR=\"$(JAMVM_INSTALL_DIR)\" 
-DCLASSPATH_INSTALL_DIR=\"$(CLASSPATH_INSTALL_DIR)\"
-CFLAGS         += $(DEFINES)
+DEFAULT_CFLAGS += $(DEFINES)
 
-LIBS           = -lpthread -lm -ldl -lz -lbfd -lopcodes -liberty $(ARCH_LIBS)
+DEFAULT_LIBS   = -lpthread -lm -ldl -lz -lbfd -lopcodes -liberty $(ARCH_LIBS)
 
 JAMVM_ARCH_H = include/vm/arch.h
 
-all: $(PROGRAM) test
+all: $(PROGRAM) $(TEST)
 .PHONY: all
 .DEFAULT: all
 
@@ -153,8 +166,8 @@ monoburg:
 
 %.o: %.c
        $(E) "  CC      " $@
-       $(Q) $(CC) -c $(CFLAGS) $< -o $@
-       $(Q) $(CC) -MM $(CFLAGS) -MT $@ $*.c -o $*.d
+       $(Q) $(CC) -c $(DEFAULT_CFLAGS) $(CFLAGS) $< -o $@
+       $(Q) $(CC) -MM $(DEFAULT_CFLAGS) $(CFLAGS) -MT $@ $*.c -o $*.d
 
 %.o: %.S
        $(E) "  AS      " $@
@@ -170,14 +183,14 @@ arch/$(ARCH)/insn-selector$(ARCH_POSTFIX).c: FORCE
 
 $(PROGRAM): lib monoburg $(JAMVM_ARCH_H) compile
        $(E) "  CC      " $@
-       $(Q) $(CC) $(CFLAGS) $(OBJS) -o $(PROGRAM) $(LIBS)
+       $(Q) $(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(OBJS) -o $(PROGRAM) $(LIBS) 
$(DEFAULT_LIBS)
 
 compile: $(OBJS)
 
 test: $(JAMVM_ARCH_H) monoburg
-       make -C test/vm/ ARCH=$(ARCH) ARCH_POSTFIX=$(ARCH_POSTFIX) test
-       make -C test/jit/ ARCH=$(ARCH) ARCH_POSTFIX=$(ARCH_POSTFIX) test
-       make -C test/arch-$(ARCH)/ ARCH_POSTFIX=$(ARCH_POSTFIX) test
+       make -C test/vm/ ARCH=$(ARCH) ARCH_POSTFIX=$(ARCH_POSTFIX) $(TEST)
+       make -C test/jit/ ARCH=$(ARCH) ARCH_POSTFIX=$(ARCH_POSTFIX) $(TEST)
+       make -C test/arch-$(ARCH)/ ARCH=$(ARCH) ARCH_POSTFIX=$(ARCH_POSTFIX) 
$(TEST)
 .PHONY: test
 
 %.class: %.java
diff --git a/monoburg/Makefile b/monoburg/Makefile
index e2fd4b0..4a4a7ff 100644
--- a/monoburg/Makefile
+++ b/monoburg/Makefile
@@ -8,22 +8,22 @@ OBJS = \
 
 CC = gcc
 
-CFLAGS         += -Wall -g -rdynamic -Werror -std=gnu99
+DEFAULT_CFLAGS += -Wall -g -rdynamic -Werror -std=gnu99
 
 WARNINGS       = -Wundef
-CFLAGS         += $(WARNINGS)
+DEFAULT_CFLAGS += $(WARNINGS)
 
 OPTIMIZATIONS  = -Os
-CFLAGS         += $(OPTIMIZATIONS)
+DEFAULT_CFLAGS += $(OPTIMIZATIONS)
 
 DEFINES                = -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0
-CFLAGS         += $(DEFINES)
+DEFAULT_CFLAGS += $(DEFINES)
 
 INCLUDES       = -I. -I..
-CFLAGS         += $(INCLUDES)
+DEFAULT_CFLAGS += $(INCLUDES)
 
-CFLAGS         += $(shell pkg-config --cflags glib-2.0)
-LIBS           += $(shell pkg-config --libs glib-2.0)
+DEFAULT_CFLAGS += $(shell pkg-config --cflags glib-2.0)
+DEFAULT_LIBS   += $(shell pkg-config --libs glib-2.0)
 
 ifeq ($(strip $(V)),)
        E = @echo
@@ -42,11 +42,11 @@ $(OBJS):
 
 $(PROGRAM): $(OBJS)
        $(E) "  CC      " $@
-       $(Q) $(CC) $(CFLAGS) $(OBJS) -o $@ $(LIBS)
+       $(Q) $(CC) $(DEFAULT_CFLAGS) $(CFLAGS) $(OBJS) -o $@ $(LIBS) 
$(DEFAULT_LIBS)
 
 %.o: %.c
        $(E) "  CC      " $@
-       $(Q) $(CC) -c $(CFLAGS) $< -o $@
+       $(Q) $(CC) -c $(DEFAULT_CFLAGS) $(CFLAGS) $< -o $@
 
 parser.c: monoburg.y
        $(E) "  BISON   " $@
diff --git a/scripts/build/test.mk b/scripts/build/test.mk
index 03d46ab..e3f1b1a 100644
--- a/scripts/build/test.mk
+++ b/scripts/build/test.mk
@@ -1,8 +1,8 @@
 ARCH_CONFIG=../../arch/$(ARCH)/include/arch/config$(ARCH_POSTFIX).h
 
-CFLAGS ?= -rdynamic -g -Wall -Wundef -Wsign-compare -Os -std=gnu99
-INCLUDE        ?= -I../include/ -I. -I../libharness -I../../include 
-I../../jit/glib -include $(ARCH_CONFIG)
-LIBS   ?= -lpthread -lm -ldl -lz -lbfd -lopcodes -liberty
+DEFAULT_CFLAGS ?= -rdynamic -g -Wall -Wundef -Wsign-compare -Os -std=gnu99
+INCLUDE                ?= -I../include/ -I. -I../libharness -I../../include 
-I../../jit/glib -include $(ARCH_CONFIG)
+DEFAULT_LIBS   ?= -lpthread -lm -ldl -lz -lbfd -lopcodes -liberty
 
 ifdef TESTS
        TESTS_C = $(TESTS:.o=.c)
@@ -12,13 +12,13 @@ endif
 
 %.o: %.c
        $(E) "  CC      " $@
-       $(Q) $(CC) $(CFLAGS) $(INCLUDE) $(DEFINES) -c $< -o `basename $...@`
+       $(Q) $(CC) $(ARCH_CFLAGS) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDE) 
$(DEFINES) -c $< -o `basename $...@`
 
 test: $(RUNNER)
 
 $(RUNNER): $(SUITE) $(OBJS)
        $(E) "  LD      " $@
-       $(Q) $(CC) $(CFLAGS) $(INCLUDE) *.o $(SUITE) -o $(RUNNER) $(LIBS)
+       $(Q) $(CC) $(ARCH_CFLAGS) $(DEFAULT_CFLAGS) $(CFLAGS) $(INCLUDE) *.o 
$(SUITE) -o $(RUNNER) $(LIBS) $(DEFAULT_LIBS)
        $(E) "  RUN     " $@
        $(Q) ./$(RUNNER)
 
diff --git a/test/arch-x86/Makefile b/test/arch-x86/Makefile
index b113baa..fa5ece2 100644
--- a/test/arch-x86/Makefile
+++ b/test/arch-x86/Makefile
@@ -1,5 +1,5 @@
-ARCH           := $(shell uname -m | sed -e s/i.86/i386/)
-OS             := $(shell uname -s | tr "[:upper:]" "[:lower:]")
+ARCH           ?= $(shell uname -m | sed -e s/i.86/i386/)
+OS             ?= $(shell uname -s | tr "[:upper:]" "[:lower:]")
 
 ifeq ($(ARCH),i386)
 ARCH           = x86
@@ -12,7 +12,7 @@ ARCH_POSTFIX  = _64
 endif
 
 ARCH_CONFIG    := ../../arch/$(ARCH)/include/arch/config$(ARCH_POSTFIX).h
-CFLAGS         := -rdynamic -g -Wall -Wundef -Wsign-compare -Os -std=gnu99
+DEFAULT_CFLAGS := -rdynamic -g -Wall -Wundef -Wsign-compare -Os -std=gnu99
 INCLUDE                := -I. -I../../arch/$(ARCH)/include -I../libharness 
-I../jit -I../../include -I../include -I../../jit/glib -include $(ARCH_CONFIG) 
 MONOBURG       := ../../monoburg/monoburg
 
-- 
1.6.0.6


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to