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 |
| 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=hprof |
| 46 | SOURCES= \ |
| 47 | debug_malloc.c \ |
| 48 | hprof_blocks.c \ |
| 49 | hprof_class.c \ |
| 50 | hprof_cpu.c \ |
| 51 | hprof_error.c \ |
| 52 | hprof_event.c \ |
| 53 | hprof_frame.c \ |
| 54 | hprof_init.c \ |
| 55 | hprof_io.c \ |
| 56 | hprof_ioname.c \ |
| 57 | hprof_listener.c \ |
| 58 | hprof_loader.c \ |
| 59 | hprof_monitor.c \ |
| 60 | hprof_object.c \ |
| 61 | hprof_reference.c \ |
| 62 | hprof_site.c \ |
| 63 | hprof_stack.c \ |
| 64 | hprof_string.c \ |
| 65 | hprof_table.c \ |
| 66 | hprof_tag.c \ |
| 67 | hprof_tls.c \ |
| 68 | hprof_trace.c \ |
| 69 | hprof_tracker.c \ |
| 70 | hprof_util.c \ |
| 71 | hprof_md.c |
| 72 | |
| 73 | JAVA_SOURCES=Tracker.java |
| 74 | |
| 75 | # Name of jar file that needs to be created |
| 76 | #JARFILE=hprof.jar |
| 77 | |
| 78 | # Solaris Sun C Compiler Version 5.5 |
| 79 | ifeq ($(OSNAME), solaris) |
| 80 | # Sun Solaris Compiler options needed |
| 81 | COMMON_FLAGS=-mt -KPIC |
| 82 | # Options that help find errors |
| 83 | COMMON_FLAGS+= -Xa -v -xstrconst -xc99=%none |
| 84 | # To make hprof logging code available |
| 85 | COMMON_FLAGS+= -DHPROF_LOGGING |
| 86 | # Check LIBARCH for any special compiler options |
| 87 | LIBARCH=$(shell uname -p) |
| 88 | ifeq ($(LIBARCH), sparc) |
| 89 | COMMON_FLAGS+=-xarch=v8 -xregs=no%appl |
| 90 | endif |
| 91 | ifeq ($(LIBARCH), sparcv9) |
| 92 | COMMON_FLAGS+=-xarch=v9 -xregs=no%appl |
| 93 | endif |
| 94 | ifeq ($(OPT), true) |
| 95 | CFLAGS=-xO2 $(COMMON_FLAGS) -DNDEBUG |
| 96 | else |
| 97 | CFLAGS=-g $(COMMON_FLAGS) -DDEBUG |
| 98 | endif |
| 99 | # Object files needed to create library |
| 100 | OBJECTS=$(SOURCES:%.c=%.o) |
| 101 | # Library name and options needed to build it |
| 102 | LIBRARY=lib$(LIBNAME).so |
| 103 | LDFLAGS=-z defs -ztext |
| 104 | # Libraries we are dependent on |
| 105 | LIBRARIES=-lsocket -lnsl -ldl -lc |
| 106 | # Building a shared library |
| 107 | LINK_SHARED=$(LINK.c) -G -o $@ |
| 108 | endif |
| 109 | |
| 110 | # Linux GNU C Compiler |
| 111 | ifeq ($(OSNAME), linux) |
| 112 | # GNU Compiler options needed to build it |
| 113 | COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer |
| 114 | # Options that help find errors |
| 115 | COMMON_FLAGS+= -W -Wall -Wno-unused -Wno-parentheses |
| 116 | # To allow access to dladdr() |
| 117 | COMMON_FLAGS+= -D_GNU_SOURCE |
| 118 | # To prevent include of procfs.h |
| 119 | COMMON_FLAGS+= -DLINUX |
| 120 | # To make sure code is reentrant |
| 121 | COMMON_FLAGS+= -D_REENTRANT |
| 122 | # To make hprof logging code available |
| 123 | COMMON_FLAGS+= -DHPROF_LOGGING |
| 124 | ifeq ($(OPT), true) |
| 125 | CFLAGS=-O2 $(COMMON_FLAGS) -DNDEBUG |
| 126 | else |
| 127 | CFLAGS=-g $(COMMON_FLAGS) -DDEBUG |
| 128 | endif |
| 129 | # Object files needed to create library |
| 130 | OBJECTS=$(SOURCES:%.c=%.o) |
| 131 | # Library name and options needed to build it |
| 132 | LIBRARY=lib$(LIBNAME).so |
| 133 | LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text |
| 134 | # Libraries we are dependent on |
| 135 | LIBRARIES= -lnsl -ldl -lc |
| 136 | # Building a shared library |
| 137 | LINK_SHARED=$(LINK.c) -shared -o $@ |
| 138 | endif |
| 139 | |
| 140 | # Windows Microsoft C/C++ Optimizing Compiler Version 12 |
| 141 | ifeq ($(OSNAME), win32) |
| 142 | CC=cl |
| 143 | # Compiler options needed to build it |
| 144 | COMMON_FLAGS=-Gy -DWIN32 |
| 145 | # Options that help find errors |
| 146 | COMMON_FLAGS+=-W0 -WX |
| 147 | # To make hprof logging code available |
| 148 | COMMON_FLAGS+= -DHPROF_LOGGING |
| 149 | ifeq ($(OPT), true) |
| 150 | CFLAGS= -Ox -Op -Zi $(COMMON_FLAGS) -DNDEBUG |
| 151 | else |
| 152 | CFLAGS= -Od -Zi $(COMMON_FLAGS) -DDEBUG |
| 153 | endif |
| 154 | # Add java_crw_demo source |
| 155 | SOURCES += ../java_crw_demo.c |
| 156 | # Object files needed to create library |
| 157 | OBJECTS=$(SOURCES:%.c=%.obj) |
| 158 | # Library name and options needed to build it |
| 159 | LIBRARY=$(LIBNAME).dll |
| 160 | LDFLAGS= |
| 161 | # Libraries we are dependent on |
| 162 | LIBRARIES=wsock32.lib winmm.lib |
| 163 | # Building a shared library |
| 164 | LINK_SHARED=link -dll -out:$@ |
| 165 | endif |
| 166 | |
| 167 | # Common -I options |
| 168 | CFLAGS += -I. |
| 169 | CFLAGS += -I../java_crw_demo |
| 170 | CFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME) |
| 171 | |
| 172 | # Default rule (build both native library and jar file) |
| 173 | all: hprof_md.c $(LIBRARY) $(JARFILE) |
| 174 | |
| 175 | # Get platform specific hprof_md.c |
| 176 | hprof_md.c: |
| 177 | rm -f $@ |
| 178 | cp $(OSNAME)/hprof_md.c $@ |
| 179 | |
| 180 | # Build native library |
| 181 | $(LIBRARY): $(OBJECTS) |
| 182 | $(LINK_SHARED) $(OBJECTS) $(LIBRARIES) |
| 183 | |
| 184 | # Build jar file |
| 185 | $(JARFILE): $(JAVA_SOURCES) |
| 186 | rm -f -r classes |
| 187 | mkdir -p classes |
| 188 | $(JDK)/bin/javac -d classes $(JAVA_SOURCES) |
| 189 | (cd classes; $(JDK)/bin/jar cf ../$@ *) |
| 190 | |
| 191 | # Cleanup the built bits |
| 192 | clean: |
| 193 | rm -f -r classes |
| 194 | rm -f $(LIBRARY) $(JARFILE) $(OBJECTS) |
| 195 | |
| 196 | # Simple tester |
| 197 | test: all |
| 198 | LD_LIBRARY_PATH=. $(JDK)/bin/java -agentlib:$(LIBNAME) -Xbootclasspath/a:./$(JARFILE) -version |
| 199 | |
| 200 | # Compilation rule only needed on Windows |
| 201 | ifeq ($(OSNAME), win32) |
| 202 | %.obj: %.c |
| 203 | $(COMPILE.c) $< |
| 204 | endif |
| 205 | |