Makefile 4.9 KB
Newer Older
1
#
2
# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
19 20 21
# 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.
22 23 24
#  
#

25
# Single gnu makefile for solaris, linux and windows (windows requires cygwin and mingw)
26 27 28 29 30 31 32

# Default arch; it is changed below as needed.
ARCH		= i386
OS		= $(shell uname)

## OS = SunOS ##
ifeq		($(OS),SunOS)
33 34 35
CPU             = $(shell uname -p)
ARCH1=$(CPU:i586=i386)
ARCH=$(ARCH1:i686=i386)
36 37
OS		= solaris
CC 		= cc
38 39 40 41 42 43 44 45 46 47 48 49
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))
50
DLDFLAGS	+= -G
51
LDFLAGS         += -ldl
52 53 54 55 56
OUTFLAGS	+= -o $@
LIB_EXT		= .so
else
## OS = Linux ##
ifeq		($(OS),Linux)
57 58 59 60 61 62 63 64 65 66 67 68
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)
69
else   #linux 
70 71 72
CPU             = $(shell uname -m)
ARCH1=$(CPU:x86_64=amd64)
ARCH=$(ARCH1:i686=i386)
73
ifdef LP64
74 75
CFLAGS/sparcv9	+= -m64
CFLAGS/amd64	+= -m64
76 77 78 79 80
else
ARCH=$(ARCH1:amd64=i386)
CFLAGS/i386	+= -m32
CFLAGS/sparc	+= -m32
endif
81 82
CFLAGS		+= $(CFLAGS/$(ARCH))
CFLAGS		+= -fPIC
83
OS		= linux
84
LIB_EXT		= .so
85
CC 		= gcc
86 87
endif
CFLAGS		+= -O
88
DLDFLAGS	+= -shared
89
LDFLAGS         += -ldl
90 91
OUTFLAGS	+= -o $@
## OS = Windows ##
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
else   # !SunOS, !Linux => Darwin or Windows
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 $@
else #Windows
117 118
OS		= windows
CC		= gcc
119
#CPPFLAGS	+= /D"WIN32" /D"_WINDOWS" /D"DEBUG" /D"NDEBUG"
120
CFLAGS		+=  /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi-
121
CFLAGS		+= LIBARCH=\"$(LIBARCH)\"
122 123 124 125
DLDFLAGS	+= /dll /subsystem:windows /incremental:no \
			/export:decode_instruction
OUTFLAGS	+= /link /out:$@
LIB_EXT		= .dll
126
endif   # Darwin
127 128 129 130 131 132 133 134 135 136 137 138 139
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

140 141 142 143 144 145 146 147 148 149
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

150
CPPFLAGS	+= -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd
151 152 153
CPPFLAGS	+= -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\"

TARGET_DIR	= build/$(OS)-$(JDKARCH)
154 155 156 157
TARGET		= $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT)

SOURCE		= hsdis.c

158 159 160
LIBRARIES =	$(TARGET_DIR)/bfd/libbfd.a \
		$(TARGET_DIR)/opcodes/libopcodes.a \
		$(TARGET_DIR)/libiberty/libiberty.a
161

162
DEMO_TARGET	= $(TARGET_DIR)/hsdis-demo
163 164 165 166
DEMO_SOURCE	= hsdis-demo.c

.PHONY:  all clean demo both

167
all:  $(TARGET)
168 169 170 171 172 173 174 175

both: all all64

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

demo: $(TARGET) $(DEMO_TARGET)

176 177 178 179 180
$(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile
	if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi

$(TARGET_DIR)/Makefile:
	(cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS))
181 182

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
183
	$(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)
184 185

$(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR)
186
	$(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS)
187 188 189 190 191 192

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

clean:
	rm -rf $(TARGET_DIR)