summaryrefslogtreecommitdiff
path: root/configure
blob: 98ba38d8204b687f36535241603832d3f637ad5c (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh

VERSION=$(cat .version)
DATE=$(date +%Y%m%d)

PREFIX_DEFAULT=/usr/local

BINDIR_set=
LIBDIR_set=
DOCDIR_set=
MANDIR_set=
LOCAL_set=

get_optval(){
    local ret
    case "$1" in
        --*=?*)
            echo "${1}" |cut -d '=' -f 2-
            ret=0
            ;;
        *)
            echo "${2}"
            ret=1
            ;;
    esac
    return ${ret}
}

set_prefix() {
    PREFIX=$(get_optval "$1" "$2")
    return $?
}

set_bindir() {
    BINDIR_set=1
    BINDIR=$(get_optval "$1" "$2")
    return $?
}

set_libdir() {
    LIBDIR_set=1
    LIBDIR=$(get_optval "$1" "$2")
    return $?
}

set_docdir() {
    DOCDIR_set=1
    DOCDIR=$(get_optval "$1" "$2")
    return $?
}

set_mandir() {
    MANDIR_set=1
    MANDIR=$(get_optval "$1" "$2")
    return $?
}

do_help() {
    cat <<__EOF__
\`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.

USAGE: ./configure [OPTION]...

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit                                                                                                                  
  --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
  --local                 don't install, and use current directory

By default, \`make install' will install all the files in
\`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
for instance \`--prefix=\${HOME}'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR           user executables [PREFIX/bin]
  --libdir=DIR           object code libraries [PREFIX/lib]
  --docdir=DIR           info documentation [PREFIX/share/doc]
  --mandir=DIR           man documentation [PREFIX/share/man]
__EOF__
}

do_error() {
    echo "[ERROR] ${@}"
    exit 1
}

#---------------------------------------------------------------------
# Set user's options

while [ $# -ne 0 ]; do
    case "$1" in
        --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
        --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
        --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
        --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
        --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
        --local)    LOCAL_set=1; shift;;
        --help|-h)  do_help; exit 0;;
        *)          do_help; exit 1;;
    esac
done

[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
if [ "${LOCAL_set}" = "1" ]; then
    set_prefix "" $(pwd)
    set_bindir "" $(pwd)
    set_libdir "" $(pwd)
    set_docdir "" $(pwd)/docs
    set_mandir "" $(pwd)/docs
fi

[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"

#---------------------------------------------------------------------
# Some sanity checks, now

# If this version is a svn snapshot, try to get the revision number
# If we can't get the revision number, use date
case "${VERSION}" in
  *+svn)
    REVISION=$(svnversion)
    case "${REVISION}" in
      exported)
        VERSION="${VERSION}:unknown@$(date +%Y%m%d.%H%M%S)";;
      *)
        URL=$(LANG=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
        ROOT=$(LANG=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
        VERSION="${VERSION}:${URL#${ROOT}}@${REVISION}"
        ;;
    esac
    ;;
esac

# Check bash is present, and at least version 3.0
[ -x /bin/bash ] || do_error "bash 3.0 or above was not found in /bin/bash"
bash_version=$(/bin/bash -c 'echo ${BASH_VERSION}')
bash_major=$(/bin/bash -c 'echo ${BASH_VERSINFO[0]}')
[ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed (/bin/bash is ${bash_version})"

sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
       -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
       -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
       -e "s,@@MANDIR@@,${MANDIR},g;"   \
       -e "s,@@VERSION@@,${VERSION},g;" \
       -e "s,@@DATE@@,${DATE},g;"       \
       -e "s,@@LOCAL@@,${LOCAL_set},g;" \
       Makefile.in >Makefile

cat <<__EOF__
crosstool-NG configured as follows:
  PREFIX="${PREFIX}"
  BINDIR="${BINDIR}"
  LIBDIR="${LIBDIR}"
  DOCDIR="${DOCDIR}"
  MANDIR="${MANDIR}"
__EOF__