1 #
   2 # Copyright (c) 2011, 2018, 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.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 include JdkNativeCompilation.gmk
  27 include Modules.gmk
  28 include ProcessMarkdown.gmk
  29 include ToolsJdk.gmk
  30 
  31 # Tell the compiler not to export any functions unless declared so in
  32 # the source code. On Windows, this is the default and cannot be changed.
  33 # On Mac, we have always exported all symbols, probably due to oversight
  34 # and/or misunderstanding. To emulate this, don't hide any symbols
  35 # by default.
  36 # On AIX/xlc we need at least xlc 13.1 for the symbol hiding (see JDK-8214063)
  37 # Also provide an override for non-conformant libraries.
  38 ifeq ($(TOOLCHAIN_TYPE), gcc)
  39   LAUNCHER_CFLAGS += -fvisibility=hidden
  40   LDFLAGS_JDKEXE += -Wl,--exclude-libs,ALL
  41 else ifeq ($(TOOLCHAIN_TYPE), clang)
  42   LAUNCHER_CFLAGS += -fvisibility=hidden
  43 else ifeq ($(TOOLCHAIN_TYPE), solstudio)
  44   LAUNCHER_CFLAGS += -xldscope=hidden
  45 endif
  46 
  47 LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher
  48 LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \
  49     -I$(TOPDIR)/src/java.base/share/native/libjli \
  50     -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \
  51     -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \
  52     #
  53 GLOBAL_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/common/version.rc
  54 JAVA_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/launcher/java.rc
  55 MACOSX_PLIST_DIR := $(TOPDIR)/src/java.base/macosx/native/launcher
  56 JAVA_MANIFEST := $(TOPDIR)/src/java.base/windows/native/launcher/java.manifest
  57 
  58 ################################################################################
  59 # Build standard launcher.
  60 
  61 # Setup make rules for building a standard launcher.
  62 #
  63 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  64 # and the targets generated are listed in a variable by that name. It is also
  65 # used as the name of the executable.
  66 #
  67 # Remaining parameters are named arguments. These include:
  68 # MAIN_MODULE  The module of the main class to launch if different from the
  69 #     current module
  70 # MAIN_CLASS   The Java main class to launch
  71 # JAVA_ARGS   Processed into a -DJAVA_ARGS and added to CFLAGS
  72 # EXTRA_JAVA_ARGS Processed into a -DEXTRA_JAVA_ARGS and is prepended
  73 #     before JAVA_ARGS to CFLAGS, primarily to allow long string literal
  74 #     compile time defines exceeding Visual Studio 2013 limitations.
  75 # CFLAGS   Additional CFLAGS
  76 # CFLAGS_windows   Additional CFLAGS_windows
  77 # LDFLAGS_solaris Additional LDFLAGS_solaris
  78 # RC_FLAGS   Additional RC_FLAGS
  79 # MACOSX_SIGNED   On macosx, sign this binary
  80 # OPTIMIZATION   Override default optimization level (LOW)
  81 # OUTPUT_DIR   Override default output directory
  82 # VERSION_INFO_RESOURCE   Override default Windows resource file
  83 SetupBuildLauncher = $(NamedParamsMacroTemplate)
  84 define SetupBuildLauncherBody
  85   # Setup default values (unless overridden)
  86   ifeq ($$($1_OPTIMIZATION), )
  87     $1_OPTIMIZATION := LOW
  88   endif
  89 
  90   ifeq ($$($1_MAIN_MODULE), )
  91     $1_MAIN_MODULE := $(MODULE)
  92   endif
  93 
  94   $1_JAVA_ARGS += -ms8m
  95   ifneq ($$($1_MAIN_CLASS), )
  96     $1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS)
  97   endif
  98 
  99   ifneq ($$($1_EXTRA_JAVA_ARGS), )
 100     $1_EXTRA_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \
 101       $$(addprefix -J, $$($1_EXTRA_JAVA_ARGS)), "$$a"$(COMMA) )) }'
 102     $1_CFLAGS += -DEXTRA_JAVA_ARGS=$$($1_EXTRA_JAVA_ARGS_STR)
 103   endif
 104   $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \
 105       $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }'
 106   $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR)
 107 
 108   ifeq ($(call isTargetOs, macosx), true)
 109     ifeq ($$($1_MACOSX_SIGNED), true)
 110       $1_PLIST_FILE := Info-privileged.plist
 111         $1_CODESIGN := true
 112     else
 113       $1_PLIST_FILE := Info-cmdline.plist
 114     endif
 115 
 116     $1_LDFLAGS += -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE)
 117 
 118     ifeq ($(STATIC_BUILD), true)
 119       $1_LDFLAGS += -exported_symbols_list \
 120               $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols
 121       $1_LIBS += \
 122           $$(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \
 123           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \
 124           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \
 125           $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \
 126           -framework CoreFoundation \
 127           -framework Foundation \
 128           -framework SystemConfiguration \
 129           -lstdc++ -liconv
 130     endif
 131   endif
 132 
 133   ifeq ($(USE_EXTERNAL_LIBZ), true)
 134     $1_LIBS += -lz
 135   endif
 136 
 137   $1_WINDOWS_JLI_LIB := $(call FindStaticLib, java.base, jli, /libjli)
 138 
 139   $$(eval $$(call SetupJdkExecutable, BUILD_LAUNCHER_$1, \
 140       NAME := $1, \
 141       EXTRA_FILES := $(LAUNCHER_SRC)/main.c, \
 142       OPTIMIZATION := $$($1_OPTIMIZATION), \
 143       CFLAGS := $$(CFLAGS_JDKEXE) $$($1_CFLAGS) \
 144           $(LAUNCHER_CFLAGS) \
 145           $(VERSION_CFLAGS) \
 146           -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \
 147           -DPROGNAME='"$1"' \
 148           $$($1_CFLAGS), \
 149       CFLAGS_linux := -fPIC, \
 150       CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \
 151       CFLAGS_windows := $$($1_CFLAGS_windows), \
 152       DISABLED_WARNINGS_gcc := unused-function, \
 153       LDFLAGS := $$(LDFLAGS_JDKEXE) \
 154           $$(call SET_EXECUTABLE_ORIGIN) \
 155           $$($1_LDFLAGS), \
 156       LDFLAGS_linux := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \
 157           -L$(call FindLibDirForModule, java.base), \
 158       LDFLAGS_macosx := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \
 159           -L$(call FindLibDirForModule, java.base), \
 160       LDFLAGS_solaris := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \
 161           -L$(call FindLibDirForModule, java.base), \
 162       LDFLAGS_aix := -L$(SUPPORT_OUTPUTDIR)/native/java.base, \
 163       LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \
 164       LIBS_linux := -ljli -lpthread $(LIBDL), \
 165       LIBS_macosx := -ljli -framework Cocoa -framework Security \
 166           -framework ApplicationServices, \
 167       LIBS_solaris := -ljli -lthread $(LIBDL), \
 168       LIBS_aix := -ljli_static, \
 169       LIBS_windows := $$($1_WINDOWS_JLI_LIB) \
 170           $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib, \
 171       OUTPUT_DIR := $$($1_OUTPUT_DIR), \
 172       VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \
 173       EXTRA_RC_FLAGS := $$($1_EXTRA_RC_FLAGS), \
 174       MANIFEST := $(JAVA_MANIFEST), \
 175       MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \
 176       CODESIGN := $$($1_CODESIGN), \
 177   ))
 178 
 179   $1 += $$(BUILD_LAUNCHER_$1)
 180   TARGETS += $$($1)
 181 
 182   ifeq ($(call isTargetOs, aix), true)
 183     $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, jli_static)
 184   endif
 185 
 186   ifeq ($(call isTargetOs, windows), true)
 187     $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, java, /libjava) \
 188         $$($1_WINDOWS_JLI_LIB)
 189   endif
 190 endef
 191 
 192 ################################################################################
 193 # Create man pages for jmod to pick up. There should be a one-to-one
 194 # relationship between executables and man pages (even if this is not always
 195 # the case), so piggyback man page generation on the launcher compilation.
 196 
 197 ifeq ($(call isTargetOsType, unix), true)
 198   # Only build manpages on unix systems.
 199   # We assume all our man pages should reside in section 1.
 200 
 201   MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE))))
 202   MAN_FILES_TROFF := $(wildcard $(addsuffix /*.1, $(call FindModuleManDirs, $(MODULE))))
 203 
 204   ifneq ($(MAN_FILES_MD), )
 205     # If we got markdown files, ignore the troff files
 206     ifeq ($(ENABLE_PANDOC), false)
 207       $(info Warning: pandoc not found. Not generating man pages)
 208     else
 209       # Create dynamic man pages from markdown using pandoc. We need
 210       # PANDOC_TROFF_MANPAGE_FILTER, a wrapper around
 211       # PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT. This is created by buildtools-jdk.
 212 
 213       # We should also depend on the source javascript filter
 214       PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT := \
 215           $(TOPDIR)/make/scripts/pandoc-troff-manpage-filter.js
 216 
 217       # The norm in man pages is to display code literals as bold, but pandoc
 218       # "correctly" converts these constructs (encoded in markdown using `...`
 219       # or ```...```) to \f[C]. Ideally, we should use the filter to encapsulate
 220       # the Code/CodeBlock in Strong. While this works for Code, pandoc cannot
 221       # correctly render man page output for CodeBlock wrapped in Strong. So we
 222       # take the easy way out, and post-process the troff output, replacing
 223       # \f[C] with \f[CB]. This has the added benefit of working correctly on
 224       # pandoc prior to version 2.0, which cannot properly produced nested
 225       # formatting in man pages (see https://github.com/jgm/pandoc/issues/3568).
 226       #
 227       # As of pandoc 2.3, the termination of formatting is still broken
 228       # (see https://github.com/jgm/pandoc/issues/4973). We need to replace
 229       # \f[] with \f[R].
 230       MAN_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \
 231           -e 's/\\f\[\]/\\f\[R\]/g'
 232 
 233       # Now generate the man pages from markdown using pandoc
 234       $(eval $(call SetupProcessMarkdown, BUILD_MAN_PAGES, \
 235           DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
 236           FILES := $(MAN_FILES_MD), \
 237           FORMAT := man, \
 238           FILTER := $(PANDOC_TROFF_MANPAGE_FILTER), \
 239           POST_PROCESS := $(MAN_POST_PROCESS), \
 240           REPLACEMENTS := @@VERSION_SHORT@@ => $(VERSION_SHORT), \
 241           EXTRA_DEPS := $(PANDOC_TROFF_MANPAGE_FILTER) \
 242               $(PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT), \
 243       ))
 244 
 245       TARGETS += $(BUILD_MAN_PAGES)
 246     endif
 247   else
 248     # No markdown man pages present
 249     ifeq ($(BUILD_MANPAGES), true)
 250       # BUILD_MANPAGES is a mis-nomer. It really means "copy the pre-generated man pages".
 251       $(eval $(call SetupCopyFiles, COPY_MAN_PAGES, \
 252           DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
 253           FILES := $(MAN_FILES_TROFF), \
 254       ))
 255 
 256       TARGETS += $(COPY_MAN_PAGES)
 257     endif
 258   endif
 259 endif