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