aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: acbdc4c07b6f53cd1dc0e995e19f326bf7b20c56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
# simple risu configure script - Claudio Fontana

# Locate the directory where this configure script is
SRCDIR="$(cd "$(dirname "$0")"; pwd)"

tmp_dir=`mktemp -d -t risu_configure_check_XXXXXX`

compile() {
    $CC $CFLAGS -c -o ${1}.o ${1}.c 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 __m68k__ ; then
        ARCH="m68k"
    elif check_define __arm__ ; then
        ARCH="arm"
    elif check_define __aarch64__ ; then
        ARCH="aarch64"
    elif check_define __powerpc64__ ; then
        if check_define __BIG_ENDIAN__; then
            ARCH="ppc64"
        else
            ARCH="ppc64le"
        fi
    else
        echo "This cpu is not supported by risu. Try -h. " >&2
        exit 1
    fi
}

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 "AS:=${AS}" >> $m
    echo "OBJCOPY:=${OBJCOPY}" >> $m
    echo "OBJDUMP:=${OBJDUMP}" >> $m
    echo "STATIC:=${STATIC}" >> $m
    echo "SRCDIR:=${SRCDIR}" >> $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]

  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}"
OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"

if test "x${ARCH}" = "x"; then
    guess_arch
fi

generate_makefilein

# Are we in a separate build tree? If so, link the Makefile
# so that 'make' works.
if test ! -e Makefile; then
    echo "linking Makefile..."
    ln -s "${SRCDIR}/Makefile" .
fi

echo "type 'make' to start the build"
exit 0