Makefile 6.3 KB
Newer Older
1
#
D
drchase 已提交
2
# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
3 4
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
5 6 7 8 9 10 11 12 13 14 15 16 17
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to
# any person obtaining a copy of this software, associated documentation
# and/or data (collectively the "Software"), free of charge and under any
# and all copyright rights in the Software, and any and all patent rights
# owned or freely licensable by each licensor hereunder covering either (i)
# the unmodified Software as contributed to or provided by such licensor,
# or (ii) the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file
18
# if one is included with the Software (each a "Larger Work" to which the
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# Software is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy,
# create derivative works of, display, perform, and distribute the Software
# and make, use, sell, offer for sale, import, export, have made, and have
# sold the Software and the Larger Work(s), and to sublicense the foregoing
# rights on either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or
# at a minimum a reference to the UPL must be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
40
#
41 42 43
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
D
drchase 已提交
44
#
45 46
#

47
# Single gnu makefile for solaris, linux and windows (windows requires cygwin and mingw)
48 49 50 51

# Default arch; it is changed below as needed.
ARCH		= i386
OS		= $(shell uname)
52
AR		= ar
53 54 55

## OS = SunOS ##
ifeq		($(OS),SunOS)
56 57 58
CPU             = $(shell uname -p)
ARCH1=$(CPU:i586=i386)
ARCH=$(ARCH1:i686=i386)
59 60
OS		= solaris
CC 		= cc
61 62 63 64 65 66 67 68 69 70 71 72
CFLAGS		+= -KPIC
ifdef LP64
ifeq ($(ARCH),sparc)
ARCH            = sparcv9
endif
ifeq ($(ARCH),i386)
ARCH            = amd64
endif
endif
CFLAGS/sparcv9	+= -xarch=v9
CFLAGS/amd64	+= -m64
CFLAGS		+= $(CFLAGS/$(ARCH))
73
DLDFLAGS	+= -G
74
LDFLAGS         += -ldl
75 76 77 78 79
OUTFLAGS	+= -o $@
LIB_EXT		= .so
else
## OS = Linux ##
ifeq		($(OS),Linux)
80 81 82 83 84 85 86 87 88 89 90 91
ifneq           ($(MINGW),)
LIB_EXT		= .dll
CPPFLAGS += -I$(TARGET_DIR)/include
LDFLAGS += -L$(TARGET_DIR)/lib
OS=windows
ifneq           ($(findstring x86_64-,$(MINGW)),)
ARCH=amd64
else
ARCH=i386
endif
CC 		= $(MINGW)-gcc
CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW)
D
drchase 已提交
92
else   #linux
93 94 95
CPU             = $(shell uname -m)
ARCH1=$(CPU:x86_64=amd64)
ARCH=$(ARCH1:i686=i386)
96
ifdef LP64
97 98
CFLAGS/sparcv9	+= -m64
CFLAGS/amd64	+= -m64
99
CFLAGS/ppc64	+= -m64
100
CFLAGS/ppc64le  += -m64 -DABI_ELFv2
101 102 103 104 105
else
ARCH=$(ARCH1:amd64=i386)
CFLAGS/i386	+= -m32
CFLAGS/sparc	+= -m32
endif
106 107
CFLAGS		+= $(CFLAGS/$(ARCH))
CFLAGS		+= -fPIC
108
OS		= linux
109
LIB_EXT		= .so
110
CC 		= gcc
111 112
endif
CFLAGS		+= -O
113
DLDFLAGS	+= -shared
114
LDFLAGS         += -ldl
115
OUTFLAGS	+= -o $@
116 117 118 119 120 121 122 123 124 125 126 127 128 129
else
## OS = AIX ##
ifeq		($(OS),AIX)
OS              = aix
ARCH            = ppc64
CC              = xlc_r
CFLAGS          += -DAIX -g -qpic=large -q64
CFLAGS/ppc64    += -q64
AR              = ar -X64
DLDFLAGS        += -qmkshrobj -lz
OUTFLAGS        += -o $@
LIB_EXT		= .so
else
## OS = Darwin ##
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
ifeq ($(OS),Darwin)
CPU             = $(shell uname -m)
ARCH1=$(CPU:x86_64=amd64)
ARCH=$(ARCH1:i686=i386)
ifdef LP64
CFLAGS/sparcv9  += -m64
CFLAGS/amd64    += -m64
else
ARCH=$(ARCH1:amd64=i386)
CFLAGS/i386     += -m32
CFLAGS/sparc    += -m32
endif # LP64
CFLAGS          += $(CFLAGS/$(ARCH))
CFLAGS          += -fPIC
OS              = macosx
LIB_EXT         = .dylib
CC              = gcc
CFLAGS          += -O
# CFLAGS        += -DZ_PREFIX
DLDFLAGS        += -shared
DLDFLAGS        += -lz
LDFLAGS         += -ldl
OUTFLAGS        += -o $@
153 154
else
## OS = Windows ##
155 156 157
OS		= windows
CC		= gcc
CFLAGS		+=  /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi-
158
CFLAGS		+= LIBARCH=\"$(LIBARCH)\"
159 160 161 162
DLDFLAGS	+= /dll /subsystem:windows /incremental:no \
			/export:decode_instruction
OUTFLAGS	+= /link /out:$@
LIB_EXT		= .dll
163
endif   # Darwin
164
endif   # AIX
165 166 167 168 169 170 171 172 173 174 175 176 177
endif	# Linux
endif	# SunOS

LIBARCH		= $(ARCH)
ifdef		LP64
LIBARCH64/sparc	= sparcv9
LIBARCH64/i386	= amd64
LIBARCH64	= $(LIBARCH64/$(ARCH))
ifneq		($(LIBARCH64),)
LIBARCH		= $(LIBARCH64)
endif   # LIBARCH64/$(ARCH)
endif   # LP64

178 179 180 181 182 183 184 185 186 187
JDKARCH=$(LIBARCH:i386=i586)

ifeq            ($(BINUTILS),)
# Pop all the way out of the workspace to look for binutils.
# ...You probably want to override this setting.
BINUTILSDIR	= $(shell cd build/binutils;pwd)
else
BINUTILSDIR	= $(shell cd $(BINUTILS);pwd)
endif

188
CPPFLAGS	+= -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd
189 190 191
CPPFLAGS	+= -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\"

TARGET_DIR	= build/$(OS)-$(JDKARCH)
192 193 194 195
TARGET		= $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT)

SOURCE		= hsdis.c

196 197 198
LIBRARIES =	$(TARGET_DIR)/bfd/libbfd.a \
		$(TARGET_DIR)/opcodes/libopcodes.a \
		$(TARGET_DIR)/libiberty/libiberty.a
199

200
DEMO_TARGET	= $(TARGET_DIR)/hsdis-demo
201 202 203 204
DEMO_SOURCE	= hsdis-demo.c

.PHONY:  all clean demo both

205
all:  $(TARGET)
206 207 208 209 210 211 212 213

both: all all64

%64:
	$(MAKE) LP64=1 ${@:%64=%}

demo: $(TARGET) $(DEMO_TARGET)

214 215 216 217
$(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile
	if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi

$(TARGET_DIR)/Makefile:
218
	(cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" AR="$(AR)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS))
219 220

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
221
	$(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)
222 223

$(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR)
224
	$(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS)
225 226 227 228 229 230

$(TARGET_DIR):
	[ -d $@ ] || mkdir -p $@

clean:
	rm -rf $(TARGET_DIR)