1# 2# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# This code is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License version 2 only, as 7# published by the Free Software Foundation. 8# 9# This code is distributed in the hope that it will be useful, but WITHOUT 10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12# version 2 for more details (a copy is included in the LICENSE file that 13# accompanied this code). 14# 15# You should have received a copy of the GNU General Public License version 16# 2 along with this work; if not, write to the Free Software Foundation, 17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18# 19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20# or visit www.oracle.com if you need additional information or have any 21# questions. 22# 23# 24 25# Single gnu makefile for solaris, linux and windows (windows requires cygwin and mingw) 26 27# Default arch; it is changed below as needed. 28ARCH = i386 29OS = $(shell uname) 30AR = ar 31 32## OS = SunOS ## 33ifeq ($(OS),SunOS) 34CPU = $(shell uname -p) 35ARCH1=$(CPU:i586=i386) 36ARCH=$(ARCH1:i686=i386) 37OS = solaris 38CC = cc 39CFLAGS += -KPIC 40ifdef LP64 41ifeq ($(ARCH),sparc) 42ARCH = sparcv9 43endif 44ifeq ($(ARCH),i386) 45ARCH = amd64 46endif 47endif 48CFLAGS/sparcv9 += -xarch=v9 49CFLAGS/amd64 += -m64 50CFLAGS += $(CFLAGS/$(ARCH)) 51DLDFLAGS += -G 52LDFLAGS += -ldl 53OUTFLAGS += -o $@ 54LIB_EXT = .so 55else 56## OS = Linux ## 57ifeq ($(OS),Linux) 58ifneq ($(MINGW),) 59LIB_EXT = .dll 60CPPFLAGS += -I$(TARGET_DIR)/include 61LDFLAGS += -L$(TARGET_DIR)/lib 62OS=windows 63ifneq ($(findstring x86_64-,$(MINGW)),) 64ARCH=amd64 65else 66ARCH=i386 67endif 68CC = $(MINGW)-gcc 69CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW) 70else #linux 71CPU = $(shell uname -m) 72ARCH1=$(CPU:x86_64=amd64) 73ARCH=$(ARCH1:i686=i386) 74ifdef LP64 75CFLAGS/sparcv9 += -m64 76CFLAGS/amd64 += -m64 77CFLAGS/ppc64 += -m64 78CFLAGS/ppc64le += -m64 -DABI_ELFv2 79else 80ARCH=$(ARCH1:amd64=i386) 81CFLAGS/i386 += -m32 82CFLAGS/sparc += -m32 83endif 84CFLAGS += $(CFLAGS/$(ARCH)) 85CFLAGS += -fPIC 86OS = linux 87LIB_EXT = .so 88CC = gcc 89endif 90CFLAGS += -O 91DLDFLAGS += -shared 92LDFLAGS += -ldl 93OUTFLAGS += -o $@ 94else 95## OS = AIX ## 96ifeq ($(OS),AIX) 97OS = aix 98ARCH = ppc64 99CC = xlc_r 100CFLAGS += -DAIX -g -qpic=large -q64 101CFLAGS/ppc64 += -q64 102AR = ar -X64 103DLDFLAGS += -qmkshrobj -lz 104OUTFLAGS += -o $@ 105LIB_EXT = .so 106else 107## OS = Darwin ## 108ifeq ($(OS),Darwin) 109CPU = $(shell uname -m) 110ARCH1=$(CPU:x86_64=amd64) 111ARCH=$(ARCH1:i686=i386) 112ifdef LP64 113CFLAGS/sparcv9 += -m64 114CFLAGS/amd64 += -m64 115else 116ARCH=$(ARCH1:amd64=i386) 117CFLAGS/i386 += -m32 118CFLAGS/sparc += -m32 119endif # LP64 120CFLAGS += $(CFLAGS/$(ARCH)) 121CFLAGS += -fPIC 122OS = macosx 123LIB_EXT = .dylib 124CC = gcc 125CFLAGS += -O 126# CFLAGS += -DZ_PREFIX 127DLDFLAGS += -shared 128DLDFLAGS += -lz 129LDFLAGS += -ldl 130OUTFLAGS += -o $@ 131else 132## OS = Windows ## 133OS = windows 134CC = gcc 135CFLAGS += /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi- 136CFLAGS += LIBARCH=\"$(LIBARCH)\" 137DLDFLAGS += /dll /subsystem:windows /incremental:no \ 138 /export:decode_instruction 139OUTFLAGS += /link /out:$@ 140LIB_EXT = .dll 141endif # Darwin 142endif # AIX 143endif # Linux 144endif # SunOS 145 146LIBARCH = $(ARCH) 147ifdef LP64 148LIBARCH64/sparc = sparcv9 149LIBARCH64/i386 = amd64 150LIBARCH64 = $(LIBARCH64/$(ARCH)) 151ifneq ($(LIBARCH64),) 152LIBARCH = $(LIBARCH64) 153endif # LIBARCH64/$(ARCH) 154endif # LP64 155 156JDKARCH=$(LIBARCH:i386=i586) 157 158ifeq ($(BINUTILS),) 159# Pop all the way out of the workspace to look for binutils. 160# ...You probably want to override this setting. 161BINUTILSDIR = $(shell cd build/binutils;pwd) 162else 163BINUTILSDIR = $(shell cd $(BINUTILS);pwd) 164endif 165 166CPPFLAGS += -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd 167CPPFLAGS += -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\" 168 169TARGET_DIR = build/$(OS)-$(JDKARCH) 170TARGET = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT) 171 172SOURCE = hsdis.c 173 174LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \ 175 $(TARGET_DIR)/opcodes/libopcodes.a \ 176 $(TARGET_DIR)/libiberty/libiberty.a 177 178DEMO_TARGET = $(TARGET_DIR)/hsdis-demo 179DEMO_SOURCE = hsdis-demo.c 180 181.PHONY: all clean demo both 182 183all: $(TARGET) 184 185both: all all64 186 187%64: 188 $(MAKE) LP64=1 ${@:%64=%} 189 190demo: $(TARGET) $(DEMO_TARGET) 191 192$(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile 193 if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi 194 195$(TARGET_DIR)/Makefile: 196 (cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" AR="$(AR)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS)) 197 198$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR) 199 $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES) 200 201$(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR) 202 $(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS) 203 204$(TARGET_DIR): 205 [ -d $@ ] || mkdir -p $@ 206 207clean: 208 rm -rf $(TARGET_DIR) 209