1 #
   2 # Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # The Universal Permissive License (UPL), Version 1.0
   6 #
   7 # Subject to the condition set forth below, permission is hereby granted to
   8 # any person obtaining a copy of this software, associated documentation
   9 # and/or data (collectively the "Software"), free of charge and under any
  10 # and all copyright rights in the Software, and any and all patent rights
  11 # owned or freely licensable by each licensor hereunder covering either (i)
  12 # the unmodified Software as contributed to or provided by such licensor,
  13 # or (ii) the Larger Works (as defined below), to deal in both
  14 #
  15 # (a) the Software, and
  16 #
  17 # (b) any piece of software and/or hardware listed in the lrgrwrks.txt file
  18 # if one is included with the Software (each a "Larger Work" to which the
  19 # Software is contributed by such licensors),
  20 #
  21 # without restriction, including without limitation the rights to copy,
  22 # create derivative works of, display, perform, and distribute the Software
  23 # and make, use, sell, offer for sale, import, export, have made, and have
  24 # sold the Software and the Larger Work(s), and to sublicense the foregoing
  25 # rights on either these or other terms.
  26 #
  27 # This license is subject to the following condition:
  28 #
  29 # The above copyright notice and either this complete permission notice or
  30 # at a minimum a reference to the UPL must be included in all copies or
  31 # substantial portions of the Software.
  32 #
  33 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  34 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  35 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  36 # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  37 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  38 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  39 # USE OR OTHER DEALINGS IN THE SOFTWARE.
  40 #
  41 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  42 # or visit www.oracle.com if you need additional information or have any
  43 # questions.
  44 #
  45 #
  46 
  47 # Single gnu makefile for linux and windows (windows requires cygwin and mingw)
  48 
  49 # Default arch; it is changed below as needed.
  50 ARCH            = i386
  51 OS              = $(shell uname)
  52 AR              = ar
  53 
  54 ## OS = Linux ##
  55 ifeq            ($(OS),Linux)
  56 ifneq           ($(MINGW),)
  57 LIB_EXT         = .dll
  58 CPPFLAGS += -I$(TARGET_DIR)/include
  59 LDFLAGS += -L$(TARGET_DIR)/lib
  60 OS=windows
  61 ifneq           ($(findstring x86_64-,$(MINGW)),)
  62 ARCH=amd64
  63 else
  64 ARCH=i386
  65 endif
  66 CC              = $(MINGW)-gcc
  67 CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW)
  68 else   #linux
  69 CPU             = $(shell uname -m)
  70 ARCH1=$(CPU:x86_64=amd64)
  71 ARCH2=$(ARCH1:i686=i386)
  72 ifdef LP64
  73 CFLAGS/amd64    += -m64
  74 CFLAGS/ppc64    += -m64
  75 CFLAGS/ppc64le  += -m64 -DABI_ELFv2
  76 else
  77 ARCH=$(ARCH2:amd64=i386)
  78 ifneq ($(findstring arm,$(ARCH)),)
  79 ARCH=arm
  80 endif
  81 CFLAGS/i386     += -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/amd64    += -m64
 113 else
 114 ARCH=$(ARCH1:amd64=i386)
 115 CFLAGS/i386     += -m32
 116 endif # LP64
 117 CFLAGS          += $(CFLAGS/$(ARCH))
 118 CFLAGS          += -fPIC
 119 OS              = macosx
 120 LIB_EXT         = .dylib
 121 CC              = gcc
 122 CFLAGS          += -O
 123 # CFLAGS        += -DZ_PREFIX
 124 DLDFLAGS        += -shared
 125 DLDFLAGS        += -lz
 126 LDFLAGS         += -ldl
 127 OUTFLAGS        += -o $@
 128 else
 129 ## OS = Windows ##
 130 OS              = windows
 131 CC              = gcc
 132 CFLAGS          +=  /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi-
 133 CFLAGS          += LIBARCH=\"$(LIBARCH)\"
 134 DLDFLAGS        += /dll /subsystem:windows /incremental:no \
 135                         /export:decode_instruction
 136 OUTFLAGS        += /link /out:$@
 137 LIB_EXT         = .dll
 138 endif   # Darwin
 139 endif   # AIX
 140 endif   # Linux
 141 
 142 LIBARCH         = $(ARCH)
 143 ifdef           LP64
 144 LIBARCH64/i386  = amd64
 145 LIBARCH64       = $(LIBARCH64/$(ARCH))
 146 ifneq           ($(LIBARCH64),)
 147 LIBARCH         = $(LIBARCH64)
 148 endif   # LIBARCH64/$(ARCH)
 149 endif   # LP64
 150 
 151 JDKARCH=$(LIBARCH:i386=i586)
 152 
 153 ifeq            ($(BINUTILS),)
 154 # Pop all the way out of the workspace to look for binutils.
 155 # ...You probably want to override this setting.
 156 BINUTILSDIR     = $(shell cd build/binutils;pwd)
 157 else
 158 BINUTILSDIR     = $(shell cd $(BINUTILS);pwd)
 159 endif
 160 
 161 CPPFLAGS        += -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd
 162 CPPFLAGS        += -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\"
 163 
 164 TARGET_DIR      = build/$(OS)-$(JDKARCH)
 165 TARGET          = $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT)
 166 
 167 SOURCE          = hsdis.c
 168 
 169 LIBRARIES =     $(TARGET_DIR)/bfd/libbfd.a \
 170                 $(TARGET_DIR)/opcodes/libopcodes.a \
 171                 $(TARGET_DIR)/libiberty/libiberty.a
 172 
 173 ifneq ($(MINGW),)
 174 LIBRARIES +=    $(TARGET_DIR)/zlib/libz.a
 175 endif
 176 
 177 DEMO_TARGET     = $(TARGET_DIR)/hsdis-demo
 178 DEMO_SOURCE     = hsdis-demo.c
 179 
 180 .PHONY:  all clean demo both
 181 
 182 all:  $(TARGET)
 183 
 184 both: all all64
 185 
 186 %64:
 187         $(MAKE) LP64=1 ${@:%64=%}
 188 
 189 demo: $(TARGET) $(DEMO_TARGET)
 190 
 191 $(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile
 192         if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi
 193 
 194 $(TARGET_DIR)/Makefile:
 195         (cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" AR="$(AR)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS))
 196 
 197 $(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
 198         $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)
 199 
 200 $(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR)
 201         $(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS)
 202 
 203 $(TARGET_DIR):
 204         [ -d $@ ] || mkdir -p $@
 205 
 206 clean:
 207         rm -rf $(TARGET_DIR)