build everything (including classes) in options-specific directory

Previously, we only built platform specific code in an
options-specific directory (e.g. build/linux-x86_64-debug), but built
the Java classes in the shared, top-level build directory.  This
minimized duplication when building with different sets of options,
but now that we're supporting the option of selecting a third-party
class library, we need to put the classes in the options-specific
directory as well.
This commit is contained in:
Joel Dice 2010-09-17 16:03:37 -06:00
parent d0d53e2e10
commit 20990950bb
2 changed files with 57 additions and 64 deletions

119
makefile
View File

@ -69,13 +69,12 @@ ifdef openjdk
openjdk-lib-dir = $(openjdk)/jre/lib openjdk-lib-dir = $(openjdk)/jre/lib
endif endif
classpath-jar = $(openjdk)/jre/lib/rt.jar classpath-jar = $(openjdk)/jre/lib/rt.jar
test-library-path = $(openjdk-lib-dir):$(native-build) test-library-path = $(openjdk-lib-dir):$(build)
test-executable = $(executable-dynamic) test-executable = $(executable-dynamic)
endif endif
root := $(shell (cd .. && pwd)) root := $(shell (cd .. && pwd))
build = build build = build/$(platform)-$(arch)$(options)
native-build = $(build)/$(platform)-$(arch)$(options)
classpath-build = $(build)/classpath classpath-build = $(build)/classpath
test-build = $(build)/test test-build = $(build)/test
src = src src = src
@ -87,8 +86,7 @@ ifneq ($(classpath),avian)
classpath-objects = $(shell find $(build)/classpath-objects -name "*.o") classpath-objects = $(shell find $(build)/classpath-objects -name "*.o")
else else
jni-sources := $(shell find $(classpath-src) -name '*.cpp') jni-sources := $(shell find $(classpath-src) -name '*.cpp')
jni-objects = \ jni-objects = $(call cpp-objects,$(jni-sources),$(classpath-src),$(build))
$(call cpp-objects,$(jni-sources),$(classpath-src),$(native-build))
endif endif
input = List input = List
@ -129,7 +127,7 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \
-Wno-non-virtual-dtor -Wno-non-virtual-dtor
common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \ common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \
"-I$(JAVA_HOME)/include" -idirafter $(src) -I$(native-build) \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(build) \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \
-DUSE_ATOMIC_OPERATIONS $(classpath-cflags) -DUSE_ATOMIC_OPERATIONS $(classpath-cflags)
@ -286,9 +284,8 @@ ifdef msvc
mt = "mt.exe" mt = "mt.exe"
cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \
-DUSE_ATOMIC_OPERATIONS \ -DUSE_ATOMIC_OPERATIONS \
-Fd$(native-build)/$(name).pdb -I"$(zlib)/include" -I$(src) \ -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \
-I"$(native-build)" -I"$(windows-java-home)/include" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32"
-I"$(windows-java-home)/include/win32"
shared = -dll shared = -dll
lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \
-DEFAULTLIB:zlib -MANIFEST -debug -DEFAULTLIB:zlib -MANIFEST -debug
@ -317,11 +314,11 @@ asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x))) java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x)))
generated-code = \ generated-code = \
$(native-build)/type-enums.cpp \ $(build)/type-enums.cpp \
$(native-build)/type-declarations.cpp \ $(build)/type-declarations.cpp \
$(native-build)/type-constructors.cpp \ $(build)/type-constructors.cpp \
$(native-build)/type-initializations.cpp \ $(build)/type-initializations.cpp \
$(native-build)/type-java-initializations.cpp $(build)/type-java-initializations.cpp
vm-depends := $(generated-code) $(wildcard $(src)/*.h) vm-depends := $(generated-code) $(wildcard $(src)/*.h)
@ -347,13 +344,13 @@ ifeq ($(process),compile)
vm-asm-sources += $(src)/compile-$(asm).S vm-asm-sources += $(src)/compile-$(asm).S
endif endif
vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(native-build)) vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(build))
vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(native-build)) vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(build))
vm-objects = $(vm-cpp-objects) $(vm-asm-objects) vm-objects = $(vm-cpp-objects) $(vm-asm-objects)
heapwalk-sources = $(src)/heapwalk.cpp heapwalk-sources = $(src)/heapwalk.cpp
heapwalk-objects = \ heapwalk-objects = \
$(call cpp-objects,$(heapwalk-sources),$(src),$(native-build)) $(call cpp-objects,$(heapwalk-sources),$(src),$(build))
ifeq ($(heapdump),true) ifeq ($(heapdump),true)
vm-sources += $(src)/heapdump.cpp vm-sources += $(src)/heapdump.cpp
@ -372,12 +369,12 @@ endif
bootimage-generator-sources = $(src)/bootimage.cpp bootimage-generator-sources = $(src)/bootimage.cpp
bootimage-generator-objects = \ bootimage-generator-objects = \
$(call cpp-objects,$(bootimage-generator-sources),$(src),$(native-build)) $(call cpp-objects,$(bootimage-generator-sources),$(src),$(build))
bootimage-generator = \ bootimage-generator = \
$(build)/$(bootimage-platform)-$(build-arch)$(options)/bootimage-generator $(build)/$(bootimage-platform)-$(build-arch)$(options)/bootimage-generator
bootimage-bin = $(native-build)/bootimage.bin bootimage-bin = $(build)/bootimage.bin
bootimage-object = $(native-build)/bootimage-bin.o bootimage-object = $(build)/bootimage-bin.o
ifeq ($(bootimage),true) ifeq ($(bootimage),true)
ifneq ($(build-arch),$(arch)) ifneq ($(build-arch),$(arch))
@ -398,31 +395,31 @@ else
endif endif
driver-source = $(src)/main.cpp driver-source = $(src)/main.cpp
driver-object = $(native-build)/main.o driver-object = $(build)/main.o
driver-dynamic-object = $(native-build)/main-dynamic.o driver-dynamic-object = $(build)/main-dynamic.o
boot-source = $(src)/boot.cpp boot-source = $(src)/boot.cpp
boot-object = $(native-build)/boot.o boot-object = $(build)/boot.o
generator-headers = $(src)/constants.h generator-headers = $(src)/constants.h
generator-sources = $(src)/type-generator.cpp generator-sources = $(src)/type-generator.cpp
generator-objects = \ generator-objects = \
$(call cpp-objects,$(generator-sources),$(src),$(native-build)) $(call cpp-objects,$(generator-sources),$(src),$(build))
generator = $(native-build)/generator generator = $(build)/generator
converter-objects = \ converter-objects = \
$(native-build)/binaryToObject-main.o \ $(build)/binaryToObject-main.o \
$(native-build)/binaryToObject-elf64.o \ $(build)/binaryToObject-elf64.o \
$(native-build)/binaryToObject-elf32.o \ $(build)/binaryToObject-elf32.o \
$(native-build)/binaryToObject-mach-o64.o \ $(build)/binaryToObject-mach-o64.o \
$(native-build)/binaryToObject-mach-o32.o \ $(build)/binaryToObject-mach-o32.o \
$(native-build)/binaryToObject-pe.o $(build)/binaryToObject-pe.o
converter = $(native-build)/binaryToObject converter = $(build)/binaryToObject
static-library = $(native-build)/lib$(name).a static-library = $(build)/lib$(name).a
executable = $(native-build)/$(name)${exe-suffix} executable = $(build)/$(name)${exe-suffix}
dynamic-library = $(native-build)/$(so-prefix)jvm$(so-suffix) dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix)
executable-dynamic = $(native-build)/$(name)-dynamic${exe-suffix} executable-dynamic = $(build)/$(name)-dynamic${exe-suffix}
ifneq ($(classpath),avian) ifneq ($(classpath),avian)
classpath-sources := \ classpath-sources := \
@ -451,7 +448,7 @@ endif
classpath-classes = \ classpath-classes = \
$(call java-classes,$(classpath-sources),$(classpath-src),$(classpath-build)) $(call java-classes,$(classpath-sources),$(classpath-src),$(classpath-build))
classpath-object = $(native-build)/classpath-jar.o classpath-object = $(build)/classpath-jar.o
classpath-dep = $(classpath-build).dep classpath-dep = $(classpath-build).dep
vm-classes = \ vm-classes = \
@ -520,20 +517,15 @@ clean:
@echo "removing build" @echo "removing build"
rm -rf build rm -rf build
.PHONY: clean-native $(build)/compile-x86-asm.o: $(src)/continuations-x86.S
clean-native:
@echo "removing $(native-build)"
rm -rf $(native-build)
$(native-build)/compile-x86-asm.o: $(src)/continuations-x86.S gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:')
gen-arg = $(shell echo $(1) | sed -e 's:$(native-build)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep) $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
@echo "generating $(@)" @echo "generating $(@)"
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(generator) $(classpath-build) $(call gen-arg,$(@)) < $(<) > $(@) $(generator) $(classpath-build) $(call gen-arg,$(@)) < $(<) > $(@)
$(native-build)/type-generator.o: \ $(build)/type-generator.o: \
$(generator-headers) $(generator-headers)
$(classpath-build)/%.class: $(classpath-src)/%.java $(classpath-build)/%.class: $(classpath-src)/%.java
@ -549,7 +541,8 @@ ifneq ($(classpath),avian)
endif endif
$(javac) -d $(classpath-build) \ $(javac) -d $(classpath-build) \
-bootclasspath $(classpath-build) \ -bootclasspath $(classpath-build) \
$(shell $(MAKE) -s --no-print-directory $(classpath-classes)) $(shell $(MAKE) -s --no-print-directory build=$(build) \
$(classpath-classes))
@touch $(@) @touch $(@)
$(test-build)/%.class: $(test)/%.java $(test-build)/%.class: $(test)/%.java
@ -558,7 +551,7 @@ $(test-build)/%.class: $(test)/%.java
$(test-dep): $(test-sources) $(test-dep): $(test-sources)
@echo "compiling test classes" @echo "compiling test classes"
@mkdir -p $(test-build) @mkdir -p $(test-build)
files="$(shell $(MAKE) -s --no-print-directory $(test-classes))"; \ files="$(shell $(MAKE) -s --no-print-directory build=$(build) $(test-classes))"; \
if test -n "$${files}"; then \ if test -n "$${files}"; then \
$(javac) -d $(test-build) -bootclasspath $(classpath-build) $${files}; \ $(javac) -d $(test-build) -bootclasspath $(classpath-build) $${files}; \
fi fi
@ -569,7 +562,7 @@ $(test-dep): $(test-sources)
$(test-extra-dep): $(test-extra-sources) $(test-extra-dep): $(test-extra-sources)
@echo "compiling extra test classes" @echo "compiling extra test classes"
@mkdir -p $(test-build) @mkdir -p $(test-build)
files="$(shell $(MAKE) -s --no-print-directory $(test-extra-classes))"; \ files="$(shell $(MAKE) -s --no-print-directory build=$(build) $(test-extra-classes))"; \
if test -n "$${files}"; then \ if test -n "$${files}"; then \
$(javac) -d $(test-build) -bootclasspath $(classpath-build) $${files}; \ $(javac) -d $(test-build) -bootclasspath $(classpath-build) $${files}; \
fi fi
@ -587,16 +580,16 @@ define compile-asm-object
$(as) -I$(src) $(asmflags) -c $(<) -o $(@) $(as) -I$(src) $(asmflags) -c $(<) -o $(@)
endef endef
$(vm-cpp-objects): $(native-build)/%.o: $(src)/%.cpp $(vm-depends) $(vm-cpp-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends)
$(compile-object) $(compile-object)
$(vm-asm-objects): $(native-build)/%-asm.o: $(src)/%.S $(vm-asm-objects): $(build)/%-asm.o: $(src)/%.S
$(compile-asm-object) $(compile-asm-object)
$(bootimage-generator-objects): $(native-build)/%.o: $(src)/%.cpp $(vm-depends) $(bootimage-generator-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends)
$(compile-object) $(compile-object)
$(heapwalk-objects): $(native-build)/%.o: $(src)/%.cpp $(vm-depends) $(heapwalk-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends)
$(compile-object) $(compile-object)
$(driver-object): $(driver-source) $(driver-object): $(driver-source)
@ -616,22 +609,22 @@ $(build)/classpath.jar: $(classpath-dep)
cd $(classpath-build) && \ cd $(classpath-build) && \
$(jar) c0f "$$($(native-path) "$${wd}/$(@)")" .) $(jar) c0f "$$($(native-path) "$${wd}/$(@)")" .)
$(native-build)/binaryToObject-main.o: $(src)/binaryToObject/main.cpp $(build)/binaryToObject-main.o: $(src)/binaryToObject/main.cpp
$(build-cxx) -c $(^) -o $(@) $(build-cxx) -c $(^) -o $(@)
$(native-build)/binaryToObject-elf64.o: $(src)/binaryToObject/elf.cpp $(build)/binaryToObject-elf64.o: $(src)/binaryToObject/elf.cpp
$(build-cxx) -DBITS_PER_WORD=64 -c $(^) -o $(@) $(build-cxx) -DBITS_PER_WORD=64 -c $(^) -o $(@)
$(native-build)/binaryToObject-elf32.o: $(src)/binaryToObject/elf.cpp $(build)/binaryToObject-elf32.o: $(src)/binaryToObject/elf.cpp
$(build-cxx) -DBITS_PER_WORD=32 -c $(^) -o $(@) $(build-cxx) -DBITS_PER_WORD=32 -c $(^) -o $(@)
$(native-build)/binaryToObject-mach-o64.o: $(src)/binaryToObject/mach-o.cpp $(build)/binaryToObject-mach-o64.o: $(src)/binaryToObject/mach-o.cpp
$(build-cxx) -DBITS_PER_WORD=64 -c $(^) -o $(@) $(build-cxx) -DBITS_PER_WORD=64 -c $(^) -o $(@)
$(native-build)/binaryToObject-mach-o32.o: $(src)/binaryToObject/mach-o.cpp $(build)/binaryToObject-mach-o32.o: $(src)/binaryToObject/mach-o.cpp
$(build-cxx) -DBITS_PER_WORD=32 -c $(^) -o $(@) $(build-cxx) -DBITS_PER_WORD=32 -c $(^) -o $(@)
$(native-build)/binaryToObject-pe.o: $(src)/binaryToObject/pe.cpp $(build)/binaryToObject-pe.o: $(src)/binaryToObject/pe.cpp
$(build-cxx) -c $(^) -o $(@) $(build-cxx) -c $(^) -o $(@)
$(converter): $(converter-objects) $(converter): $(converter-objects)
@ -642,13 +635,13 @@ $(classpath-object): $(build)/classpath.jar $(converter)
$(converter) $(<) $(@) _binary_classpath_jar_start \ $(converter) $(<) $(@) _binary_classpath_jar_start \
_binary_classpath_jar_end $(platform) $(arch) _binary_classpath_jar_end $(platform) $(arch)
$(generator-objects): $(native-build)/%.o: $(src)/%.cpp $(generator-objects): $(build)/%.o: $(src)/%.cpp
@echo "compiling $(@)" @echo "compiling $(@)"
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(build-cxx) -DPOINTER_SIZE=$(pointer-size) -O0 -g3 $(build-cflags) \ $(build-cxx) -DPOINTER_SIZE=$(pointer-size) -O0 -g3 $(build-cflags) \
-c $(<) -o $(@) -c $(<) -o $(@)
$(jni-objects): $(native-build)/%.o: $(classpath-src)/%.cpp $(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp
$(compile-object) $(compile-object)
$(static-library): $(classpath-object-dep) $(static-library): $(classpath-object-dep)
@ -727,7 +720,7 @@ $(dynamic-library): \
@echo "linking $(@)" @echo "linking $(@)"
ifdef msvc ifdef msvc
$(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \
-IMPLIB:$(native-build)/$(name).lib -MANIFESTFILE:$(@).manifest -IMPLIB:$(build)/$(name).lib -MANIFESTFILE:$(@).manifest
$(mt) -manifest $(@).manifest -outputresource:"$(@);2" $(mt) -manifest $(@).manifest -outputresource:"$(@);2"
else else
$(ld) $(^) -Wl,--version-script=openjdk.ld \ $(ld) $(^) -Wl,--version-script=openjdk.ld \
@ -738,11 +731,11 @@ endif
$(executable-dynamic): $(driver-dynamic-object) $(dynamic-library) $(executable-dynamic): $(driver-dynamic-object) $(dynamic-library)
@echo "linking $(@)" @echo "linking $(@)"
ifdef msvc ifdef msvc
$(ld) $(lflags) -LIBPATH:$(native-build) -DEFAULTLIB:$(name) \ $(ld) $(lflags) -LIBPATH:$(build) -DEFAULTLIB:$(name) \
-PDB:$(@).pdb -IMPLIB:$(@).lib $(<) -out:$(@) -MANIFESTFILE:$(@).manifest -PDB:$(@).pdb -IMPLIB:$(@).lib $(<) -out:$(@) -MANIFESTFILE:$(@).manifest
$(mt) -manifest $(@).manifest -outputresource:"$(@);1" $(mt) -manifest $(@).manifest -outputresource:"$(@);1"
else else
$(ld) $(<) -L$(native-build) -ljvm $(lflags) -o $(@) $(ld) $(<) -L$(build) -ljvm $(lflags) -o $(@)
endif endif
$(strip) $(strip-all) $(@) $(strip) $(strip-all) $(@)

View File

@ -246,7 +246,7 @@ VM object files and bootstrap classpath jar.
$ mkdir hello $ mkdir hello
$ cd hello $ cd hello
$ ar x ../build/${platform}-${arch}/libavian.a $ ar x ../build/${platform}-${arch}/libavian.a
$ cp ../build/classpath.jar boot.jar $ cp ../build/${platform}-${arch}/classpath.jar boot.jar
Step 2: Build the Java code and add it to the jar. Step 2: Build the Java code and add it to the jar.