build standalone executable (no seperate .so) on all platforms; build libvm.a too

This commit is contained in:
Joel Dice 2007-10-23 17:23:55 -06:00
parent 1c948652fd
commit 4dfcaa0f91

View File

@ -1,6 +1,6 @@
#MAKEFLAGS = -s #MAKEFLAGS = -s
input = $(cls)/Memory.class input = $(cls)/Hello.class
build-arch = $(shell uname -m) build-arch = $(shell uname -m)
ifeq ($(build-arch),i586) ifeq ($(build-arch),i586)
@ -24,7 +24,6 @@ process = interpret
mode = debug mode = debug
build-dir = build/$(build-platform)/$(build-arch)
bld = build/$(platform)/$(arch)/$(mode) bld = build/$(platform)/$(arch)/$(mode)
cls = build/classes cls = build/classes
src = src src = src
@ -36,6 +35,8 @@ build-cc = gcc
cxx = $(build-cxx) cxx = $(build-cxx)
cc = $(build-cc) cc = $(build-cc)
ar = ar
ranlib = ranlib
vg = nice valgrind --suppressions=valgrind.supp --undef-value-errors=no \ vg = nice valgrind --suppressions=valgrind.supp --undef-value-errors=no \
--num-callers=32 --db-attach=yes --freelist-vol=100000000 --num-callers=32 --db-attach=yes --freelist-vol=100000000
db = gdb --args db = gdb --args
@ -44,18 +45,17 @@ strip = :
show-size = : show-size = :
rdynamic = -rdynamic rdynamic = -rdynamic
thread-cflags = -pthread
shared = -shared shared = -shared
so-prefix = lib
so-extension = so
ld-library-path = LD_LIBRARY_PATH
warnings = -Wall -Wextra -Werror -Wunused-parameter \ warnings = -Wall -Wextra -Werror -Wunused-parameter \
-Winit-self -Wconversion -Winit-self -Wconversion
cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \ common-cflags = $(warnings) -fno-rtti -fno-exceptions \
-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(src) -I$(bld) \ -I$(JAVA_HOME)/include -idirafter $(src) -I$(bld) -D__STDC_LIMIT_MACROS \
$(thread-cflags) -D__STDC_LIMIT_MACROS -DBUILTIN_LIBRARIES=\"natives,tlscontext,scaler\"
cflags = $(common-cflags) -fPIC -fvisibility=hidden \
-I$(JAVA_HOME)/include/linux -I$(src) -pthread
lflags = -lpthread -ldl -lm -lz lflags = -lpthread -ldl -lm -lz
@ -66,8 +66,6 @@ ifeq ($(platform),darwin)
rdynamic = rdynamic =
thread-cflags = thread-cflags =
shared = -dynamiclib shared = -dynamiclib
so-extension = jnilib
ld-library-path = DYLD_LIBRARY_PATH
endif endif
ifeq ($(platform),windows) ifeq ($(platform),windows)
inc = ../6.0/shared/include/msw inc = ../6.0/shared/include/msw
@ -75,18 +73,15 @@ ifeq ($(platform),windows)
system = windows system = windows
cxx = i586-mingw32msvc-g++ cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc cc = i586-mingw32msvc-gcc
dlltool = i586-mingw32msvc-dlltool dlltool = i586-mingw32msvc-dlltool
ar = i586-mingw32msvc-ar
ranlib = i586-mingw32msvc-ranlib
rdynamic = -Wl,--export-dynamic rdynamic = -Wl,--export-dynamic
so-prefix = lflags = -L$(lib) -lm -lz -lws2_32 -Wl,--kill-at
so-extension = dll cflags = $(common-cflags) -I$(inc)
thread-cflags =
lflags = -L$(lib) -lm -lz -lws2_32 -Wl,--kill-at
cflags = $(warnings) -fno-rtti -fno-exceptions $(thread-cflags) \
-D__STDC_LIMIT_MACROS -DBUILTIN_LIBRARIES=\"natives\" \
-I$(bld) -I$(JAVA_HOME)/include -I$(inc) -idirafter $(src)
endif endif
ifeq ($(mode),debug) ifeq ($(mode),debug)
@ -105,9 +100,9 @@ ifeq ($(mode),fast)
endif endif
ifeq ($(arch),i386) ifeq ($(arch),i386)
pointer-size = 4 pointer-size = 4
else else
pointer-size = 8 pointer-size = 8
endif endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x))) cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x)))
@ -117,7 +112,6 @@ java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(cls)/%.class,$(x)))
jni-sources = $(shell find $(classpath) -name '*.cpp') jni-sources = $(shell find $(classpath) -name '*.cpp')
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(bld)) jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(bld))
jni-cflags = $(cflags) jni-cflags = $(cflags)
jni-library = $(bld)/$(so-prefix)natives.$(so-extension)
generated-code = \ generated-code = \
$(bld)/type-enums.cpp \ $(bld)/type-enums.cpp \
@ -168,16 +162,16 @@ generator-headers = \
$(src)/output.h $(src)/output.h
generator-sources = \ generator-sources = \
$(src)/type-generator.cpp $(src)/type-generator.cpp
generator-objects = $(call \ generator-objects = $(call cpp-objects,$(generator-sources),$(src),$(bld))
cpp-objects,$(generator-sources),$(src),$(build-dir)) generator-executable = $(bld)/generator
generator-executable = $(build-dir)/generator
archive = $(bld)/libvm.a
executable = $(bld)/vm executable = $(bld)/vm
classpath-sources = $(shell find $(classpath) -name '*.java') classpath-sources = $(shell find $(classpath) -name '*.java')
classpath-classes = $(call java-classes,$(classpath-sources),$(classpath)) classpath-classes = $(call java-classes,$(classpath-sources),$(classpath))
classpath-objects = $(classpath-classes) $(jni-library) classpath-objects = $(classpath-classes)
test-sources = $(shell find $(test) -name '*.java') test-sources = $(shell find $(test) -name '*.java')
test-classes = $(call java-classes,$(test-sources),$(test)) test-classes = $(call java-classes,$(test-sources),$(test))
@ -195,19 +189,19 @@ $(input): $(classpath-classes)
.PHONY: run .PHONY: run
run: build run: build
$(ld-library-path)=$(bld) $(executable) $(args) $(executable) $(args)
.PHONY: debug .PHONY: debug
debug: build debug: build
$(ld-library-path)=$(bld) gdb --args $(executable) $(args) gdb --args $(executable) $(args)
.PHONY: vg .PHONY: vg
vg: build vg: build
$(ld-library-path)=$(bld) $(vg) $(executable) $(args) $(vg) $(executable) $(args)
.PHONY: test .PHONY: test
test: test: build
$(ld-library-path)=$(bld) /bin/bash $(test)/test.sh 2>/dev/null \ /bin/bash $(test)/test.sh 2>/dev/null \
$(executable) $(mode) "$(flags)" $(call class-names,$(test-classes)) $(executable) $(mode) "$(flags)" $(call class-names,$(test-classes))
.PHONY: clean .PHONY: clean
@ -217,8 +211,8 @@ clean:
.PHONY: clean-native .PHONY: clean-native
clean-native: clean-native:
@echo "removing $(bld) and $(build-dir)" @echo "removing $(bld)"
rm -rf $(bld) $(build-dir) rm -rf $(bld)
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:') gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator-executable) $(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@ -226,7 +220,7 @@ $(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@mkdir -p -m 1777 $(dir $(@)) @mkdir -p -m 1777 $(dir $(@))
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@) $(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
$(build-dir)/type-generator.o: \ $(bld)/type-generator.o: \
$(generator-headers) $(generator-headers)
define compile-class define compile-class
@ -255,7 +249,7 @@ $(interpreter-cpp-objects): $(bld)/%.o: $(src)/%.cpp $(interpreter-depends)
$(interpreter-asm-objects): $(bld)/%-asm.o: $(src)/%.S $(interpreter-asm-objects): $(bld)/%-asm.o: $(src)/%.S
$(compile-object) $(compile-object)
$(generator-objects): $(build-dir)/%.o: $(src)/%.cpp $(generator-objects): $(bld)/%.o: $(src)/%.cpp
@echo "compiling $(@)" @echo "compiling $(@)"
@mkdir -p -m 1777 $(dir $(@)) @mkdir -p -m 1777 $(dir $(@))
$(build-cxx) -DPOINTER_SIZE=$(pointer-size) $(cflags) -c $(<) -o $(@) $(build-cxx) -DPOINTER_SIZE=$(pointer-size) $(cflags) -c $(<) -o $(@)
@ -265,25 +259,26 @@ $(jni-objects): $(bld)/%.o: $(classpath)/%.cpp
@mkdir -p -m 1777 $(dir $(@)) @mkdir -p -m 1777 $(dir $(@))
$(cxx) $(jni-cflags) -c $(<) -o $(@) $(cxx) $(jni-cflags) -c $(<) -o $(@)
$(jni-library): $(jni-objects)
@echo "linking $(@)"
$(cc) $(^) $(lflags) $(shared) -o $(@)
ifeq ($(platform),windows) ifeq ($(platform),windows)
$(executable): $(interpreter-objects) $(jni-objects) $(archive): $(interpreter-objects) $(jni-objects)
@echo "linking $(@)" @echo "creating $(@)"
$(dlltool) --export-all-symbols -z $(@).def $(^) $(dlltool) --export-all-symbols -z $(@).def $(^)
$(dlltool) -k -d $(@).def -e $(@).exp $(dlltool) -k -d $(@).def -e $(@).exp
$(cc) $(^) $(lflags) $(@).exp -o $(@) $(ar) cru $(@) $(@).exp $(^)
@$(strip) --strip-all $(@) $(ranlib) $(@)
@$(show-size) $(@)
else else
$(executable): $(interpreter-objects) $(archive): $(interpreter-objects) $(jni-objects)
@echo "creating $(@)"
$(ar) cru $(@) $(^)
$(ranlib) $(@)
endif
$(executable): $(archive)
@echo "linking $(@)" @echo "linking $(@)"
$(cc) $(^) $(lflags) $(rdynamic) -o $(@) $(cc) -Wl,--whole-archive $(^) -Wl,--no-whole-archive \
$(lflags) $(rdynamic) -o $(@)
@$(strip) --strip-all $(@) @$(strip) --strip-all $(@)
@$(show-size) $(@) @$(show-size) $(@)
endif
$(generator-executable): $(generator-objects) $(generator-executable): $(generator-objects)
@echo "linking $(@)" @echo "linking $(@)"