blob: b04bd07a78df7c3cb4ff6c4b3a594376fb45f0d6 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#
2# Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7#
8# - Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10#
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14#
15# - Neither the name of Sun Microsystems nor the names of its
16# contributors may be used to endorse or promote products derived
17# from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#
31
32########################################################################
33#
34# Sample GNU Makefile for building JVMTI Demo waiters
35#
36# Example uses:
37# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparc]
38# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparcv9]
39# gnumake JDK=<java_home> OSNAME=linux [OPT=true]
40# gnumake JDK=<java_home> OSNAME=win32 [OPT=true]
41#
42########################################################################
43
44# Source lists
45LIBNAME=waiters
46SOURCES=waiters.cpp Agent.cpp Thread.cpp Monitor.cpp ../agent_util/agent_util.c
47
48# Solaris Sun C Compiler Version 5.5
49ifeq ($(OSNAME), solaris)
50 # Tell gnumake which compilers to use
51 CC=cc
52 CXX=CC
53 # Sun Solaris Compiler options needed
54 COMMON_FLAGS=-mt -KPIC
55 # Check LIBARCH for any special compiler options
56 LIBARCH=$(shell uname -p)
57 ifeq ($(LIBARCH), sparc)
58 COMMON_FLAGS+=-xarch=v8 -xregs=no%appl
59 endif
60 ifeq ($(LIBARCH), sparcv9)
61 COMMON_FLAGS+=-xarch=v9 -xregs=no%appl
62 endif
63 ifeq ($(OPT), true)
64 CXXFLAGS=-xO2 $(COMMON_FLAGS)
65 else
66 CXXFLAGS=-g $(COMMON_FLAGS)
67 endif
68 # Object files needed to create library
69 OBJECTS=$(SOURCES:%.cpp=%.o)
70 # Library name and options needed to build it
71 LIBRARY=lib$(LIBNAME).so
72 LDFLAGS=-z defs -ztext
73 # Libraries we are dependent on
74 LIBRARIES= -lc
75 # Building a shared library
76 LINK_SHARED=$(LINK.cc) -G -o $@
77endif
78
79# Linux GNU C Compiler
80ifeq ($(OSNAME), linux)
81 # GNU Compiler options needed to build it
82 COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer
83 # Options that help find errors
84 COMMON_FLAGS+= -W -Wall -Wno-unused -Wno-parentheses
85 ifeq ($(OPT), true)
86 CXXFLAGS=-O2 $(COMMON_FLAGS)
87 else
88 CXXFLAGS=-g $(COMMON_FLAGS)
89 endif
90 # Object files needed to create library
91 OBJECTS=$(SOURCES:%.cpp=%.o)
92 # Library name and options needed to build it
93 LIBRARY=lib$(LIBNAME).so
94 LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
95 # Libraries we are dependent on
96 LIBRARIES=
97 # Building a shared library
98 LINK_SHARED=$(LINK.cc) -shared -o $@
99endif
100
101# Windows Microsoft C/C++ Optimizing Compiler Version 12
102ifeq ($(OSNAME), win32)
103 CC=cl
104 # Compiler options needed to build it
105 COMMON_FLAGS=-Gy -DWIN32
106 # Options that help find errors
107 COMMON_FLAGS+=-W0 -WX
108 ifeq ($(OPT), true)
109 CXXFLAGS= -Ox -Op -Zi $(COMMON_FLAGS)
110 else
111 CXXFLAGS= -Od -Zi $(COMMON_FLAGS)
112 endif
113 # Object files needed to create library
114 OBJECTS=$(SOURCES:%.cpp=%.obj)
115 # Library name and options needed to build it
116 LIBRARY=$(LIBNAME).dll
117 LDFLAGS=
118 # Libraries we are dependent on
119 LIBRARIES=
120 # Building a shared library
121 LINK_SHARED=link -dll -out:$@
122endif
123
124# Common -I options
125CXXFLAGS += -I.
126CXXFLAGS += -I../agent_util
127CXXFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME)
128
129# Default rule
130all: $(LIBRARY)
131
132# Build native library
133$(LIBRARY): $(OBJECTS)
134 $(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
135
136# Cleanup the built bits
137clean:
138 rm -f $(LIBRARY) $(OBJECTS)
139
140# Simple tester
141test: all
142 LD_LIBRARY_PATH=`pwd` $(JDK)/bin/java -agentlib:$(LIBNAME) -version
143
144# Compilation rule only needed on Windows
145ifeq ($(OSNAME), win32)
146%.obj: %.cpp
147 $(COMPILE.cc) $<
148endif
149