diff mbox series

[11/11] riscv: Add configure script

Message ID 20200711161655.2856-12-zhiwei_liu@c-sky.com
State New
Headers show
Series RISC-V risu porting | expand

Commit Message

LIU Zhiwei July 11, 2020, 4:16 p.m. UTC
For RV64 risu, make CFLAGS="-march=rv64g"

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
 configure          |   4 +-
 upstream/configure | 204 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 upstream/configure
diff mbox series

Patch

diff --git a/configure b/configure
index ca2d7db..00624d3 100755
--- a/configure
+++ b/configure
@@ -58,6 +58,8 @@  guess_arch() {
         ARCH="m68k"
     elif check_define __powerpc64__ ; then
         ARCH="ppc64"
+    elif check_define __riscv && check_define _LP64; then
+        ARCH="riscv64"
     else
         echo "This cpu is not supported by risu. Try -h. " >&2
         exit 1
@@ -139,7 +141,7 @@  Some influential environment variables:
                prefixed with the given string.
 
   ARCH         force target architecture instead of trying to detect it.
-               Valid values=[arm|aarch64|ppc64|ppc64le|m68k]
+               Valid values=[arm|aarch64|ppc64|ppc64le|m68k|riscv64]
 
   CC           C compiler command
   CFLAGS       C compiler flags
diff --git a/upstream/configure b/upstream/configure
new file mode 100644
index 0000000..297cd3a
--- /dev/null
+++ b/upstream/configure
@@ -0,0 +1,204 @@ 
+#!/bin/sh
+# simple risu configure script
+#
+# Copyright (c) 2013 Linaro Limited
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#      Claudio Fontana (Linaro) - initial implementation
+
+# Locate the directory where this configure script is
+SRCDIR="$(cd "$(dirname "$0")"; pwd)"
+
+# Temporary directory used for files created by this script.
+# Like autoconf (and like QEMU) we put this directory in the
+# build directory, which means we can just give it a fixed name and
+# blow it away when configure is run, and we don't need to jump
+# through complicated hoops to delete it when configure exits
+# abnormally (it may be useful for debug purposes on an
+# abnormal exit).
+tmp_dir="config-temp"
+rm -rf "$tmp_dir"
+mkdir -p "$tmp_dir"
+if [ $? -ne 0 ]; then
+    echo "ERROR: could not create temporary directory"
+    exit 1
+fi
+
+compile() {
+    $CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null
+}
+
+link() {
+    $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null
+}
+
+check_define() {
+    c=${tmp_dir}/check_define_${1}
+    cat > ${c}.c <<EOF
+#if !defined($1)
+#error $1 not defined
+#endif
+int main(void) { return 0; }
+EOF
+    compile $c
+}
+
+guess_arch() {
+    if check_define __aarch64__ ; then
+        ARCH="aarch64"
+    elif check_define __arm__ ; then
+        ARCH="arm"
+    elif check_define __i386__ || check_define __x86_64__ ; then
+        ARCH="i386"
+    elif check_define __m68k__ ; then
+        ARCH="m68k"
+    elif check_define __powerpc64__ ; then
+        ARCH="ppc64"
+    elif check_define __riscv ; then
+        if __riscv_xlen == 64; then
+            ARCH="riscv64"
+        elif __riscv_xlen == 32; then
+            ARCH="riscv32"
+        else
+            echo "__riscv_xlen is not supported by risu. " >&2
+            exit 1
+        fi
+    else
+        echo "This cpu is not supported by risu. Try -h. " >&2
+        exit 1
+    fi
+}
+
+check_type() {
+    c=${tmp_dir}/check_type_${1}
+    cat > ${c}.c <<EOF
+#include <inttypes.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main(void) { $1 thisone; return 0; }
+EOF
+    compile $c
+}
+
+check_lib() {
+    c=${tmp_dir}/check_lib${1}
+    cat > ${c}.c <<EOF
+#include <stdint.h>
+#include <$2.h>
+
+int main(void) { $3; return 0; }
+EOF
+    compile $c && link $c $1
+}
+
+generate_config() {
+    cfg=config.h
+    echo "generating config.h..."
+
+    echo "/* config.h - generated by the 'configure' script */" > $cfg
+    echo "#ifndef CONFIG_H" >> $cfg
+    echo "#define CONFIG_H 1" >> $cfg
+
+    if check_lib z zlib "zlibVersion()"; then
+        echo "#define HAVE_ZLIB 1" >> $cfg
+        LDFLAGS=-lz
+    fi
+
+    echo "#endif /* CONFIG_H */" >> $cfg
+
+    echo "...done"
+}
+
+generate_makefilein() {
+    m=Makefile.in
+    echo "generating Makefile.in..."
+
+    echo "# Makefile.in - generated by the 'configure' script" > $m
+    echo "ARCH:=${ARCH}" >> $m
+    echo "CC:=${CC}" >> $m
+    echo "CPPFLAGS:=${CPPFLAGS}" >> $m
+    echo "LDFLAGS:=${LDFLAGS}" >> $m
+    echo "AS:=${AS}" >> $m
+    echo "OBJCOPY:=${OBJCOPY}" >> $m
+    echo "OBJDUMP:=${OBJDUMP}" >> $m
+    echo "STATIC:=${STATIC}" >> $m
+    echo "SRCDIR:=${SRCDIR}" >> $m
+    echo "BUILD_INC:=${BUILD_INC}" >> $m
+
+    echo "...done"
+}
+
+usage() {
+    cat <<EOF
+Usage: [VAR=VALUE]... ./configure [-h|--help] [-s|--static]
+
+  -s/--static - force a static build of risu
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Some influential environment variables:
+  CROSS_PREFIX cross-compiler prefix, defaults to gcc and other tools
+               prefixed with the given string.
+
+  ARCH         force target architecture instead of trying to detect it.
+               Valid values=[arm|aarch64|ppc64|ppc64le|m68k|riscv64]
+
+  CC           C compiler command
+  CFLAGS       C compiler flags
+  CPPFLAGS     C preprocessor flags, e.g. -I<include dir>
+
+  AS           assembler command
+  OBJCOPY      object copy utility command
+  OBJDUMP      object dump utility command
+
+EOF
+}
+
+# STARTUP: entry point
+STATIC=""
+
+for opt do
+  case "$opt" in
+      --help | -h)
+          usage;
+          exit 0;;
+      --static | -s)
+          STATIC="-static"
+          ;;
+
+  esac
+done
+
+CC="${CC-${CROSS_PREFIX}gcc}"
+AS="${AS-${CROSS_PREFIX}as}"
+LD="${LD-${CROSS_PREFIX}ld}"
+OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
+OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"
+
+if test "x${ARCH}" = "x"; then
+    guess_arch
+fi
+
+# Are we in a separate build tree? If so, link the Makefile
+# so that 'make' works.
+if test ! -e Makefile || test -s Makefile; then
+    echo "linking Makefile..."
+    BUILD_INC="-I $(pwd)"
+    ln -sf "${SRCDIR}/Makefile" .
+fi
+
+generate_config
+generate_makefilein
+
+rm -r "$tmp_dir"
+
+echo "type 'make' to start the build"
+exit 0
+