aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: da82fd648c42ce832cfe2e9b8084f0393fb1bea3 (plain) (blame)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/sh

OPTS=`getopt -o "h" --long \
help,fetch-only,no-debug,disable-fast-vapi,with-tests,\
enable-plugin:,disable-plugin:,\
prefix:,program-prefix:,exec-prefix:,lib-suffix:,\
bindir:,libdir:,includedir:,datadir:,\
host:,build:,\
sbindir:,sysconfdir:,libexecdir:,localstatedir:,sharedstatedir:,mandir:,infodir:,\
enable-dependency-tracking,disable-dependency-tracking,\
disable-silent-rules,disable-maintainer-mode\
 -n './configure' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi

eval set -- "$OPTS"

PREFIX=${PREFIX:-/usr/local}
ENABLED_PLUGINS=
DISABLED_PLUGINS=
BUILD_TESTS=
DISABLE_FAST_VAPI=
LIB_SUFFIX=
NO_DEBUG=
FETCH_ONLY=

EXEC_PREFIX=
BINDIR=
SBINDIR=n
SYSCONFDIR=
DATADIR=
INCLUDEDIR=
LIBDIR=
LIBEXECDIR=
LOCALSTATEDIR=
SHAREDSTATEDIR=
MANDIR=
INFODIR=

help() {
    cat << EOF
Usage:
  ./configure [OPTION]...

Defaults for the options (based on current environment) are specified in
brackets.

Configuration:
  -h, --help                 Print this help and exit
  --fetch-only               Only fetch the files required to run ./configure
                             without network access later and exit
  --no-debug                 Build without debug symbols
  --disable-fast-vapi        Disable the usage of Vala compilers fast-vapi
                             feature. fast-vapi mode is slower when doing
                             clean builds, but faster when doing incremental
                             builds (during development).
  --with-tests               Also build tests.

Plugin configuration:
  --enable-plugin=PLUGIN     Enable compilation of plugin PLUGIN.
  --disable-plugin=PLUGIN    Disable compilation of plugin PLUGIN.

Installation directories:
  --prefix=PREFIX            Install architecture-independent files in PREFIX
                             [$PREFIX]
  --program-prefix=PREFIX    Same as --prefix
  --exec-prefix=             Install architecture-dependent files in EPREFIX
                             [PREFIX]
  --lib-suffix=SUFFIX        Append SUFFIX to the directory name for libraries

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

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR               user executables [EPREFIX/bin]
  --libdir=DIR               object code libraries [EPREFIX/lib]
  --includedir=DIR           C header files [PREFIX/include]
  --datadir=DIR              read-only data [PREFIX/share]

For compatibility with autotools, these options will be silently ignored:
--host, --build, --sbindir, --sysconfdir, --libexecdir, --sharedstatedir,
--localstatedir, --mandir, --infodir, --enable-dependency-tracking,
--disable-dependency-tracking

Some influential environment variables:
  CC                         C compiler command
  CFLAGS                     C compiler flags
  PKG_CONFIG_PATH            directories to add to pkg-config's search path
  PKG_CONFIG_LIBDIR          path overriding pkg-config's built-in search path
  USE_CCACHE                 decide to use ccache when compiling C objects
  VALAC                      Vala compiler command
  VALACFLAGS                 Vala compiler flags

Use these variables to override the choices made by \`configure' or to help
it to find libraries and programs with nonstandard names/locations.

EOF
}

while true; do
    case "$1" in
        --prefix ) PREFIX="$2"; shift; shift ;;
        --enable-plugin ) if [ -z "$ENABLED_PLUGINS" ]; then ENABLED_PLUGINS="$2"; else ENABLED_PLUGINS="$ENABLED_PLUGINS;$2"; fi; shift; shift ;;
        --disable-plugin ) if [ -z "$DISABLED_PLUGINS" ]; then DISABLED_PLUGINS="$2"; else DISABLED_PLUGINS="$DISABLED_PLUGINS;$2"; fi; shift; shift ;;
        --valac ) VALA_EXECUTABLE="$2"; shift; shift ;;
        --valac-flags ) VALAC_FLAGS="$2"; shift; shift ;;
        --lib-suffix ) LIB_SUFFIX="$2"; shift; shift ;;
        --disable-fast-vapi ) DISABLE_FAST_VAPI=yes; shift ;;
        --no-debug ) NO_DEBUG=yes; shift ;;
        --fetch-only ) FETCH_ONLY=yes; shift ;;
        --with-tests ) BUILD_TESTS=yes; shift ;;
        # Autotools paths
        --program-prefix ) PREFIX="$2"; shift; shift ;;
        --exec-prefix ) EXEC_PREFIX="$2"; shift; shift ;;
        --bindir ) BINDIR="$2"; shift; shift ;;
        --datadir ) DATADIR="$2"; shift; shift ;;
        --includedir ) INCLUDEDIR="$2"; shift; shift ;;
        --libdir ) LIBDIR="$2"; shift; shift ;;
        # Autotools paths not used
        --sbindir ) SBINDIR="$2"; shift; shift ;;
        --sysconfdir ) SYSCONFDIR="$2"; shift; shift ;;
        --libexecdir ) LIBEXECDIR="$2"; shift; shift ;;
        --localstatedir ) LOCALSTATEDIR="$2"; shift; shift ;;
        --sharedstatedir ) SHAREDSTATEDIR="$2"; shift; shift ;;
        --mandir ) MANDIR="$2"; shift; shift ;;
        --infodir ) INFODIR="$2"; shift; shift ;;
        # Ignore for autotools compat
        --host | --build ) shift; shift ;;
        --disable-dependency-tracking | --enable-dependency-tracking ) shift ;;
        # Ignore for debian compat
        --disable-silent-rules | --disable-maintainer-mode ) shift ;;
        -h | --help ) help; exit 0 ;;
        -- ) shift; break ;;
        * ) break ;;
    esac
done

if [ -d ".git" ]; then
    git submodule update --init 2>/dev/null
else
    tmp=0
    for i in $(cat .gitmodules | grep -n submodule | awk -F ':' '{print $1}') $(wc -l .gitmodules | awk '{print $1}'); do
        if ! [ $tmp -eq 0 ]; then
            name=$(cat .gitmodules | head -n $tmp | tail -n 1 | awk -F '"' '{print $2}')
            def=$(cat .gitmodules | head -n $i | tail -n $(expr "$i" - "$tmp") | awk -F ' ' '{print $1 $2 $3}')
            path=$(echo "$def" | grep '^path=' | awk -F '=' '{print $2}')
            url=$(echo "$def" | grep '^url=' | awk -F '=' '{print $2}')
            branch=$(echo "$def" | grep '^branch=' | awk -F '=' '{print $2}')

            if ! ls "$path"/* >/dev/null 2>/dev/null; then
                git=$(which git)
                if ! [ $? -eq 0 ] || ! [ -x $git ]; then
                    echo "Failed retrieving missing files"
                    exit 5
                fi
                res=$(git clone "$url" "$path" 2>&1)
                if ! [ $? -eq 0 ] || ! [ -d $path ]; then
                    echo "Failed retrieving missing files: $res"
                    exit 5
                fi
                if [ -n "$branch" ]; then
                    olddir="$(pwd)"
                    cd "$path"
                    res=$(git checkout "$branch" 2>&1)
                    if ! [ $? -eq 0 ]; then
                        echo "Failed retrieving missing files: $res"
                        exit 5
                    fi
                    cd "$olddir"
                fi
                echo "Submodule path '$path': checked out '$branch' (via git clone)"
            fi
        fi
        tmp=$i
    done
fi

if [ "$FETCH_ONLY" = "yes" ]; then exit 0; fi

if [ ! -x "$(which cmake 2>/dev/null)" ]
then
    echo "-!- CMake required."
    exit 1
fi

ninja_bin="$(which ninja-build 2>/dev/null)"
if ! [ -x "$ninja_bin" ]; then
    ninja_bin="$(which ninja 2>/dev/null)"
fi
if [ -x "$ninja_bin" ]; then
    ninja_version=$($ninja_bin --version 2>/dev/null)
    if [ $? -eq 0 ]; then
        echo "-- Found Ninja: $ninja_bin (found version \"$ninja_version\")"
        cmake_type="Ninja"
        exec_bin="$ninja_bin"
        exec_command="$exec_bin"
    elif [ "/usr/sbin/ninja" = "$ninja_bin" ]; then
        echo "-- Ninja at $ninja_bin is not usable. Did you install 'ninja' instead of 'ninja-build'?"
    fi
fi

if ! [ -x "$exec_bin" ]; then
    make_bin="$(which make 2>/dev/null)"
    if [ -x "$make_bin" ]; then
        echo "-- Found Make: $make_bin"
        cmake_type="Unix Makefiles"
        exec_bin="$make_bin"
        exec_command="$exec_bin"
        echo "--   Running with make. Using Ninja (ninja-build) might improve build experience."
    fi
fi

if ! [ -x "$exec_bin" ]; then
    echo "-!- No compatible build system (Ninja, Make) found."
    exit 4
fi


if [ -f ./build ]
then
    echo "-!- ./build file exists. ./configure can't continue"
    exit 2
fi

if [ -d build ]
then
    last_type=`cat build/.cmake_type`
    if [ "$cmake_type" != "$last_type" ]
    then
        echo "-- Using different build system, cleaning build system files"
        cd build
        rm -r CMakeCache.txt CMakeFiles
        cd ..
    fi
fi

mkdir -p build
cd build

echo "$cmake_type" > .cmake_type
cmake -G "$cmake_type" \
    -DCMAKE_INSTALL_PREFIX="$PREFIX" \
    -DENABLED_PLUGINS="$ENABLED_PLUGINS" \
    -DDISABLED_PLUGINS="$DISABLED_PLUGINS" \
    -DBUILD_TESTS="$BUILD_TESTS" \
    -DVALA_EXECUTABLE="$VALAC" \
    -DCMAKE_VALA_FLAGS="$VALACFLAGS" \
    -DDISABLE_FAST_VAPI="$DISABLE_FAST_VAPI" \
    -DLIB_SUFFIX="$LIB_SUFFIX" \
    -DNO_DEBUG="$NO_DEBUG" \
    -DEXEC_INSTALL_PREFIX="$EXEC_PREFIX" \
    -DSHARE_INSTALL_PREFIX="$DATADIR" \
    -DBIN_INSTALL_DIR="$BINDIR" \
    -DINCLUDE_INSTALL_DIR="$INCLUDEDIR" \
    -DLIB_INSTALL_DIR="$LIBDIR" \
    .. || exit 9

if [ "$cmake_type" = "Ninja" ]
then
cat << EOF > Makefile
default:
	@sh -c "$exec_command"
%:
	@sh -c "$exec_command \"\$@\""
EOF
fi

cd ..

cat << EOF > Makefile
default:
	@sh -c "cd build; $exec_command"
distclean: clean uninstall
	
test: default
	echo "make test not yet supported"
%:
	@sh -c "cd build; $exec_command \"\$@\""
EOF

echo "-- Configured. Type 'make' to build, 'make install' to install."