Tue, 08 Aug 2017 15:57:29 +0800
merge
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 #
25 # Single gnu makefile for solaris, linux and windows (windows requires cygwin and mingw)
27 # Default arch; it is changed below as needed.
28 ARCH = i386
29 OS = $(shell uname)
30 AR = ar
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 ARCH=$(ARCH1:i686=i386)
74 ifdef LP64
75 CFLAGS/sparcv9 += -m64
76 CFLAGS/amd64 += -m64
77 CFLAGS/ppc64 += -m64
78 else
79 ARCH=$(ARCH1:amd64=i386)
80 CFLAGS/i386 += -m32
81 CFLAGS/sparc += -m32
82 endif
83 CFLAGS += $(CFLAGS/$(ARCH))
84 CFLAGS += -fPIC
85 OS = linux
86 LIB_EXT = .so
87 CC = gcc
88 endif
89 CFLAGS += -O
90 DLDFLAGS += -shared
91 LDFLAGS += -ldl
92 OUTFLAGS += -o $@
93 else
94 ## OS = AIX ##
95 ifeq ($(OS),AIX)
96 OS = aix
97 ARCH = ppc64
98 CC = xlc_r
99 CFLAGS += -DAIX -g -qpic=large -q64
100 CFLAGS/ppc64 += -q64
101 AR = ar -X64
102 DLDFLAGS += -qmkshrobj -lz
103 OUTFLAGS += -o $@
104 LIB_EXT = .so
105 else
106 ## OS = Darwin ##
107 ifeq ($(OS),Darwin)
108 CPU = $(shell uname -m)
109 ARCH1=$(CPU:x86_64=amd64)
110 ARCH=$(ARCH1:i686=i386)
111 ifdef LP64
112 CFLAGS/sparcv9 += -m64
113 CFLAGS/amd64 += -m64
114 else
115 ARCH=$(ARCH1:amd64=i386)
116 CFLAGS/i386 += -m32
117 CFLAGS/sparc += -m32
118 endif # LP64
119 CFLAGS += $(CFLAGS/$(ARCH))
120 CFLAGS += -fPIC
121 OS = macosx
122 LIB_EXT = .dylib
123 CC = gcc
124 CFLAGS += -O
125 # CFLAGS += -DZ_PREFIX
126 DLDFLAGS += -shared
127 DLDFLAGS += -lz
128 LDFLAGS += -ldl
129 OUTFLAGS += -o $@
130 else
131 ## OS = Windows ##
132 OS = windows
133 CC = gcc
134 CFLAGS += /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi-
135 CFLAGS += LIBARCH=\"$(LIBARCH)\"
136 DLDFLAGS += /dll /subsystem:windows /incremental:no \
137 /export:decode_instruction
138 OUTFLAGS += /link /out:$@
139 LIB_EXT = .dll
140 endif # Darwin
141 endif # AIX
142 endif # Linux
143 endif # SunOS
145 LIBARCH = $(ARCH)
146 ifdef LP64
147 LIBARCH64/sparc = sparcv9
148 LIBARCH64/i386 = amd64
149 LIBARCH64 = $(LIBARCH64/$(ARCH))
150 ifneq ($(LIBARCH64),)
151 LIBARCH = $(LIBARCH64)
152 endif # LIBARCH64/$(ARCH)
153 endif # LP64
155 JDKARCH=$(LIBARCH:i386=i586)
157 ifeq ($(BINUTILS),)
158 # Pop all the way out of the workspace to look for binutils.
159 # ...You probably want to override this setting.
160 BINUTILSDIR = $(shell cd build/binutils;pwd)
161 else
162 BINUTILSDIR = $(shell cd $(BINUTILS);pwd)
163 endif
165 CPPFLAGS += -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd
166 CPPFLAGS += -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\"
168 TARGET_DIR = build/$(OS)-$(JDKARCH)
169 TARGET = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT)
171 SOURCE = hsdis.c
173 LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \
174 $(TARGET_DIR)/opcodes/libopcodes.a \
175 $(TARGET_DIR)/libiberty/libiberty.a
177 DEMO_TARGET = $(TARGET_DIR)/hsdis-demo
178 DEMO_SOURCE = hsdis-demo.c
180 .PHONY: all clean demo both
182 all: $(TARGET)
184 both: all all64
186 %64:
187 $(MAKE) LP64=1 ${@:%64=%}
189 demo: $(TARGET) $(DEMO_TARGET)
191 $(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile
192 if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi
194 $(TARGET_DIR)/Makefile:
195 (cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" AR="$(AR)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS))
197 $(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
198 $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)
200 $(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR)
201 $(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS)
203 $(TARGET_DIR):
204 [ -d $@ ] || mkdir -p $@
206 clean:
207 rm -rf $(TARGET_DIR)