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. 28 ARCH = i386 29 OS = $(shell uname) 30 AR = ar 31 32 ## OS = SunOS ## 33 ifeq ($(OS),SunOS) 34 CPU = $(shell uname -p) 35 ARCH1=$(CPU:i586=i386) 36 ARCH=$(ARCH1:i686=i386) 37 OS = solaris 38 CC = cc 39 CFLAGS += -KPIC 40 ifdef LP64 41 ifeq ($(ARCH),sparc) 42 ARCH = sparcv9 43 endif 44 ifeq ($(ARCH),i386) 45 ARCH = amd64 46 endif 47 endif 48 CFLAGS/sparcv9 += -xarch=v9 49 CFLAGS/amd64 += -m64 50 CFLAGS += $(CFLAGS/$(ARCH)) 51 DLDFLAGS += -G 52 LDFLAGS += -ldl 53 OUTFLAGS += -o $@ 54 LIB_EXT = .so 55 else 56 ## OS = Linux ## 57 ifeq ($(OS),Linux) 58 ifneq ($(MINGW),) 59 LIB_EXT = .dll 60 CPPFLAGS += -I$(TARGET_DIR)/include 61 LDFLAGS += -L$(TARGET_DIR)/lib 62 OS=windows 63 ifneq ($(findstring x86_64-,$(MINGW)),) 64 ARCH=amd64 65 else 66 ARCH=i386 67 endif 68 CC = $(MINGW)-gcc 69 CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW) 70 else #linux 71 CPU = $(shell uname -m) 72 ARCH1=$(CPU:x86_64=amd64) 73 ARCH2=$(ARCH1:i686=i386) 74 ARCH=$(ARCH2:ppc64le=ppc64) 75 ifdef LP64 76 CFLAGS/sparcv9 += -m64 77 CFLAGS/amd64 += -m64 78 CFLAGS/ppc64 += -m64 79 else 80 ARCH=$(ARCH1:amd64=i386) 81 CFLAGS/i386 += -m32 82 CFLAGS/sparc += -m32 83 endif 84 CFLAGS += $(CFLAGS/$(ARCH)) 85 CFLAGS += -fPIC 86 OS = linux 87 LIB_EXT = .so 88 CC = gcc 89 endif 90 CFLAGS += -O 91 DLDFLAGS += -shared 92 LDFLAGS += -ldl 93 OUTFLAGS += -o $@ 94 else 95 ## OS = AIX ## 96 ifeq ($(OS),AIX) 97 OS = aix 98 ARCH = ppc64 99 CC = xlc_r 100 CFLAGS += -DAIX -g -qpic=large -q64 101 CFLAGS/ppc64 += -q64 102 AR = ar -X64 103 DLDFLAGS += -qmkshrobj -lz 104 OUTFLAGS += -o $@ 105 LIB_EXT = .so 106 else 107 ## OS = Darwin ## 108 ifeq ($(OS),Darwin) 109 CPU = $(shell uname -m) 110 ARCH1=$(CPU:x86_64=amd64) 111 ARCH=$(ARCH1:i686=i386) 112 ifdef LP64 113 CFLAGS/sparcv9 += -m64 114 CFLAGS/amd64 += -m64 115 else 116 ARCH=$(ARCH1:amd64=i386) 117 CFLAGS/i386 += -m32 118 CFLAGS/sparc += -m32 119 endif # LP64 120 CFLAGS += $(CFLAGS/$(ARCH)) 121 CFLAGS += -fPIC 122 OS = macosx 123 LIB_EXT = .dylib 124 CC = gcc 125 CFLAGS += -O 126 # CFLAGS += -DZ_PREFIX 127 DLDFLAGS += -shared 128 DLDFLAGS += -lz 129 LDFLAGS += -ldl 130 OUTFLAGS += -o $@ 131 else 132 ## OS = Windows ## 133 OS = windows 134 CC = gcc 135 CFLAGS += /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi- 136 CFLAGS += LIBARCH=\"$(LIBARCH)\" 137 DLDFLAGS += /dll /subsystem:windows /incremental:no \ 138 /export:decode_instruction 139 OUTFLAGS += /link /out:$@ 140 LIB_EXT = .dll 141 endif # Darwin 142 endif # AIX 143 endif # Linux 144 endif # SunOS 145 146 LIBARCH = $(ARCH) 147 ifdef LP64 148 LIBARCH64/sparc = sparcv9 149 LIBARCH64/i386 = amd64 150 LIBARCH64 = $(LIBARCH64/$(ARCH)) 151 ifneq ($(LIBARCH64),) 152 LIBARCH = $(LIBARCH64) 153 endif # LIBARCH64/$(ARCH) 154 endif # LP64 155 156 JDKARCH=$(LIBARCH:i386=i586) 157 158 ifeq ($(BINUTILS),) 159 # Pop all the way out of the workspace to look for binutils. 160 # ...You probably want to override this setting. 161 BINUTILSDIR = $(shell cd build/binutils;pwd) 162 else 163 BINUTILSDIR = $(shell cd $(BINUTILS);pwd) 164 endif 165 166 CPPFLAGS += -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd 167 CPPFLAGS += -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\" 168 169 TARGET_DIR = build/$(OS)-$(JDKARCH) 170 TARGET = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT) 171 172 SOURCE = hsdis.c 173 174 LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \ 175 $(TARGET_DIR)/opcodes/libopcodes.a \ 176 $(TARGET_DIR)/libiberty/libiberty.a 177 178 DEMO_TARGET = $(TARGET_DIR)/hsdis-demo 179 DEMO_SOURCE = hsdis-demo.c 180 181 .PHONY: all clean demo both 182 183 all: $(TARGET) 184 185 both: all all64 186 187 %64: 188 $(MAKE) LP64=1 ${@:%64=%} 189 190 demo: $(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 207 clean: 208 rm -rf $(TARGET_DIR)