1 #
   2 # Copyright (c) 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 ################################################################################
  27 # Setup softfloat library
  28 ################################################################################
  29 AC_DEFUN_ONCE([LIB_SETUP_SOFTFLOAT],
  30 [
  31   # define options
  32   AC_ARG_WITH(sflt, [AS_HELP_STRING([--with-sflt],
  33       [specify prefix directory for the SoftFloat-3 prefix
  34       (expecting PATH/lib/softfloat.a, PATH/include/softfloat.h and PATH/share/softfloat/softfloat.md)])])
  35 
  36   AC_ARG_WITH(sflt-lib, [AS_HELP_STRING([--with-sflt-lib],
  37       [specify the path to SoftFloat-3 static library])])
  38 
  39   AC_ARG_WITH(sflt-include, [AS_HELP_STRING([--with-sflt-include],
  40       [specify the path to SoftFloat-3 include directory])])
  41 
  42   AC_ARG_WITH(sflt-license, [AS_HELP_STRING([--with-sflt-license],
  43       [specify the path to SoftFloat-3 license file])])
  44 
  45   # check if softfloat can be used and if the user enabled it
  46   AC_MSG_CHECKING([if softfloat library should be used])
  47   if test "x$USES_LIB_SOFTFLOAT" = "xtrue"; then
  48     SOFTFLOAT_SPECIFIED=no
  49 
  50     if test "x${with_sflt}" != x; then
  51       if test "x${with_sflt}" = "xyes" || test "x${with_sflt}" = "xno"; then
  52         AC_MSG_RESULT([error])
  53         AC_MSG_ERROR([--with-sflt must have a value])
  54       fi
  55       SOFTFLOAT_CFLAGS="-I${with_sflt}/include -DSOFTFLOAT_EXTERNAL"
  56       SOFTFLOAT_LIBS="${with_sflt}/lib/softfloat.a"
  57       SOFTFLOAT_SPECIFIED=yes
  58     fi
  59     if test "x${with_sflt_include}" != x; then
  60       if test "x${with_sflt_include}" = "xyes" || test "x${with_sflt_include}" = "xno"; then
  61         AC_MSG_RESULT([error])
  62         AC_MSG_ERROR([--with-sflt-include must have a value])
  63       fi
  64       SOFTFLOAT_CFLAGS="-I${with_sflt_include} -DSOFTFLOAT_EXTERNAL"
  65       SOFTFLOAT_SPECIFIED=yes
  66     fi
  67     if test "x${with_sflt_lib}" != x; then
  68       if test "x${with_sflt_lib}" = "xyes" || test "x${with_sflt_lib}" = "xno"; then
  69         AC_MSG_RESULT([error])
  70         AC_MSG_ERROR([--with-sflt-lib must have a value])
  71       fi
  72       SOFTFLOAT_LIBS="${with_sflt_lib}"
  73       SOFTFLOAT_SPECIFIED=yes
  74     fi
  75 
  76     if test "x$SOFTFLOAT_SPECIFIED" = xno; then
  77       AC_MSG_RESULT([no, system softfp used])
  78       AC_MSG_NOTICE([Floating point operations may be less precise by a very small amount])
  79       SOFTFLOAT_LICENSE=
  80       SOFTFLOAT_CFLAGS=
  81       SOFTFLOAT_LIBS=
  82     else
  83       AC_MSG_RESULT([yes])
  84 
  85       AC_MSG_CHECKING([for softfloat preprocessor flags])
  86       AC_MSG_RESULT([$SOFTFLOAT_CFLAGS])
  87 
  88       AC_MSG_CHECKING([for softfloat linker flags])
  89       AC_MSG_RESULT([$SOFTFLOAT_LIBS])
  90 
  91       AC_MSG_CHECKING([if softfloat works])
  92       AC_LANG_PUSH(C)
  93       OLD_CFLAGS="$CFLAGS"
  94       CFLAGS="$CFLAGS $SOFTFLOAT_CFLAGS"
  95       OLD_LIBS="$LIBS"
  96       LIBS="$LIBS $SOFTFLOAT_LIBS"
  97       AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <softfloat.h>],
  98           [
  99             return f32_to_i32(f32_sub(i32_to_f32(1), i32_to_f32(1)), softfloat_round_near_even, false);
 100           ])],
 101           [SOFTFLOAT_WORKS=yes],
 102           [SOFTFLOAT_WORKS=no]
 103       )
 104       CFLAGS="$OLD_CFLAGS"
 105       LIBS="$OLD_LIBS"
 106       AC_LANG_POP(C)
 107       AC_MSG_RESULT([$SOFTFLOAT_WORKS])
 108 
 109       if test "x$SOFTFLOAT_WORKS" = xno; then
 110         HELP_MSG_MISSING_DEPENDENCY([softfloat])
 111         AC_MSG_ERROR([Found softfloat but could not link and compile with it. $HELP_MSG])
 112       fi
 113 
 114       SOFTFLOAT_LICENSE=""
 115       AC_MSG_CHECKING([for softfloat license])
 116 
 117       if test "x$with_sflt_license" = "xyes" || test "x$with_sflt_license" = "xno"; then
 118         AC_MSG_RESULT([error])
 119         AC_MSG_ERROR([--with-sflt-license must have a value])
 120       elif test "x$with_sflt_license" != "x"; then
 121         AC_MSG_RESULT([$with_sflt_license])
 122         SOFTFLOAT_LICENSE="$with_sflt_license"
 123         BASIC_FIXUP_PATH(SOFTFLOAT_LICENSE)
 124         if test ! -f "$SOFTFLOAT_LICENSE"; then
 125           AC_MSG_ERROR([$SOFTFLOAT_LICENSE cannot be found])
 126         fi
 127       else
 128         if test "x$with_sflt" != "x" && test -f "$with_sflt/share/softfloat/softfloat.md"; then
 129           SOFTFLOAT_LICENSE="$with_sflt/share/softfloat/softfloat.md"
 130           AC_MSG_RESULT([$SOFTFLOAT_LICENSE])
 131           BASIC_FIXUP_PATH(SOFTFLOAT_LICENSE)
 132         else
 133           AC_MSG_RESULT([error])
 134           AC_MSG_ERROR([softfloat license file cannot be found])
 135         fi
 136       fi
 137 
 138     fi
 139   else
 140     AC_MSG_RESULT([no, not needed])
 141     if test "x${with_sflt}" != x && test "x${with_sflt}" != xno; then
 142       AC_MSG_WARN([[not building for sflt, so --with-sflt is ignored]])
 143     fi
 144     if test "x${with_sflt_lib}" != x && test "x${with_sflt_lib}" != xno; then
 145       AC_MSG_WARN([[not building for sflt, so --with-sflt-lib is ignored]])
 146     fi
 147     if test "x${with_sflt_include}" != x && test "x${with_sflt_include}" != xno; then
 148       AC_MSG_WARN([[not building for sflt, so --with-sflt-include is ignored]])
 149     fi
 150     if test "x${with_sflt_license}" != x && test "x${with_sflt_license}" != xno; then
 151       AC_MSG_WARN([[not building for sflt, so --with-sflt-license is ignored]])
 152     fi
 153     SOFTFLOAT_CFLAGS=
 154     SOFTFLOAT_LIBS=
 155     SOFTFLOAT_LICENSE=
 156   fi
 157 
 158   AC_SUBST(SOFTFLOAT_LIBS)
 159   AC_SUBST(SOFTFLOAT_CFLAGS)
 160   AC_SUBST(SOFTFLOAT_LICENSE)
 161 ])