corda/makefile

339 lines
7.8 KiB
Makefile
Raw Normal View History

2008-01-08 22:05:56 +00:00
MAKEFLAGS = -s
name = vm
build-arch = $(shell uname -m)
ifeq ($(build-arch),i586)
build-arch = i386
2007-06-29 16:43:25 +00:00
endif
ifeq ($(build-arch),i686)
build-arch = i386
2007-06-29 16:43:25 +00:00
endif
2007-06-29 16:42:39 +00:00
build-platform = $(shell uname -s | tr [:upper:] [:lower:])
2007-09-21 14:16:43 +00:00
arch = $(build-arch)
platform = $(build-platform)
2007-10-26 21:02:39 +00:00
ifeq ($(platform),windows)
arch = i386
endif
2007-09-25 23:53:11 +00:00
mode = fast
2008-01-03 19:49:42 +00:00
process = compile
build = build
2008-01-03 19:49:42 +00:00
native-build = $(build)/$(platform)-$(arch)-$(process)-$(mode)
classpath-build = $(build)/classpath
test-build = $(build)/test
src = src
2007-06-25 01:34:07 +00:00
classpath = classpath
test = test
input = List
build-cxx = g++
build-cc = gcc
2007-07-17 01:55:49 +00:00
cxx = $(build-cxx)
cc = $(build-cc)
ar = ar
ranlib = ranlib
objcopy = objcopy
2008-01-04 02:17:42 +00:00
vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000
2007-12-11 21:26:59 +00:00
vg += --leak-check=full
db = gdb --args
2007-06-21 01:38:02 +00:00
javac = javac
jar = jar
strip = :
strip-all = --strip-all
rdynamic = -rdynamic
warnings = -Wall -Wextra -Werror -Wunused-parameter \
-Winit-self -Wconversion
common-cflags = $(warnings) -fno-rtti -fno-exceptions \
-I$(JAVA_HOME)/include -idirafter $(src) -I$(native-build) \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_
2007-10-26 14:34:54 +00:00
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
2007-10-26 22:16:47 +00:00
-I$(JAVA_HOME)/include/linux -I$(src) -pthread
2007-10-26 14:34:54 +00:00
cflags = $(build-cflags)
2007-10-26 21:02:39 +00:00
common-lflags = -lm -lz
2007-10-26 22:16:47 +00:00
lflags = $(common-lflags) -lpthread -ldl -rdynamic
2007-10-26 14:34:54 +00:00
system = posix
2007-10-23 01:00:57 +00:00
asm = x86
2007-10-26 21:02:39 +00:00
object-arch = i386:x86-64
object-format = elf64-x86-64
pointer-size = 8
ifeq ($(arch),i386)
object-arch = i386
object-format = elf32-i386
pointer-size = 4
endif
ifeq ($(platform),darwin)
2007-10-26 22:16:47 +00:00
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
-I$(JAVA_HOME)/include/linux -I$(src)
lflags = $(common-lflags) -ldl -framework CoreFoundation
2007-11-01 20:37:51 +00:00
strip-all = -S -x
binaryToMacho = $(native-build)/binaryToMacho
endif
2007-10-26 21:02:39 +00:00
ifeq ($(platform),windows)
inc = /usr/local/win32/include
lib = /usr/local/win32/lib
system = windows
2007-10-26 21:02:39 +00:00
object-format = pe-i386
cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc
dlltool = i586-mingw32msvc-dlltool
ar = i586-mingw32msvc-ar
ranlib = i586-mingw32msvc-ranlib
objcopy = i586-mingw32msvc-objcopy
rdynamic = -Wl,--export-dynamic
2007-10-26 21:02:39 +00:00
lflags = -L$(lib) $(common-lflags) -lws2_32 -Wl,--kill-at -mwindows -mconsole
cflags = $(common-cflags) -I$(inc)
endif
ifeq ($(mode),debug)
2007-12-11 21:26:59 +00:00
cflags += -O0 -g3
endif
2008-01-12 00:15:34 +00:00
ifeq ($(mode),debug-fast)
cflags += -O0 -g3 -DNDEBUG
endif
ifeq ($(mode),stress)
2007-12-16 22:41:07 +00:00
cflags += -O0 -g3 -DVM_STRESS
endif
ifeq ($(mode),stress-major)
2007-12-16 22:41:07 +00:00
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
endif
ifeq ($(mode),fast)
cflags += -O3 -g3 -DNDEBUG
strip = strip
endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x)))
asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x)))
jni-sources = $(shell find $(classpath) -name '*.cpp')
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(native-build))
2007-06-25 01:34:07 +00:00
generated-code = \
$(native-build)/type-enums.cpp \
$(native-build)/type-declarations.cpp \
$(native-build)/type-constructors.cpp \
$(native-build)/type-initializations.cpp \
$(native-build)/type-java-initializations.cpp
2007-07-06 23:50:26 +00:00
vm-depends = \
$(generated-code) \
$(src)/allocator.h \
$(src)/common.h \
$(src)/system.h \
2007-06-04 23:39:59 +00:00
$(src)/heap.h \
$(src)/finder.h \
$(src)/processor.h \
$(src)/process.h \
$(src)/stream.h \
$(src)/constants.h \
2007-07-06 23:50:26 +00:00
$(src)/jnienv.h \
2007-11-26 23:15:53 +00:00
$(src)/machine.h \
$(src)/util.h \
$(src)/zone.h
2007-07-06 23:50:26 +00:00
vm-sources = \
$(src)/$(system).cpp \
$(src)/finder.cpp \
2007-07-06 23:50:26 +00:00
$(src)/machine.cpp \
2007-11-26 23:15:53 +00:00
$(src)/util.cpp \
2007-06-20 19:20:25 +00:00
$(src)/heap.cpp \
2007-09-25 23:53:11 +00:00
$(src)/$(process).cpp \
$(src)/builtin.cpp \
$(src)/jnienv.cpp \
$(src)/process.cpp
2007-06-29 02:58:48 +00:00
vm-asm-sources = $(src)/$(asm).S
ifeq ($(process),compile)
vm-depends += \
2007-12-09 22:45:43 +00:00
$(src)/compiler.h \
$(src)/vector.h
vm-sources += $(src)/compiler.cpp
2007-12-09 22:45:43 +00:00
vm-asm-sources += $(src)/compile.S
endif
2007-06-29 02:58:48 +00:00
vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(native-build))
vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(native-build))
vm-objects = $(vm-cpp-objects) $(vm-asm-objects)
driver-sources = $(src)/main.cpp
2007-10-26 14:34:54 +00:00
driver-object = $(call cpp-objects,$(driver-sources),$(src),$(native-build))
generator-headers = $(src)/constants.h
generator-sources = $(src)/type-generator.cpp
generator-objects = \
$(call cpp-objects,$(generator-sources),$(src),$(native-build))
generator = $(native-build)/generator
libvm = $(native-build)/lib$(name).a
vm = $(native-build)/$(name)
2007-06-30 02:39:01 +00:00
classpath-sources = $(shell find $(classpath) -name '*.java')
classpath-classes = \
$(call java-classes,$(classpath-sources),$(classpath),$(classpath-build))
classpath-object = $(native-build)/classpath-jar.o
classpath-dep = $(classpath-build)/dep
2007-10-28 01:54:30 +00:00
test-sources = $(wildcard $(test)/*.java)
test-classes = $(call java-classes,$(test-sources),$(test),$(test-build))
test-dep = $(test-build)/dep
class-name = $(patsubst $(1)/%.class,%,$(2))
2007-10-28 01:54:30 +00:00
class-names = $(foreach x,$(2),$(call class-name,$(1),$(x)))
flags = -cp $(test-build)
args = $(flags) $(input)
2007-06-21 01:38:02 +00:00
.PHONY: build
build: $(vm) $(libvm) $(classpath-dep) $(test-dep)
$(test-classes): $(classpath-dep)
2007-06-21 01:38:02 +00:00
.PHONY: run
2007-09-30 16:32:17 +00:00
run: build
$(vm) $(args)
.PHONY: debug
2007-09-30 16:32:17 +00:00
debug: build
gdb --args $(vm) $(args)
.PHONY: vg
2007-09-30 16:32:17 +00:00
vg: build
$(vg) $(vm) $(args)
.PHONY: test
test: build
/bin/bash $(test)/test.sh 2>/dev/null \
$(vm) $(mode) "$(flags)" \
2007-10-28 01:54:30 +00:00
$(call class-names,$(test-build),$(test-classes))
.PHONY: clean
clean:
2007-06-29 16:42:39 +00:00
@echo "removing build"
rm -rf build
.PHONY: clean-native
clean-native:
@echo "removing $(native-build)"
rm -rf $(native-build)
gen-arg = $(shell echo $(1) | sed -e 's:$(native-build)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
@echo "generating $(@)"
2007-10-28 01:54:30 +00:00
@mkdir -p $(dir $(@))
$(generator) $(classpath-build) $(call gen-arg,$(@)) < $(<) > $(@)
$(native-build)/type-generator.o: \
2007-06-04 23:39:59 +00:00
$(generator-headers)
$(classpath-build)/%.class: $(classpath)/%.java
@echo $(<)
$(classpath-dep): $(classpath-sources)
@echo "compiling classpath classes"
2007-10-28 01:54:30 +00:00
@mkdir -p $(dir $(@))
$(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \
$(shell make -s $(classpath-classes))
@touch $(@)
2007-06-29 02:58:48 +00:00
$(test-build)/%.class: $(test)/%.java
2007-11-02 21:08:14 +00:00
@echo $(<)
$(test-dep): $(test-sources)
@echo "compiling test classes"
2007-10-28 01:54:30 +00:00
@mkdir -p $(dir $(@))
$(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \
$(shell make -s $(test-classes))
@touch $(@)
define compile-object
@echo "compiling $(@)"
2007-10-28 01:54:30 +00:00
@mkdir -p $(dir $(@))
$(cxx) $(cflags) -c $(<) -o $(@)
endef
$(vm-cpp-objects): $(native-build)/%.o: $(src)/%.cpp $(vm-depends)
$(compile-object)
$(vm-asm-objects): $(native-build)/%-asm.o: $(src)/%.S
$(compile-object)
2007-10-26 14:34:54 +00:00
$(driver-object): $(native-build)/%.o: $(src)/%.cpp
$(compile-object)
$(build)/classpath.jar: $(classpath-dep)
2007-10-26 00:03:26 +00:00
(wd=$$(pwd); \
cd $(classpath-build); \
$(jar) c0f $${wd}/$(@) $$(find . -name '*.class'))
$(binaryToMacho): $(src)/binaryToMacho.cpp
$(cxx) $(^) -o $(@)
$(classpath-object): $(build)/classpath.jar $(binaryToMacho)
ifeq ($(platform),darwin)
$(binaryToMacho) $(build)/classpath.jar \
__binary_classpath_jar_start __binary_classpath_jar_size > $(@)
else
(wd=$$(pwd); \
cd $(build); \
$(objcopy) -I binary classpath.jar \
-O $(object-format) -B $(object-arch) $${wd}/$(@))
endif
$(generator-objects): $(native-build)/%.o: $(src)/%.cpp
@echo "compiling $(@)"
2007-10-28 01:54:30 +00:00
@mkdir -p $(dir $(@))
$(build-cxx) -DPOINTER_SIZE=$(pointer-size) -O0 -g3 $(build-cflags) \
-c $(<) -o $(@)
$(jni-objects): $(native-build)/%.o: $(classpath)/%.cpp
$(compile-object)
2007-06-25 01:34:07 +00:00
$(libvm): $(vm-objects) $(jni-objects)
@echo "creating $(@)"
2007-10-26 21:02:39 +00:00
rm -rf $(@)
$(ar) cru $(@) $(^)
$(ranlib) $(@)
$(vm): $(vm-objects) $(classpath-object) $(jni-objects) $(driver-object)
@echo "linking $(@)"
2007-10-26 21:02:39 +00:00
ifeq ($(platform),windows)
$(dlltool) -z $(@).def $(^)
$(dlltool) -k -d $(@).def -e $(@).exp
$(cc) $(@).exp $(^) $(lflags) -o $(@)
else
$(cc) $(^) $(lflags) -o $(@)
endif
2007-11-01 20:37:51 +00:00
$(strip) $(strip-all) $(@)
$(generator): $(generator-objects)
@echo "linking $(@)"
$(build-cc) $(^) -o $(@)