sample.makefile.txt revision 5029
1N/A#
1N/A# Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
1N/A#
1N/A# Redistribution and use in source and binary forms, with or without
1N/A# modification, are permitted provided that the following conditions
1N/A# are met:
1N/A#
1N/A# - Redistributions of source code must retain the above copyright
1N/A# notice, this list of conditions and the following disclaimer.
1N/A#
1N/A# - Redistributions in binary form must reproduce the above copyright
1N/A# notice, this list of conditions and the following disclaimer in the
1N/A# documentation and/or other materials provided with the distribution.
1N/A#
1N/A# - Neither the name of Oracle nor the names of its
1N/A# contributors may be used to endorse or promote products derived
1N/A# from this software without specific prior written permission.
1N/A#
1N/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
1N/A# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
1N/A# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1N/A# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
1N/A# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1N/A# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1N/A# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1N/A# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1N/A# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1N/A# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1N/A# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1N/A#
1N/A
1N/A########################################################################
1N/A#
1N/A# Sample GNU Makefile for building JVMTI Demo minst
1N/A#
1N/A# Example uses:
1N/A# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparc]
1N/A# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparcv9]
1N/A# gnumake JDK=<java_home> OSNAME=linux [OPT=true]
1N/A# gnumake JDK=<java_home> OSNAME=win32 [OPT=true]
1N/A#
1N/A########################################################################
1N/A
1N/A# Source lists
1N/ALIBNAME=minst
1N/ASOURCES=minst.c ../agent_util/agent_util.c
1N/AJAVA_SOURCES=Minst.java
1N/A
1N/A# Name of jar file that needs to be created
1N/AJARFILE=minst.jar
1N/A
1N/A# Solaris Sun C Compiler Version 5.5
1N/Aifeq ($(OSNAME), solaris)
1N/A # Sun Solaris Compiler options needed
1N/A COMMON_FLAGS=-mt -KPIC
1N/A # Options that help find errors
1N/A COMMON_FLAGS+= -Xa -v -xstrconst -xc99=%none
1N/A # Check LIBARCH for any special compiler options
1N/A LIBARCH=$(shell uname -p)
1N/A ifeq ($(LIBARCH), sparc)
1N/A COMMON_FLAGS+=-xarch=v8 -xregs=no%appl
1N/A endif
1N/A ifeq ($(LIBARCH), sparcv9)
1N/A COMMON_FLAGS+=-xarch=v9 -xregs=no%appl
1N/A endif
1N/A ifeq ($(OPT), true)
1N/A CFLAGS=-xO2 $(COMMON_FLAGS)
1N/A else
1N/A CFLAGS=-g $(COMMON_FLAGS)
1N/A endif
1N/A # Object files needed to create library
1N/A OBJECTS=$(SOURCES:%.c=%.o)
1N/A # Library name and options needed to build it
1N/A LIBRARY=lib$(LIBNAME).so
1N/A LDFLAGS=-z defs -ztext
1N/A # Libraries we are dependent on
1N/A LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc
1N/A # Building a shared library
1N/A LINK_SHARED=$(LINK.c) -G -o $@
1N/Aendif
1N/A
1N/A# Linux GNU C Compiler
1N/Aifeq ($(OSNAME), linux)
1N/A # GNU Compiler options needed to build it
1N/A COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer
1N/A # Options that help find errors
1N/A COMMON_FLAGS+= -W -Wall -Wno-unused -Wno-parentheses
1N/A ifeq ($(OPT), true)
1N/A CFLAGS=-O2 $(COMMON_FLAGS)
1N/A else
1N/A CFLAGS=-g $(COMMON_FLAGS)
1N/A endif
1N/A # Object files needed to create library
1N/A OBJECTS=$(SOURCES:%.c=%.o)
1N/A # Library name and options needed to build it
1N/A LIBRARY=lib$(LIBNAME).so
1N/A LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
1N/A # Libraries we are dependent on
1N/A LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc
1N/A # Building a shared library
1N/A LINK_SHARED=$(LINK.c) -shared -o $@
1N/Aendif
1N/A
1N/A# Windows Microsoft C/C++ Optimizing Compiler Version 12
1N/Aifeq ($(OSNAME), win32)
1N/A CC=cl
1N/A # Compiler options needed to build it
1N/A COMMON_FLAGS=-Gy -DWIN32
1N/A # Options that help find errors
1N/A COMMON_FLAGS+=-W0 -WX
1N/A ifeq ($(OPT), true)
1N/A CFLAGS= -Ox -Op -Zi $(COMMON_FLAGS)
1N/A else
1N/A CFLAGS= -Od -Zi $(COMMON_FLAGS)
1N/A endif
1N/A # Add in java_crw_demo obj file on windows (easier)
1N/A SOURCES+=../java_crw_demo/java_crw_demo.c
1N/A # Object files needed to create library
1N/A OBJECTS=$(SOURCES:%.c=%.obj)
1N/A # Library name and options needed to build it
1N/A LIBRARY=$(LIBNAME).dll
1N/A LDFLAGS=
1N/A # Libraries we are dependent on
1N/A LIBRARIES=$(JDK)/
1N/A # Building a shared library
1N/A LINK_SHARED=link -dll -out:$@
1N/Aendif
1N/A
1N/A# Common -I options
1N/ACFLAGS += -I.
1N/ACFLAGS += -I../agent_util
1N/ACFLAGS += -I../java_crw_demo
1N/ACFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME)
1N/A
1N/A# Default rule (build both native library and jar file)
1N/Aall: $(LIBRARY) $(JARFILE)
1N/A
1N/A# Build native library
1N/A$(LIBRARY): $(OBJECTS)
1N/A $(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
1N/A
1N/A# Build jar file
1N/A$(JARFILE): $(JAVA_SOURCES)
1N/A rm -f -r classes
1N/A mkdir -p classes
1N/A $(JDK)/bin/javac -d classes $(JAVA_SOURCES)
1N/A (cd classes; $(JDK)/bin/jar cf ../$@ *)
1N/A
1N/A# Cleanup the built bits
1N/Aclean:
1N/A rm -f -r classes
1N/A rm -f $(LIBRARY) $(JARFILE) $(OBJECTS)
1N/A
1N/A# Simple tester
1N/Atest: all
1N/A LD_LIBRARY_PATH=. $(JDK)/bin/java -agentlib:$(LIBNAME) -Xbootclasspath/a:./$(JARFILE) -version
1N/A
1N/A# Compilation rule only needed on Windows
1N/Aifeq ($(OSNAME), win32)
1N/A%.obj: %.c
1N/A $(COMPILE.c) $<
1N/Aendif
1N/A
1N/A