Makefile revision 1472:c18cbe5936b8
1# 2# Copyright (c) 2008, 2009, 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) 30 31## OS = SunOS ## 32ifeq ($(OS),SunOS) 33CPU = $(shell uname -p) 34ARCH1=$(CPU:i586=i386) 35ARCH=$(ARCH1:i686=i386) 36OS = solaris 37CC = cc 38CFLAGS += -KPIC 39ifdef LP64 40ifeq ($(ARCH),sparc) 41ARCH = sparcv9 42endif 43ifeq ($(ARCH),i386) 44ARCH = amd64 45endif 46endif 47CFLAGS/sparcv9 += -xarch=v9 48CFLAGS/amd64 += -m64 49CFLAGS += $(CFLAGS/$(ARCH)) 50DLDFLAGS += -G 51LDFLAGS += -ldl 52OUTFLAGS += -o $@ 53LIB_EXT = .so 54else 55## OS = Linux ## 56ifeq ($(OS),Linux) 57ifneq ($(MINGW),) 58LIB_EXT = .dll 59CPPFLAGS += -I$(TARGET_DIR)/include 60LDFLAGS += -L$(TARGET_DIR)/lib 61OS=windows 62ifneq ($(findstring x86_64-,$(MINGW)),) 63ARCH=amd64 64else 65ARCH=i386 66endif 67CC = $(MINGW)-gcc 68CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW) 69else 70CPU = $(shell uname -m) 71ARCH1=$(CPU:x86_64=amd64) 72ARCH=$(ARCH1:i686=i386) 73CFLAGS/i386 += -m32 74CFLAGS/sparc += -m32 75CFLAGS/sparcv9 += -m64 76CFLAGS/amd64 += -m64 77CFLAGS += $(CFLAGS/$(ARCH)) 78CFLAGS += -fPIC 79OS = linux 80LIB_EXT = .so 81CC = gcc 82endif 83CFLAGS += -O 84DLDFLAGS += -shared 85LDFLAGS += -ldl 86OUTFLAGS += -o $@ 87## OS = Windows ## 88else # !SunOS, !Linux => Windows 89OS = windows 90CC = gcc 91#CPPFLAGS += /D"WIN32" /D"_WINDOWS" /D"DEBUG" /D"NDEBUG" 92CFLAGS += /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi- 93CFLAGS += LIBARCH=\"$(LIBARCH)\"" 94DLDFLAGS += /dll /subsystem:windows /incremental:no \ 95 /export:decode_instruction 96OUTFLAGS += /link /out:$@ 97LIB_EXT = .dll 98endif # Linux 99endif # SunOS 100 101LIBARCH = $(ARCH) 102ifdef LP64 103LIBARCH64/sparc = sparcv9 104LIBARCH64/i386 = amd64 105LIBARCH64 = $(LIBARCH64/$(ARCH)) 106ifneq ($(LIBARCH64),) 107LIBARCH = $(LIBARCH64) 108endif # LIBARCH64/$(ARCH) 109endif # LP64 110 111JDKARCH=$(LIBARCH:i386=i586) 112 113ifeq ($(BINUTILS),) 114# Pop all the way out of the workspace to look for binutils. 115# ...You probably want to override this setting. 116BINUTILSDIR = $(shell cd build/binutils;pwd) 117else 118BINUTILSDIR = $(shell cd $(BINUTILS);pwd) 119endif 120 121CPPFLAGS += -I$(BINUTILSDIR)/include -I$(BINUTILS)/bfd -I$(TARGET_DIR)/bfd 122CPPFLAGS += -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\" 123 124TARGET_DIR = build/$(OS)-$(JDKARCH) 125TARGET = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT) 126 127SOURCE = hsdis.c 128 129LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \ 130 $(TARGET_DIR)/opcodes/libopcodes.a \ 131 $(TARGET_DIR)/libiberty/libiberty.a 132 133DEMO_TARGET = $(TARGET_DIR)/hsdis-demo 134DEMO_SOURCE = hsdis-demo.c 135 136.PHONY: all clean demo both 137 138all: $(TARGET) 139 140both: all all64 141 142%64: 143 $(MAKE) LP64=1 ${@:%64=%} 144 145demo: $(TARGET) $(DEMO_TARGET) 146 147$(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile 148 if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi 149 150$(TARGET_DIR)/Makefile: 151 (cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS)) 152 153$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR) 154 $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES) 155 156$(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR) 157 $(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS) 158 159$(TARGET_DIR): 160 [ -d $@ ] || mkdir -p $@ 161 162clean: 163 rm -rf $(TARGET_DIR) 164