J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | # |
| 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 heapTracker |
| 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 |
| 45 | LIBNAME=heapTracker |
| 46 | SOURCES=heapTracker.c ../agent_util/agent_util.c |
| 47 | JAVA_SOURCES=HeapTracker.java |
| 48 | |
| 49 | # Name of jar file that needs to be created |
| 50 | JARFILE=heapTracker.jar |
| 51 | |
| 52 | # Solaris Sun C Compiler Version 5.5 |
| 53 | ifeq ($(OSNAME), solaris) |
| 54 | # Sun Solaris Compiler options needed |
| 55 | COMMON_FLAGS=-mt -KPIC |
| 56 | # Options that help find errors |
| 57 | COMMON_FLAGS+= -Xa -v -xstrconst -xc99=%none |
| 58 | # Check LIBARCH for any special compiler options |
| 59 | LIBARCH=$(shell uname -p) |
| 60 | ifeq ($(LIBARCH), sparc) |
| 61 | COMMON_FLAGS+=-xarch=v8 -xregs=no%appl |
| 62 | endif |
| 63 | ifeq ($(LIBARCH), sparcv9) |
| 64 | COMMON_FLAGS+=-xarch=v9 -xregs=no%appl |
| 65 | endif |
| 66 | ifeq ($(OPT), true) |
| 67 | CFLAGS=-xO2 $(COMMON_FLAGS) |
| 68 | else |
| 69 | CFLAGS=-g $(COMMON_FLAGS) |
| 70 | endif |
| 71 | # Object files needed to create library |
| 72 | OBJECTS=$(SOURCES:%.c=%.o) |
| 73 | # Library name and options needed to build it |
| 74 | LIBRARY=lib$(LIBNAME).so |
| 75 | LDFLAGS=-z defs -ztext |
| 76 | # Libraries we are dependent on |
| 77 | LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc |
| 78 | # Building a shared library |
| 79 | LINK_SHARED=$(LINK.c) -G -o $@ |
| 80 | endif |
| 81 | |
| 82 | # Linux GNU C Compiler |
| 83 | ifeq ($(OSNAME), linux) |
| 84 | # GNU Compiler options needed to build it |
| 85 | COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer |
| 86 | # Options that help find errors |
| 87 | COMMON_FLAGS+= -W -Wall -Wno-unused -Wno-parentheses |
| 88 | ifeq ($(OPT), true) |
| 89 | CFLAGS=-O2 $(COMMON_FLAGS) |
| 90 | else |
| 91 | CFLAGS=-g $(COMMON_FLAGS) |
| 92 | endif |
| 93 | # Object files needed to create library |
| 94 | OBJECTS=$(SOURCES:%.c=%.o) |
| 95 | # Library name and options needed to build it |
| 96 | LIBRARY=lib$(LIBNAME).so |
| 97 | LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text |
| 98 | # Libraries we are dependent on |
| 99 | LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc |
| 100 | # Building a shared library |
| 101 | LINK_SHARED=$(LINK.c) -shared -o $@ |
| 102 | endif |
| 103 | |
| 104 | # Windows Microsoft C/C++ Optimizing Compiler Version 12 |
| 105 | ifeq ($(OSNAME), win32) |
| 106 | CC=cl |
| 107 | # Compiler options needed to build it |
| 108 | COMMON_FLAGS=-Gy -DWIN32 |
| 109 | # Options that help find errors |
| 110 | COMMON_FLAGS+=-W0 -WX |
| 111 | ifeq ($(OPT), true) |
| 112 | CFLAGS= -Ox -Op -Zi $(COMMON_FLAGS) |
| 113 | else |
| 114 | CFLAGS= -Od -Zi $(COMMON_FLAGS) |
| 115 | endif |
| 116 | # Sources need java_crw_demo |
| 117 | SOURCES += ../java_crw_demo/java_crw_demo.c |
| 118 | # Object files needed to create library |
| 119 | OBJECTS=$(SOURCES:%.c=%.obj) |
| 120 | # Library name and options needed to build it |
| 121 | LIBRARY=$(LIBNAME).dll |
| 122 | LDFLAGS= |
| 123 | # Libraries we are dependent on |
| 124 | LIBRARIES=$(JDK)/ |
| 125 | # Building a shared library |
| 126 | LINK_SHARED=link -dll -out:$@ |
| 127 | endif |
| 128 | |
| 129 | # Common -I options |
| 130 | CFLAGS += -I. |
| 131 | CFLAGS += -I../agent_util |
| 132 | CFLAGS += -I../java_crw_demo |
| 133 | CFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME) |
| 134 | |
| 135 | # Default rule (build both native library and jar file) |
| 136 | all: $(LIBRARY) $(JARFILE) |
| 137 | |
| 138 | # Build native library |
| 139 | $(LIBRARY): $(OBJECTS) |
| 140 | $(LINK_SHARED) $(OBJECTS) $(LIBRARIES) |
| 141 | |
| 142 | # Build jar file |
| 143 | $(JARFILE): $(JAVA_SOURCES) |
| 144 | rm -f -r classes |
| 145 | mkdir -p classes |
| 146 | $(JDK)/bin/javac -d classes $(JAVA_SOURCES) |
| 147 | (cd classes; $(JDK)/bin/jar cf ../$@ *) |
| 148 | |
| 149 | # Cleanup the built bits |
| 150 | clean: |
| 151 | rm -f -r classes |
| 152 | rm -f $(LIBRARY) $(JARFILE) $(OBJECTS) |
| 153 | |
| 154 | # Simple tester |
| 155 | test: all |
| 156 | LD_LIBRARY_PATH=. $(JDK)/bin/java -agentlib:$(LIBNAME) -Xbootclasspath/a:./$(JARFILE) -version |
| 157 | |
| 158 | # Compilation rule only needed on Windows |
| 159 | ifeq ($(OSNAME), win32) |
| 160 | %.obj: %.c |
| 161 | $(COMPILE.c) $< |
| 162 | endif |
| 163 | |