Commit a9974185 authored by Lubomir Bulej's avatar Lubomir Bulej

- Shadow VM agent now uses a Makefile based on the one for DiSL agent.

- Shadow VM agent now uses the bundled JNI and JVMTI include files.
- Ant build system adjusted to the new Makefile.
parent d8865ce1
......@@ -366,8 +366,9 @@
<!-- Shadow VM agent -->
<target name="compile-shvm-agent" depends="determine-lib-names">
<exec executable="make" dir="${src.shvm.agent}/javahome" />
<exec executable="make" dir="${src.shvm.agent}" />
<exec executable="make" dir="${src.shvm.agent}">
<arg value="WHOLE=1" />
</exec>
</target>
......@@ -744,11 +745,8 @@
<arg value="cleanall" />
</exec>
<exec executable="make" dir="${src.shvm.agent}/javahome">
<arg value="clean" />
</exec>
<exec executable="make" dir="${src.shvm.agent}">
<arg value="clean" />
<arg value="cleanall" />
</exec>
<delete dir="${out.dir}" />
......
# if there is JAVA_HOME var file then include it
ifneq (, $(wildcard javahome/var))
include javahome/var
# Import local variable definitions
-include Makefile.local
INCLUDE_DIR ?= ../src-jdk-include
LIBRARY_BASE ?= dislreagent
ifeq ($(OS),Windows_NT)
ifeq (,$(findstring /cygdrive/,$(PATH)))
$(error Building on the Windows platform is only supported under Cygwin)
endif
HOST_ENV := Cygwin
else
HOST_ENV := $(shell uname -s)
HOST_CPU := $(shell uname -m)
endif
# Source lists
LIBNAME=dislreagent
SOURCES=dislreagent.c
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
# Library name and options needed to build it
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
LIBRARY=lib$(LIBNAME).so
JNI_OS=linux
else ifeq ($(UNAME), Darwin)
LIBRARY=lib$(LIBNAME).jnilib
JNI_OS=darwin
TARGET_ENV ?= $(HOST_ENV)
TARGET_CPU ?= $(HOST_CPU)
LIBRARY_WINDOWS = $(LIBRARY_BASE).dll
LIBRARY_MACOSX = lib$(LIBRARY_BASE).jnilib
LIBRARY_LINUX = lib$(LIBRARY_BASE).so
ifneq ($(HOST_ENV),$(TARGET_ENV))
ifneq ($(TARGET_ENV),MinGW)
$(error Cross-compiling is only supported for TARGET_ENV=MinGW)
else
$(warning The MinGW port for the Windows platform is experimental!)
endif
endif
ifneq (,$(filter MinGW Cygwin,$(TARGET_ENV)))
JDK_TARGET := windows
LIBRARY := $(LIBRARY_WINDOWS)
ifeq (MinGW,$(TARGET_ENV))
CC := $(TARGET_CPU)-w64-mingw32-gcc
CFLAGS += -DMINGW -mthreads
CFLAGS_LD += -Wl,--kill-at
LIBS += -lws2_32
endif
else ifeq (Darwin,$(TARGET_ENV))
JDK_TARGET := macosx
LIBRARY := $(LIBRARY_MACOSX)
else ifeq (Linux,$(TARGET_ENV))
LIBRARY := $(LIBRARY_LINUX)
JDK_TARGET := linux
CFLAGS_WHOLE := -fwhole-program
else
$(error error: unsupported operating system: $(UNAME))
$(error Target environment $(TARGET_ENV) is not supported)
endif
# Building a shared library
LINK_SHARED=$(LINK.c) -shared -o $@
# Source and object files needed to create the library
SOURCES = dislreagent.c
# GNU Compiler options needed to build it
COMMON_FLAGS=-fPIC
# Options that help find errors
COMMON_FLAGS+= -W -Wall -Wextra -O3 -Wno-unused-parameter -lpthread
HEADERS = $(wildcard *.h)
GENSRCS =
OBJECTS = $(SOURCES:%.c=%.o)
SRCDEPS = $(SOURCES:%.c=%.d)
CFLAGS += $(COMMON_FLAGS)
CFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(JNI_OS)
# add debugging output
ifneq ($(DEBUG),)
CFLAGS += -DDEBUG -g3
# Base options depending on the build
ifeq (,$(DEBUG))
CFLAGS += -O3 -DNDEBUG
else
CFLAGS += -g3 -DDEBUG
endif
ifneq ($(DEBUGFULL),)
CFLAGS += -DDEBUG -DDEBUGANL -g3
# Tell the linker to create a shared library.
CFLAGS_LD += -shared
#
# For non-MinGW targets, use position independent code
# and dynamically link to the pthread library. When
# building the library as a whole, tell GCC to build
# a shared library as well.
#
ifneq (MinGW,$(TARGET_ENV))
CFLAGS += -fPIC
LIBS += -lpthread
endif
all: $(LIBRARY)
# JNI and JVMTI includes
CFLAGS += -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/$(JDK_TARGET)
# Source code options
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter
#CFLAGS += -std=gnu99 -W -Wall -Wextra -Wno-unused-parameter
# Fix-up quirks before first target
-include Makefile.quirks
# Default goal
.PHONY: agent
agent: $(GENSRCS) $(LIBRARY)
# Convenience targets
.PHONY: whole
whole:
@$(MAKE) WHOLE=1
.PHONY: debug
debug:
@$(MAKE) DEBUG=1
# Compilation and linking targets
ifneq (,$(WHOLE))
#
# Despite the GCC documentation saying that -flto should not be used with
# -fwhole-program, the option needs to be there, otherwise GCC produces a
# library with undefined symbols (bypass bytecode) despite them being present.
#
CFLAGS += -DWHOLE -flto $(CFLAGS_WHOLE)
$(LIBRARY): $(HEADERS) $(SOURCES)
$(CC) $(CFLAGS) $(TARGET_ARCH) $(CFLAGS_LD) $(SOURCES) $(LIBS) $(OUTPUT_OPTION)
else
CFLAGS += -flto
# Build native library
$(LIBRARY): $(OBJECTS)
$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
$(CC) $(CFLAGS) $(TARGET_ARCH) $(CFLAGS_LD) $(OBJECTS) $(LIBS) $(OUTPUT_OPTION)
%.d: %.c
@$(CC) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
-include $(SRCDEPS)
# Cleanup the built bits
endif
# Cleanup targets
.PHONY: clean
clean:
rm -f $(LIBRARY) $(OBJECTS)
-rm -f $(OBJECTS)
-rm -f $(SRCDEPS)
debug:
$(MAKE) DEBUG=TRUE
.PHONY: cleanall
cleanall: clean
-rm -f $(LIBRARY_LINUX) $(LIBRARY_MACOSX) $(LIBRARY_WINDOWS)
debugfull:
$(MAKE) DEBUGFULL=TRUE
.PHONY: pristine
pristine: cleanall
-rm -f $(GENSRCS)
#
# This file is intended to contain variable assignments specific to this
# environment, without having to modify the main Makefile.
#
......@@ -1725,7 +1725,14 @@ void JNICALL jvmti_callback_thread_end_hook(
// ******************* JVMTI entry method *******************
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
#ifdef WHOLE
#define VISIBLE __attribute__((externally_visible))
#else
#define VISIBLE
#endif
JNIEXPORT jint JNICALL VISIBLE
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
#ifdef DEBUG
setvbuf(stdout, NULL, _IONBF, 0);
......
UNAME := Unknown
ifeq ($(OS),Windows_NT)
UNAME := Windows
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
endif
else
UNAME_KNOWN := $(shell uname -s)
ifeq ($(UNAME_KNOWN),Linux)
UNAME := Linux
endif
ifeq ($(UNAME_KNOWN),Darwin)
UNAME := Darwin
endif
endif
.PHONY: all, clean
all: $(UNAME)-all
Linux-all:
@./find.sh
Darwin-all:
@./find.sh
Cygwin-all:
@./find.sh
Windows-all:
@.\\find.bat
Unknown-all:
$(error error: unsupported operating system $(UNAME))
clean: $(UNAME)-clean
Linux-clean:
@rm -f var
Darwin-clean:
@rm -f var
Cygwin-clean:
@rm -f var
Windows-clean:
@CMD /C IF EXIST var DEL /Q/F var
Unknown-clean:
$(error error: unsupported operating system $(UNAME))
The Java finder works in the following order.
1. If there is a file "var.local" then it is used. It's supposed there is
JAVA_HOME specified as in the "var.local.tmpl".
2. If there is no such file then the script checks the environment for the
JAVA_HOME variable.
3. If the envorinment variable is not found the script tries to guess based on
currently prefered java compiler and derives the destination of JAVA_HOME.
@ECHO OFF
:: use variable specified by the use
IF EXIST "var.local" (
COPY /B/V/Y "var.local" "var" > NUL
EXIT /B 0
)
:: use environment variable
IF not "%JAVA_HOME%" == "" (
ECHO JAVA_HOME=%JAVA_HOME% > "var"
EXIT /B 0
)
#!/bin/sh
# use variable specified by the user
if [ -f "var.local" ]; then
cp -f "var.local" "var"
exit 0
fi
# use environment variable
if [ ! -z "$JAVA_HOME" ]; then
echo "JAVA_HOME="$JAVA_HOME > "var"
exit 0
fi
# guess
JAVAC=`which javac 2>/dev/null`
JH=`readlink -f ${JAVAC}`
JH=`echo ${JH%/*}`
JH=`echo ${JH%/*}`
echo "JAVA_HOME="${JH} > "var"
JAVA_HOME=/path/to/java/directory
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment