1 #
   2 # Copyright (c) 2009, 2010, 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 PACKAGE = sun.security.ec
  93 PRODUCT = sun
  94 
  95 #
  96 # The following is for when we need to do postprocessing
  97 # (signing) against a read-only build.  If the OUTPUTDIR
  98 # isn't writable, the build currently crashes out.
  99 #
 100 ifndef OPENJDK
 101   ifdef ALT_JCE_BUILD_DIR
 102     # =====================================================
 103     # Where to place the output, in case we're building from a read-only
 104     # build area.  (e.g. a release engineering build.)
 105     JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
 106     IGNORE_WRITABLE_OUTPUTDIR_TEST=true
 107   else
 108     JCE_BUILD_DIR=${TEMPDIR}
 109   endif
 110 endif
 111 
 112 include $(BUILDDIR)/common/Defs.gmk
 113 
 114 #
 115 # Location for the newly built classfiles.
 116 #
 117 CLASSDESTDIR = $(TEMPDIR)/classes
 118 
 119 #
 120 # Java files
 121 #
 122 AUTO_FILES_JAVA_DIRS = $(PKGDIR)
 123 
 124 #
 125 # Exclude the sources that get built by ../other/Makefile
 126 #
 127 AUTO_JAVA_PRUNE = \
 128     ECKeyFactory.java \
 129     ECParameters.java \
 130     ECPrivateKeyImpl.java \
 131     ECPublicKeyImpl.java \
 132     NamedCurve.java
 133 
 134 #
 135 # Some licensees do not get the native ECC sources, but we still need to
 136 # be able to build "all" for them.  Check here to see if the sources are
 137 # available.  If not, then skip them.
 138 #
 139 
 140 NATIVE_ECC_AVAILABLE := $(shell \
 141     if [ -d $(SHARE_SRC)/native/$(PKGDIR)/impl ] ; then \
 142         $(ECHO) true; \
 143     else \
 144         $(ECHO) false; \
 145     fi)
 146 
 147 ifeq ($(NATIVE_ECC_AVAILABLE), true)
 148 
 149   LIBRARY = sunec
 150 
 151   #
 152   # Java files that define native methods
 153   #
 154   FILES_export = \
 155       $(PKGDIR)/ECDHKeyAgreement.java \
 156       $(PKGDIR)/ECDSASignature.java \
 157       $(PKGDIR)/ECKeyPairGenerator.java
 158 
 159   JAVAHFLAGS += -classpath $(CLASSDESTDIR)
 160 
 161   #
 162   # C and C++ files
 163   #
 164   include FILES_c.gmk
 165 
 166   FILES_cpp = ECC_JNI.cpp
 167 
 168   CPLUSPLUSLIBRARY=true
 169 
 170   FILES_m = mapfile-vers
 171 
 172   #
 173   # Find native code
 174   #
 175   vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)
 176 
 177   vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/impl
 178 
 179   #
 180   # Find include files
 181   #
 182   OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR)/impl
 183 
 184   #
 185   # Compiler flags
 186   #
 187   OTHER_CFLAGS += -DMP_API_COMPATIBLE -DNSS_ECC_MORE_THAN_SUITE_B
 188 
 189   #
 190   # Libraries to link
 191   #
 192   ifeq ($(PLATFORM), windows)
 193     OTHER_LDLIBS += $(JVMLIB)
 194   else
 195     OTHER_LDLIBS = -ldl $(JVMLIB) $(LIBCXX)
 196   endif
 197 
 198   include $(BUILDDIR)/common/Mapfile-vers.gmk
 199 
 200   include $(BUILDDIR)/common/Library.gmk
 201 
 202 else # NATIVE_ECC_AVAILABLE
 203 
 204   include $(BUILDDIR)/common/Classes.gmk
 205 
 206 endif # NATIVE_ECC_AVAILABLE
 207 
 208 #
 209 # We use a variety of subdirectories in the $(TEMPDIR) depending on what
 210 # part of the build we're doing.  Both OPENJDK/JDK builds are initially
 211 # done in the unsigned area.  When files are signed in JDK,
 212 # they will be placed in the appropriate area.
 213 #
 214 UNSIGNED_DIR = $(TEMPDIR)/unsigned
 215 
 216 include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
 217 
 218 #
 219 # Rules
 220 #
 221 
 222 ifdef OPENJDK
 223 all: build-jar install-jar
 224 else
 225 all: build-jar install-prebuilt
 226         $(build-warning)
 227 endif
 228 
 229 
 230 # =====================================================
 231 # Build the unsigned sunec.jar file.
 232 #
 233 
 234 JAR_DESTFILE = $(EXTDIR)/sunec.jar
 235 
 236 #
 237 # Since the -C option to jar is used below, each directory entry must be
 238 # preceded with the appropriate directory to "cd" into.
 239 #
 240 JAR_DIRS = $(patsubst %, -C $(CLASSDESTDIR) %, $(AUTO_FILES_JAVA_DIRS))
 241 
 242 build-jar: $(UNSIGNED_DIR)/sunec.jar
 243 
 244 #
 245 # Build sunec.jar.
 246 #
 247 $(UNSIGNED_DIR)/sunec.jar: build
 248         $(prep-target)
 249         $(BOOT_JAR_CMD) cf $@ $(JAR_DIRS) \
 250             $(BOOT_JAR_JFLAGS)
 251         @$(java-vm-cleanup)
 252 
 253 
 254 ifndef OPENJDK
 255 # =====================================================
 256 # Sign the provider jar file.  Not needed for OpenJDK.
 257 #
 258 
 259 SIGNED_DIR = $(JCE_BUILD_DIR)/signed
 260 
 261 sign: sign-jar
 262 
 263 sign-jar: $(SIGNED_DIR)/sunec.jar
 264 
 265 ifndef ALT_JCE_BUILD_DIR
 266 $(SIGNED_DIR)/sunec.jar: $(UNSIGNED_DIR)/sunec.jar
 267 else
 268 #
 269 # We have to remove the build dependency, otherwise, we'll try to rebuild it
 270 # which we can't do on a read-only filesystem.
 271 #
 272 $(SIGNED_DIR)/sunec.jar:
 273         @if [ ! -r $(UNSIGNED_DIR)/sunec.jar ] ; then \
 274             $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunec.jar"; \
 275             exit 1; \
 276         fi
 277 endif
 278         $(call sign-file, $(UNSIGNED_DIR)/sunec.jar)
 279 
 280 
 281 # =====================================================
 282 # Create the Release Engineering files.  Signed builds, etc.
 283 #
 284 
 285 release: $(SIGNED_DIR)/sunec.jar
 286         $(RM) $(JCE_BUILD_DIR)/release/sunec.jar
 287         $(MKDIR) -p $(JCE_BUILD_DIR)/release
 288         $(CP) $(SIGNED_DIR)/sunec.jar $(JCE_BUILD_DIR)/release
 289         $(release-warning)
 290 
 291 endif # OPENJDK
 292 
 293 
 294 # =====================================================
 295 # Install routines.
 296 #
 297 
 298 #
 299 # Install sunec.jar, depending on which type is requested.
 300 #
 301 install-jar jar: $(JAR_DESTFILE)
 302 ifndef OPENJDK
 303         $(release-warning)
 304 endif
 305 
 306 ifdef OPENJDK
 307 $(JAR_DESTFILE): $(UNSIGNED_DIR)/sunec.jar
 308 else
 309 $(JAR_DESTFILE): $(SIGNED_DIR)/sunec.jar
 310 endif
 311         $(install-file)
 312 
 313 ifndef OPENJDK
 314 install-prebuilt:
 315         @$(ECHO) "\n>>>Installing prebuilt SunEC provider..."
 316         $(RM) $(JAR_DESTFILE)
 317         $(CP) $(PREBUILT_DIR)/ec/sunec.jar $(JAR_DESTFILE)
 318 endif
 319 
 320 
 321 # =====================================================
 322 # Support routines.
 323 #
 324 
 325 clobber clean::
 326         $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
 327 
 328 .PHONY: build-jar jar install-jar
 329 ifndef OPENJDK
 330 .PHONY: sign sign-jar release install-prebuilt
 331 endif