1 #
   2 # Copyright (c) 2009, 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 #
  27 # Makefile for building sunec.jar and sunec native library.
  28 #
  29 # This file was derived from make/com/sun/crypto/provider/Makefile.
  30 #
  31 
  32 #
  33 # (The terms "OpenJDK" and "JDK" below refer to OpenJDK and Sun JDK builds
  34 # respectively.)
  35 #
  36 # JCE builds are very different between OpenJDK and JDK.  The OpenJDK JCE
  37 # jar files do not require signing, but those for JDK do.  If an unsigned
  38 # jar file is installed into JDK, things will break when the crypto
  39 # routines are called.
  40 #
  41 # This Makefile does the "real" build of the JCE files.  For OpenJDK,
  42 # the jar files built here are installed directly into the OpenJDK.
  43 #
  44 # For JDK, the binaries use pre-built/pre-signed binary files stored in
  45 # the closed workspace that are not shipped in the OpenJDK workspaces.
  46 # We still build the JDK files here to verify the files compile, and in
  47 # preparation for possible signing.  Developers working on JCE in JDK
  48 # must sign the JCE files before testing.  The JCE signing key is kept
  49 # separate from the JDK workspace to prevent its disclosure.
  50 #
  51 # SPECIAL NOTE TO JCE/JDK developers:  The source files must eventually
  52 # be built, signed, and then the resulting jar files MUST BE CHECKED
  53 # INTO THE CLOSED PART OF THE WORKSPACE*.  This separate step *MUST NOT
  54 # BE FORGOTTEN*, otherwise a bug fixed in the source code will not be
  55 # reflected in the shipped binaries.  The "release" target should be
  56 # used to generate the required files.
  57 #
  58 # There are a number of targets to help both JDK/OpenJDK developers.
  59 #
  60 # Main Targets (JDK/OPENJDK):
  61 #
  62 #     all/clobber/clean         The usual, plus the native libraries.
  63 #                                   If OpenJDK, installs sunec.jar.
  64 #                                   If JDK, installs prebuilt
  65 #                                   sunec.jar.
  66 #
  67 #     jar                       Builds/installs sunec.jar
  68 #                                   If OpenJDK, does not sign.
  69 #                                   If JDK, tries to sign.
  70 #
  71 # Other lesser-used Targets (JDK/OPENJDK):
  72 #
  73 #     build-jar                 Builds sunec.jar
  74 #                                   (does not sign/install)
  75 #
  76 #     install-jar               Alias for "jar" above.
  77 #
  78 # Other targets (JDK only):
  79 #
  80 #     sign                      Alias for sign-jar
  81 #         sign-jar              Builds/signs sunec.jar (no install)
  82 #
  83 #     release                   Builds all targets in preparation
  84 #                               for workspace integration.
  85 #
  86 #     install-prebuilt          Installs the pre-built jar files
  87 #
  88 # This makefile was written to support parallel target execution.
  89 #
  90 
  91 BUILDDIR = ../../..
  92 MODULE  = security-sunec
  93 PACKAGE = sun.security.ec
  94 PRODUCT = sun
  95 
  96 #
  97 # The following is for when we need to do postprocessing
  98 # (signing) against a read-only build.  If the OUTPUTDIR
  99 # isn't writable, the build currently crashes out.
 100 #
 101 ifndef OPENJDK
 102   ifdef ALT_JCE_BUILD_DIR
 103     # =====================================================
 104     # Where to place the output, in case we're building from a read-only
 105     # build area.  (e.g. a release engineering build.)
 106     JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
 107     IGNORE_WRITABLE_OUTPUTDIR_TEST=true
 108   else
 109     JCE_BUILD_DIR=${TEMPDIR}
 110   endif
 111 endif
 112 
 113 include $(BUILDDIR)/common/Defs.gmk
 114 
 115 #
 116 # Location for the newly built classfiles.
 117 #
 118 CLASSDESTDIR = $(TEMPDIR)/classes
 119 
 120 #
 121 # Java files
 122 #
 123 AUTO_FILES_JAVA_DIRS = $(PKGDIR)
 124 
 125 #
 126 # Exclude the sources that get built by ../other/Makefile
 127 #
 128 AUTO_JAVA_PRUNE = \
 129     ECKeyFactory.java \
 130     ECParameters.java \
 131     ECPrivateKeyImpl.java \
 132     ECPublicKeyImpl.java \
 133     NamedCurve.java
 134 
 135 #
 136 # Some licensees do not get the native ECC sources, but we still need to
 137 # be able to build "all" for them.  Check here to see if the sources are
 138 # available.  If not, then skip them.
 139 #
 140 
 141 NATIVE_ECC_AVAILABLE := $(shell \
 142     if [ -d $(SHARE_SRC)/native/$(PKGDIR)/impl ] ; then \
 143         $(ECHO) true; \
 144     else \
 145         $(ECHO) false; \
 146     fi)
 147 
 148 ifeq ($(NATIVE_ECC_AVAILABLE), true)
 149 
 150   LIBRARY = sunec
 151 
 152   #
 153   # Java files that define native methods
 154   #
 155   FILES_export = \
 156       $(PKGDIR)/ECDHKeyAgreement.java \
 157       $(PKGDIR)/ECDSASignature.java \
 158       $(PKGDIR)/ECKeyPairGenerator.java
 159 
 160   JAVAHFLAGS += -classpath $(CLASSDESTDIR)
 161 
 162   #
 163   # C and C++ files
 164   #
 165   include FILES_c.gmk
 166 
 167   FILES_cpp = ECC_JNI.cpp
 168 
 169   CPLUSPLUSLIBRARY=true
 170 
 171   FILES_m = mapfile-vers
 172 
 173   #
 174   # Find native code
 175   #
 176   vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)
 177 
 178   vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/impl
 179 
 180   #
 181   # Find include files
 182   #
 183   OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR)/impl
 184 
 185   #
 186   # Compiler flags
 187   #
 188   OTHER_CFLAGS += -DMP_API_COMPATIBLE -DNSS_ECC_MORE_THAN_SUITE_B
 189 
 190   #
 191   # Libraries to link
 192   #
 193   ifeq ($(PLATFORM), windows)
 194     OTHER_LDLIBS += $(JVMLIB)
 195   else
 196     OTHER_LDLIBS = -ldl $(JVMLIB) $(LIBCXX)
 197   endif
 198 
 199   include $(BUILDDIR)/common/Mapfile-vers.gmk
 200 
 201   include $(BUILDDIR)/common/Library.gmk
 202 
 203 else # NATIVE_ECC_AVAILABLE
 204 
 205   include $(BUILDDIR)/common/Classes.gmk
 206 
 207 endif # NATIVE_ECC_AVAILABLE
 208 
 209 #
 210 # We use a variety of subdirectories in the $(TEMPDIR) depending on what
 211 # part of the build we're doing.  Both OPENJDK/JDK builds are initially
 212 # done in the unsigned area.  When files are signed in JDK,
 213 # they will be placed in the appropriate area.
 214 #
 215 UNSIGNED_DIR = $(TEMPDIR)/unsigned
 216 
 217 include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
 218 
 219 #
 220 # Rules
 221 #
 222 
 223 ifdef OPENJDK
 224 all: build-jar install-jar
 225 else
 226 all: build-jar install-prebuilt
 227         $(build-warning)
 228 endif
 229 
 230 
 231 # =====================================================
 232 # Build the unsigned sunec.jar file.
 233 #
 234 
 235 JAR_DESTFILE = $(EXTDIR)/sunec.jar
 236 
 237 #
 238 # Since the -C option to jar is used below, each directory entry must be
 239 # preceded with the appropriate directory to "cd" into.
 240 #
 241 JAR_DIRS = $(patsubst %, -C $(CLASSDESTDIR) %, $(AUTO_FILES_JAVA_DIRS))
 242 
 243 build-jar: $(UNSIGNED_DIR)/sunec.jar
 244 
 245 #
 246 # Build sunec.jar.
 247 #
 248 $(UNSIGNED_DIR)/sunec.jar: build
 249         $(prep-target)
 250         $(BOOT_JAR_CMD) cf $@ $(JAR_DIRS) \
 251             $(BOOT_JAR_JFLAGS)
 252         @$(java-vm-cleanup)
 253 
 254 
 255 ifndef OPENJDK
 256 # =====================================================
 257 # Sign the provider jar file.  Not needed for OpenJDK.
 258 #
 259 
 260 SIGNED_DIR = $(JCE_BUILD_DIR)/signed
 261 
 262 sign: sign-jar
 263 
 264 sign-jar: $(SIGNED_DIR)/sunec.jar
 265 
 266 ifndef ALT_JCE_BUILD_DIR
 267 $(SIGNED_DIR)/sunec.jar: $(UNSIGNED_DIR)/sunec.jar
 268 else
 269 #
 270 # We have to remove the build dependency, otherwise, we'll try to rebuild it
 271 # which we can't do on a read-only filesystem.
 272 #
 273 $(SIGNED_DIR)/sunec.jar:
 274         @if [ ! -r $(UNSIGNED_DIR)/sunec.jar ] ; then \
 275             $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunec.jar"; \
 276             exit 1; \
 277         fi
 278 endif
 279         $(call sign-file, $(UNSIGNED_DIR)/sunec.jar)
 280 
 281 
 282 # =====================================================
 283 # Create the Release Engineering files.  Signed builds, etc.
 284 #
 285 
 286 release: $(SIGNED_DIR)/sunec.jar
 287         $(RM) $(JCE_BUILD_DIR)/release/sunec.jar
 288         $(MKDIR) -p $(JCE_BUILD_DIR)/release
 289         $(CP) $(SIGNED_DIR)/sunec.jar $(JCE_BUILD_DIR)/release
 290         $(release-warning)
 291 
 292 endif # OPENJDK
 293 
 294 
 295 # =====================================================
 296 # Install routines.
 297 #
 298 
 299 #
 300 # Install sunec.jar, depending on which type is requested.
 301 #
 302 install-jar jar: $(JAR_DESTFILE)
 303 ifndef OPENJDK
 304         $(release-warning)
 305 endif
 306 
 307 ifdef OPENJDK
 308 $(JAR_DESTFILE): $(UNSIGNED_DIR)/sunec.jar
 309 else
 310 $(JAR_DESTFILE): $(SIGNED_DIR)/sunec.jar
 311 endif
 312         $(install-non-module-file)
 313 
 314 ifndef OPENJDK
 315 install-prebuilt:
 316         @$(ECHO) "\n>>>Installing prebuilt SunEC provider..."
 317         $(RM) $(JAR_DESTFILE)
 318         $(CP) $(PREBUILT_DIR)/ec/sunec.jar $(JAR_DESTFILE)
 319 endif
 320 
 321 
 322 # =====================================================
 323 # Support routines.
 324 #
 325 
 326 clobber clean::
 327         $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
 328 
 329 .PHONY: build-jar jar install-jar
 330 ifndef OPENJDK
 331 .PHONY: sign sign-jar release install-prebuilt
 332 endif