jrose@535: # jrose@535: # Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. jrose@535: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jrose@535: # jrose@535: # This code is free software; you can redistribute it and/or modify it jrose@535: # under the terms of the GNU General Public License version 2 only, as jrose@535: # published by the Free Software Foundation. jrose@535: # jrose@535: # This code is distributed in the hope that it will be useful, but WITHOUT jrose@535: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jrose@535: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jrose@535: # version 2 for more details (a copy is included in the LICENSE file that jrose@535: # accompanied this code). jrose@535: # jrose@535: # You should have received a copy of the GNU General Public License version jrose@535: # 2 along with this work; if not, write to the Free Software Foundation, jrose@535: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jrose@535: # jrose@535: # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jrose@535: # CA 95054 USA or visit www.sun.com if you need additional information or jrose@535: # have any questions. jrose@535: # jrose@535: # jrose@535: jrose@535: # Single gnu makefile for solaris, linux and windows (windows requires mks or jrose@535: # cygwin). jrose@535: jrose@535: ifeq ($(BINUTILS),) jrose@535: # Pop all the way out of the workspace to look for binutils. jrose@535: # ...You probably want to override this setting. jrose@535: BINUTILS = $(shell cd ../../../../..;pwd)/binutils-2.17-$(LIBARCH) jrose@535: endif jrose@535: jrose@535: # Default arch; it is changed below as needed. jrose@535: ARCH = i386 jrose@535: OS = $(shell uname) jrose@535: jrose@535: CPPFLAGS += -I$(BINUTILS)/include -I$(BINUTILS)/bfd jrose@535: CPPFLAGS += -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\" -DLIBARCH_$(LIBARCH) jrose@535: CPPFLAGS += -DHOTSPOT_OS=\"$(OS)\" -DOS_$(OS) jrose@535: jrose@535: ## OS = SunOS ## jrose@535: ifeq ($(OS),SunOS) jrose@535: ARCH = $(shell uname -p) jrose@535: OS = solaris jrose@535: CC = cc jrose@535: CCFLAGS += -Kpic -g jrose@535: CCFLAGS/amd64 += -xarch=amd64 jrose@535: CCFLAGS/sparcv9 += -xarch=v9 jrose@535: CCFLAGS += $(CCFLAGS/$(LIBARCH)) jrose@535: DLDFLAGS += -G jrose@535: OUTFLAGS += -o $@ jrose@535: LIB_EXT = .so jrose@535: else jrose@535: ## OS = Linux ## jrose@535: ifeq ($(OS),Linux) jrose@535: CPU = $(shell uname -m) jrose@535: ifeq ($(CPU),ia64) jrose@535: ARCH = ia64 jrose@535: else jrose@535: ifeq ($(CPU),x86_64) jrose@535: CCFLAGS += -fPIC jrose@535: endif # x86_64 jrose@535: endif # ia64 jrose@535: OS = linux jrose@535: CC = gcc jrose@535: CCFLAGS += -O jrose@535: DLDFLAGS += -shared jrose@535: OUTFLAGS += -o $@ jrose@535: LIB_EXT = .so jrose@535: CPPFLAGS += -Iinclude -Iinclude/$(OS)_$(ARCH)/ jrose@535: ## OS = Windows ## jrose@535: else # !SunOS, !Linux => Windows jrose@535: OS = win jrose@535: CC = cl jrose@535: #CPPFLAGS += /D"WIN32" /D"_WINDOWS" /D"DEBUG" /D"NDEBUG" jrose@535: CCFLAGS += /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi- jrose@535: CCFLAGS += -Iinclude -Iinclude/gnu -Iinclude/$(OS)_$(ARCH) jrose@535: CCFLAGS += /D"HOTSPOT_LIB_ARCH=\"$(LIBARCH)\"" jrose@535: DLDFLAGS += /dll /subsystem:windows /incremental:no \ jrose@535: /export:decode_instruction jrose@535: OUTFLAGS += /link /out:$@ jrose@535: LIB_EXT = .dll jrose@535: endif # Linux jrose@535: endif # SunOS jrose@535: jrose@535: LIBARCH = $(ARCH) jrose@535: ifdef LP64 jrose@535: LIBARCH64/sparc = sparcv9 jrose@535: LIBARCH64/i386 = amd64 jrose@535: LIBARCH64 = $(LIBARCH64/$(ARCH)) jrose@535: ifneq ($(LIBARCH64),) jrose@535: LIBARCH = $(LIBARCH64) jrose@535: endif # LIBARCH64/$(ARCH) jrose@535: endif # LP64 jrose@535: jrose@535: TARGET_DIR = bin/$(OS) jrose@535: TARGET = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT) jrose@535: jrose@535: SOURCE = hsdis.c jrose@535: jrose@535: LIBRARIES = $(BINUTILS)/bfd/libbfd.a \ jrose@535: $(BINUTILS)/opcodes/libopcodes.a \ jrose@535: $(BINUTILS)/libiberty/libiberty.a jrose@535: jrose@535: DEMO_TARGET = $(TARGET_DIR)/hsdis-demo-$(LIBARCH) jrose@535: DEMO_SOURCE = hsdis-demo.c jrose@535: jrose@535: .PHONY: all clean demo both jrose@535: jrose@535: all: $(TARGET) demo jrose@535: jrose@535: both: all all64 jrose@535: jrose@535: %64: jrose@535: $(MAKE) LP64=1 ${@:%64=%} jrose@535: jrose@535: demo: $(TARGET) $(DEMO_TARGET) jrose@535: jrose@535: $(LIBRARIES): jrose@535: @echo "*** Please build binutils first; see ./README: ***" jrose@535: @sed < ./README '1,/__________/d' | head -20 jrose@535: @echo "..."; exit 1 jrose@535: jrose@535: $(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR) jrose@535: $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CCFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES) jrose@535: jrose@535: $(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR) jrose@535: $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CCFLAGS) $(DEMO_SOURCE) $(LDFLAGS) jrose@535: jrose@535: $(TARGET_DIR): jrose@535: [ -d $@ ] || mkdir -p $@ jrose@535: jrose@535: clean: jrose@535: rm -rf $(TARGET_DIR)