corda/makefile

250 lines
5.8 KiB
Makefile
Raw Normal View History

2007-10-08 23:13:55 +00:00
MAKEFLAGS = -s
2007-06-29 16:43:25 +00:00
arch = $(shell uname -m)
ifeq ($(arch),i586)
arch = i386
endif
ifeq ($(arch),i686)
arch = i386
endif
2007-06-29 16:42:39 +00:00
2007-09-21 14:16:43 +00:00
platform = $(shell uname -s | tr [:upper:] [:lower:])
ifeq ($(platform),darwin)
rdynamic =
thread-cflags =
shared = -dynamiclib
so-extension = jnilib
ld-library-path = DYLD_LIBRARY_PATH
else
rdynamic = -rdynamic
thread-cflags = -pthread
shared = -shared
so-extension = so
ld-library-path = LD_LIBRARY_PATH
endif
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
input = $(cls)/Memory.class
2007-07-17 01:55:49 +00:00
cxx = g++
cc = gcc
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 = :
warnings = -Wall -Wextra -Werror -Wunused-parameter \
-Winit-self -Wconversion
thread-lflags = -lpthread
cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \
2007-07-11 01:38:06 +00:00
-I$(src) -I$(bld) $(thread-cflags) -D__STDC_LIMIT_MACROS
2007-09-17 00:13:36 +00:00
lflags = $(thread-lflags) -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
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x)))
2007-10-04 00:41:54 +00:00
asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(bld)/%-asm.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(cls)/%.class,$(x)))
stdcpp-sources = $(src)/stdc++.cpp
stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src))
jni-sources = $(shell find $(classpath) -name '*.cpp')
2007-06-25 01:34:07 +00:00
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath))
jni-cflags = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux $(cflags)
jni-library = $(bld)/libnatives.$(so-extension)
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-20 19:20:25 +00:00
$(src)/main.cpp
2007-06-29 02:58:48 +00:00
2007-10-04 00:41:54 +00:00
interpreter-asm-sources = $(src)/compile.S $(src)/system.S
2007-06-29 02:58:48 +00:00
interpreter-cpp-objects = \
$(call cpp-objects,$(interpreter-sources),$(src))
interpreter-asm-objects = \
$(call asm-objects,$(interpreter-asm-sources),$(src))
2007-06-29 02:58:48 +00:00
interpreter-objects = \
$(interpreter-cpp-objects) \
$(interpreter-asm-objects)
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))
generator-executable = $(bld)/generator
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) $(jni-library)
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
$(ld-library-path)=$(bld) $(executable) $(args)
.PHONY: debug
2007-09-30 16:32:17 +00:00
debug: build
LD_LIBRARY_PATH=$(bld) gdb --args $(executable) $(args)
.PHONY: vg
2007-09-30 16:32:17 +00:00
vg: build
LD_LIBRARY_PATH=$(bld) $(vg) $(executable) $(args)
.PHONY: test
2007-09-30 16:32:17 +00:00
test: build
LD_LIBRARY_PATH=$(bld) /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 $(@)"
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
2007-06-04 23:39:59 +00:00
$(bld)/type-generator.o: \
$(generator-headers)
define compile-class
2007-06-21 01:38:02 +00:00
@echo "compiling $(@)"
@mkdir -p $(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 $(@)"
@mkdir -p $(dir $(@))
$(cxx) $(cflags) -c $(<) -o $(@)
endef
$(stdcpp-objects): $(bld)/%.o: $(src)/%.cpp
$(compile-object)
$(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)
$(generator-objects): $(bld)/%.o: $(src)/%.cpp
$(compile-object)
2007-06-25 01:34:07 +00:00
$(jni-objects): $(bld)/%.o: $(classpath)/%.cpp
@echo "compiling $(@)"
@mkdir -p $(dir $(@))
$(cxx) $(jni-cflags) -c $(<) -o $(@)
$(jni-library): $(jni-objects)
@echo "linking $(@)"
$(cc) $(lflags) $(shared) $(^) -o $(@)
2007-06-25 01:34:07 +00:00
$(executable): $(interpreter-objects) $(stdcpp-objects)
@echo "linking $(@)"
$(cc) $(lflags) $(rdynamic) $(^) -o $(@)
2007-08-20 02:57:32 +00:00
@$(strip) --strip-all $(@)
@$(show-size) $(@)
.PHONY: generator
generator: $(generator-executable)
.PHONY: run-generator
run-generator: $(generator-executable)
$(<) < $(src)/types.def
.PHONY: vg-generator
vg-generator: $(generator-executable)
$(vg) $(<) < $(src)/types.def
$(generator-executable): $(generator-objects) $(stdcpp-objects)
@echo "linking $(@)"
$(cc) $(lflags) $(^) -o $(@)