corda/makefile

301 lines
6.7 KiB
Makefile
Raw Normal View History

2007-10-23 17:22:48 +00:00
#MAKEFLAGS = -s
input = $(cls)/Hello.class
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
2007-10-23 17:22:48 +00:00
ifeq ($(build-platform),cygwin_nt-5.1)
build-platform = windows
endif
arch = $(build-arch)
platform = $(build-platform)
process = interpret
2007-09-25 23:53:11 +00:00
mode = debug
2007-09-21 14:16:43 +00:00
bld = build/$(platform)/$(arch)/$(mode)
cls = build/classes
src = src
2007-06-25 01:34:07 +00:00
classpath = classpath
test = test
build-cxx = g++
build-cc = gcc
2007-07-17 01:55:49 +00:00
2007-10-25 14:55:48 +00:00
pthread = -pthread
lpthread = -lpthread
cxx = $(build-cxx)
cc = $(build-cc)
ar = ar
ranlib = ranlib
2007-09-14 23:04:08 +00:00
vg = nice valgrind --suppressions=valgrind.supp --undef-value-errors=no \
--num-callers=32 --db-attach=yes --freelist-vol=100000000
db = gdb --args
2007-06-21 01:38:02 +00:00
javac = javac
strip = :
show-size = :
rdynamic = -rdynamic
shared = -shared
warnings = -Wall -Wextra -Werror -Wunused-parameter \
-Winit-self -Wconversion
common-cflags = $(warnings) -fno-rtti -fno-exceptions \
-I$(JAVA_HOME)/include -idirafter $(src) -I$(bld) -D__STDC_LIMIT_MACROS \
-D_JNI_IMPLEMENTATION_
system = posix
2007-10-23 01:00:57 +00:00
asm = x86
begin-merge-archive = -Wl,--whole-archive
end-merge-archive = -Wl,--no-whole-archive
ifeq ($(platform),darwin)
rdynamic =
thread-cflags =
shared = -dynamiclib
2007-10-25 14:55:48 +00:00
pthread =
lpthread =
begin-merge-archive = -Wl,-all_load
end-merge-archive =
endif
ifeq ($(platform),windows)
inc = /usr/local/win32/include
lib = /usr/local/win32/lib
system = windows
cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc
dlltool = i586-mingw32msvc-dlltool
ar = i586-mingw32msvc-ar
ranlib = i586-mingw32msvc-ranlib
rdynamic = -Wl,--export-dynamic
2007-10-24 17:24:19 +00:00
lflags = -L$(lib) -lm -lz -lws2_32 -Wl,--kill-at -mwindows -mconsole
cflags = $(common-cflags) -I$(inc)
endif
2007-10-25 14:55:48 +00:00
cflags = $(common-cflags) -fPIC -fvisibility=hidden \
-I$(JAVA_HOME)/include/linux -I$(src) $(pthread)
lflags = $(lpthread) -ldl -lm -lz
ifeq ($(mode),debug)
cflags += -O0 -g3
endif
ifeq ($(mode),stress)
cflags += -O0 -g3 -DVM_STRESS
endif
ifeq ($(mode),stress-major)
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
endif
ifeq ($(mode),fast)
cflags += -O3 -DNDEBUG
strip = strip
show-size = ls -l
endif
ifeq ($(arch),i386)
pointer-size = 4
else
pointer-size = 8
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,$(cls)/%.class,$(x)))
jni-sources = $(shell find $(classpath) -name '*.cpp')
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(bld))
jni-cflags = $(cflags)
2007-06-25 01:34:07 +00:00
generated-code = \
$(bld)/type-enums.cpp \
$(bld)/type-declarations.cpp \
$(bld)/type-constructors.cpp \
$(bld)/type-initializations.cpp \
$(bld)/type-java-initializations.cpp
2007-07-06 23:50:26 +00:00
interpreter-depends = \
$(generated-code) \
$(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 \
$(src)/machine.h
interpreter-sources = \
$(src)/$(system).cpp \
$(src)/finder.cpp \
2007-07-06 23:50:26 +00:00
$(src)/machine.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
2007-06-29 02:58:48 +00:00
2007-10-23 01:00:57 +00:00
interpreter-asm-sources = $(src)/$(asm).S
ifeq ($(process),compile)
interpreter-asm-sources += $(src)/compile.S
endif
2007-06-29 02:58:48 +00:00
interpreter-cpp-objects = \
$(call cpp-objects,$(interpreter-sources),$(src),$(bld))
interpreter-asm-objects = \
$(call asm-objects,$(interpreter-asm-sources),$(src),$(bld))
2007-06-29 02:58:48 +00:00
interpreter-objects = \
$(interpreter-cpp-objects) \
$(interpreter-asm-objects)
driver-sources = $(src)/main.cpp
driver-objects = $(call cpp-objects,$(driver-sources),$(src),$(bld))
2007-06-04 23:39:59 +00:00
generator-headers = \
$(src)/input.h \
$(src)/output.h
generator-sources = \
$(src)/type-generator.cpp
generator-objects = $(call cpp-objects,$(generator-sources),$(src),$(bld))
generator-executable = $(bld)/generator
archive = $(bld)/libvm.a
executable = $(bld)/vm
classpath-sources = $(shell find $(classpath) -name '*.java')
2007-06-30 02:39:01 +00:00
classpath-classes = $(call java-classes,$(classpath-sources),$(classpath))
classpath-objects = $(classpath-classes)
test-sources = $(shell find $(test) -name '*.java')
test-classes = $(call java-classes,$(test-sources),$(test))
class-name = $(patsubst $(cls)/%.class,%,$(1))
class-names = $(foreach x,$(1),$(call class-name,$(x)))
flags = -cp $(cls)
args = $(flags) $(call class-name,$(input))
2007-06-21 01:38:02 +00:00
.PHONY: build
build: $(executable) $(classpath-objects) $(test-classes)
2007-09-30 16:32:17 +00:00
$(input): $(classpath-classes)
2007-06-21 01:38:02 +00:00
.PHONY: run
2007-09-30 16:32:17 +00:00
run: build
$(executable) $(args)
.PHONY: debug
2007-09-30 16:32:17 +00:00
debug: build
gdb --args $(executable) $(args)
.PHONY: vg
2007-09-30 16:32:17 +00:00
vg: build
$(vg) $(executable) $(args)
.PHONY: test
test: build
/bin/bash $(test)/test.sh 2>/dev/null \
2007-09-30 16:32:17 +00:00
$(executable) $(mode) "$(flags)" $(call class-names,$(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 $(bld)"
rm -rf $(bld)
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@echo "generating $(@)"
@mkdir -p -m 1777 $(dir $(@))
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
$(bld)/type-generator.o: \
2007-06-04 23:39:59 +00:00
$(generator-headers)
define compile-class
2007-06-21 01:38:02 +00:00
@echo "compiling $(@)"
2007-10-23 17:22:48 +00:00
@mkdir -p -m 1777 $(dir $(@))
$(javac) -bootclasspath $(classpath) -classpath $(classpath) \
-d $(cls) $(<)
2007-09-30 16:32:17 +00:00
@touch $(@)
endef
2007-06-21 01:38:02 +00:00
$(cls)/%.class: $(classpath)/%.java
$(compile-class)
2007-06-29 02:58:48 +00:00
$(cls)/%.class: $(test)/%.java
$(compile-class)
define compile-object
@echo "compiling $(@)"
2007-10-23 17:22:48 +00:00
@mkdir -p -m 1777 $(dir $(@))
$(cxx) $(cflags) -c $(<) -o $(@)
endef
$(interpreter-cpp-objects): $(bld)/%.o: $(src)/%.cpp $(interpreter-depends)
$(compile-object)
2007-10-04 00:41:54 +00:00
$(interpreter-asm-objects): $(bld)/%-asm.o: $(src)/%.S
$(compile-object)
$(driver-objects): $(bld)/%.o: $(src)/%.cpp
$(compile-object)
$(generator-objects): $(bld)/%.o: $(src)/%.cpp
@echo "compiling $(@)"
2007-10-23 17:22:48 +00:00
@mkdir -p -m 1777 $(dir $(@))
$(build-cxx) -DPOINTER_SIZE=$(pointer-size) $(cflags) -c $(<) -o $(@)
2007-06-25 01:34:07 +00:00
$(jni-objects): $(bld)/%.o: $(classpath)/%.cpp
@echo "compiling $(@)"
2007-10-23 17:22:48 +00:00
@mkdir -p -m 1777 $(dir $(@))
$(cxx) $(jni-cflags) -c $(<) -o $(@)
2007-06-25 01:34:07 +00:00
ifeq ($(platform),windows)
$(archive): $(interpreter-objects) $(jni-objects)
@echo "creating $(@)"
2007-10-24 17:24:19 +00:00
$(dlltool) -z $(@).def $(^)
2007-10-23 20:18:42 +00:00
$(dlltool) -k -d $(@).def -e $(@).exp
$(ar) cru $(@) $(@).exp $(^)
$(ranlib) $(@)
else
$(archive): $(interpreter-objects) $(jni-objects)
@echo "creating $(@)"
$(ar) cru $(@) $(^)
$(ranlib) $(@)
endif
$(executable): $(archive) $(driver-objects)
@echo "linking $(@)"
2007-10-25 15:03:24 +00:00
$(cc) $(begin-merge-archive) $(^) $(end-merge-archive) \
$(lflags) $(rdynamic) -o $(@)
2007-08-20 02:57:32 +00:00
@$(strip) --strip-all $(@)
@$(show-size) $(@)
$(generator-executable): $(generator-objects)
@echo "linking $(@)"
$(build-cc) $(^) -o $(@)