src/utils/hsdis/Makefile
changeset 47216 71c04702a3d5
parent 46748 4aeae5b90e60
child 51202 59b0d8afc831
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 #
       
     2 # Copyright (c) 2008, 2017, 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 AR		= ar
       
    31 
       
    32 ## OS = SunOS ##
       
    33 ifeq		($(OS),SunOS)
       
    34 CPU             = $(shell uname -p)
       
    35 ARCH1=$(CPU:i586=i386)
       
    36 ARCH=$(ARCH1:i686=i386)
       
    37 OS		= solaris
       
    38 CC 		= cc
       
    39 CFLAGS		+= -KPIC
       
    40 ifdef LP64
       
    41 ifeq ($(ARCH),sparc)
       
    42 ARCH            = sparcv9
       
    43 endif
       
    44 ifeq ($(ARCH),i386)
       
    45 ARCH            = amd64
       
    46 endif
       
    47 endif
       
    48 CFLAGS/sparcv9	+= -xarch=v9
       
    49 CFLAGS/amd64	+= -m64
       
    50 CFLAGS		+= $(CFLAGS/$(ARCH))
       
    51 DLDFLAGS	+= -G
       
    52 LDFLAGS         += -ldl
       
    53 OUTFLAGS	+= -o $@
       
    54 LIB_EXT		= .so
       
    55 else
       
    56 ## OS = Linux ##
       
    57 ifeq		($(OS),Linux)
       
    58 ifneq           ($(MINGW),)
       
    59 LIB_EXT		= .dll
       
    60 CPPFLAGS += -I$(TARGET_DIR)/include
       
    61 LDFLAGS += -L$(TARGET_DIR)/lib
       
    62 OS=windows
       
    63 ifneq           ($(findstring x86_64-,$(MINGW)),)
       
    64 ARCH=amd64
       
    65 else
       
    66 ARCH=i386
       
    67 endif
       
    68 CC 		= $(MINGW)-gcc
       
    69 CONFIGURE_ARGS= --host=$(MINGW) --target=$(MINGW)
       
    70 else   #linux
       
    71 CPU             = $(shell uname -m)
       
    72 ARCH1=$(CPU:x86_64=amd64)
       
    73 ARCH2=$(ARCH1:i686=i386)
       
    74 ARCH=$(ARCH2:sparc64=sparcv9)
       
    75 ifdef LP64
       
    76 CFLAGS/sparcv9	+= -m64
       
    77 CFLAGS/amd64	+= -m64
       
    78 CFLAGS/ppc64	+= -m64
       
    79 CFLAGS/ppc64le  += -m64 -DABI_ELFv2
       
    80 else
       
    81 ARCH=$(ARCH2:amd64=i386)
       
    82 ifneq ($(findstring arm,$(ARCH)),)
       
    83 ARCH=arm
       
    84 endif
       
    85 CFLAGS/i386	+= -m32
       
    86 CFLAGS/sparc	+= -m32
       
    87 endif
       
    88 CFLAGS		+= $(CFLAGS/$(ARCH))
       
    89 CFLAGS		+= -fPIC
       
    90 OS		= linux
       
    91 LIB_EXT		= .so
       
    92 CC 		= gcc
       
    93 endif
       
    94 CFLAGS		+= -O
       
    95 DLDFLAGS	+= -shared
       
    96 LDFLAGS         += -ldl
       
    97 OUTFLAGS	+= -o $@
       
    98 else
       
    99 ## OS = AIX ##
       
   100 ifeq		($(OS),AIX)
       
   101 OS              = aix
       
   102 ARCH            = ppc64
       
   103 CC              = xlc_r
       
   104 CFLAGS          += -DAIX -g -qpic=large -q64
       
   105 CFLAGS/ppc64    += -q64
       
   106 AR              = ar -X64
       
   107 DLDFLAGS        += -qmkshrobj -lz
       
   108 OUTFLAGS        += -o $@
       
   109 LIB_EXT		= .so
       
   110 else
       
   111 ## OS = Darwin ##
       
   112 ifeq ($(OS),Darwin)
       
   113 CPU             = $(shell uname -m)
       
   114 ARCH1=$(CPU:x86_64=amd64)
       
   115 ARCH=$(ARCH1:i686=i386)
       
   116 ifdef LP64
       
   117 CFLAGS/sparcv9  += -m64
       
   118 CFLAGS/amd64    += -m64
       
   119 else
       
   120 ARCH=$(ARCH1:amd64=i386)
       
   121 CFLAGS/i386     += -m32
       
   122 CFLAGS/sparc    += -m32
       
   123 endif # LP64
       
   124 CFLAGS          += $(CFLAGS/$(ARCH))
       
   125 CFLAGS          += -fPIC
       
   126 OS              = macosx
       
   127 LIB_EXT         = .dylib
       
   128 CC              = gcc
       
   129 CFLAGS          += -O
       
   130 # CFLAGS        += -DZ_PREFIX
       
   131 DLDFLAGS        += -shared
       
   132 DLDFLAGS        += -lz
       
   133 LDFLAGS         += -ldl
       
   134 OUTFLAGS        += -o $@
       
   135 else
       
   136 ## OS = Windows ##
       
   137 OS		= windows
       
   138 CC		= gcc
       
   139 CFLAGS		+=  /nologo /MD /W3 /WX /O2 /Fo$(@:.dll=.obj) /Gi-
       
   140 CFLAGS		+= LIBARCH=\"$(LIBARCH)\"
       
   141 DLDFLAGS	+= /dll /subsystem:windows /incremental:no \
       
   142 			/export:decode_instruction
       
   143 OUTFLAGS	+= /link /out:$@
       
   144 LIB_EXT		= .dll
       
   145 endif   # Darwin
       
   146 endif   # AIX
       
   147 endif	# Linux
       
   148 endif	# SunOS
       
   149 
       
   150 LIBARCH		= $(ARCH)
       
   151 ifdef		LP64
       
   152 LIBARCH64/sparc	= sparcv9
       
   153 LIBARCH64/i386	= amd64
       
   154 LIBARCH64	= $(LIBARCH64/$(ARCH))
       
   155 ifneq		($(LIBARCH64),)
       
   156 LIBARCH		= $(LIBARCH64)
       
   157 endif   # LIBARCH64/$(ARCH)
       
   158 endif   # LP64
       
   159 
       
   160 JDKARCH=$(LIBARCH:i386=i586)
       
   161 
       
   162 ifeq            ($(BINUTILS),)
       
   163 # Pop all the way out of the workspace to look for binutils.
       
   164 # ...You probably want to override this setting.
       
   165 BINUTILSDIR	= $(shell cd build/binutils;pwd)
       
   166 else
       
   167 BINUTILSDIR	= $(shell cd $(BINUTILS);pwd)
       
   168 endif
       
   169 
       
   170 CPPFLAGS	+= -I$(BINUTILSDIR)/include -I$(BINUTILSDIR)/bfd -I$(TARGET_DIR)/bfd
       
   171 CPPFLAGS	+= -DLIBARCH_$(LIBARCH) -DLIBARCH=\"$(LIBARCH)\" -DLIB_EXT=\"$(LIB_EXT)\"
       
   172 
       
   173 TARGET_DIR	= build/$(OS)-$(JDKARCH)
       
   174 TARGET		= $(TARGET_DIR)/hsdis-$(LIBARCH)$(LIB_EXT)
       
   175 
       
   176 SOURCE		= hsdis.c
       
   177 
       
   178 LIBRARIES =	$(TARGET_DIR)/bfd/libbfd.a \
       
   179 		$(TARGET_DIR)/opcodes/libopcodes.a \
       
   180 		$(TARGET_DIR)/libiberty/libiberty.a
       
   181 
       
   182 DEMO_TARGET	= $(TARGET_DIR)/hsdis-demo
       
   183 DEMO_SOURCE	= hsdis-demo.c
       
   184 
       
   185 .PHONY:  all clean demo both
       
   186 
       
   187 all:  $(TARGET)
       
   188 
       
   189 both: all all64
       
   190 
       
   191 %64:
       
   192 	$(MAKE) LP64=1 ${@:%64=%}
       
   193 
       
   194 demo: $(TARGET) $(DEMO_TARGET)
       
   195 
       
   196 $(LIBRARIES): $(TARGET_DIR) $(TARGET_DIR)/Makefile
       
   197 	if [ ! -f $@ ]; then cd $(TARGET_DIR); make all-opcodes; fi
       
   198 
       
   199 $(TARGET_DIR)/Makefile:
       
   200 	(cd $(TARGET_DIR); CC=$(CC) CFLAGS="$(CFLAGS)" AR="$(AR)" $(BINUTILSDIR)/configure --disable-nls $(CONFIGURE_ARGS))
       
   201 
       
   202 $(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
       
   203 	$(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)
       
   204 
       
   205 $(DEMO_TARGET): $(DEMO_SOURCE) $(TARGET) $(TARGET_DIR)
       
   206 	$(CC) $(OUTFLAGS) -DTARGET_DIR=\"$(TARGET_DIR)\" $(CPPFLAGS) -g $(CFLAGS/$(ARCH)) $(DEMO_SOURCE) $(LDFLAGS)
       
   207 
       
   208 $(TARGET_DIR):
       
   209 	[ -d $@ ] || mkdir -p $@
       
   210 
       
   211 clean:
       
   212 	rm -rf $(TARGET_DIR)