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