blob: 84f0c01b81e7c6c41023b8e007f07e47e4ef6ea3 [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
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=java_crw_demo
46SOURCES=java_crw_demo.c
47
48# Solaris Sun C Compiler Version 5.5
49ifeq ($(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 $@
76endif
77
78# Linux GNU C Compiler
79ifeq ($(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 $@
98endif
99
100# Windows Microsoft C/C++ Optimizing Compiler Version 12
101ifeq ($(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:$@
121endif
122
123# Common -I options
124CFLAGS += -I.
125CFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME)
126
127# Default rule (build both native library and jar file)
128all: $(LIBRARY)
129
130# Build native library
131$(LIBRARY): $(OBJECTS)
132 $(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
133
134# Cleanup the built bits
135clean:
136 rm -f -r classes
137 rm -f $(LIBRARY) $(OBJECTS)
138
139# Compilation rule only needed on Windows
140ifeq ($(OSNAME), win32)
141%.obj: %.c
142 $(COMPILE.c) $<
143endif
144