aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: dbbeaabdce40718822071659da901a69523c125e (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
#!/bin/bash

cont() {
    read c
    if [ "$c" != "yes" ] && [ "$c" != "Yes" ] && [ "$c" != "y" ] && [ "$c" != "Y" ]
    then
      exit 3
    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"
    echo "--   Using Ninja (ninja-build) might improve build experience."
    cmake_type="Unix Makefiles"
    exec_bin="$make_bin"
    exec_command="$exec_bin -j4"
  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
  if [ ! -f "build/.cmake_type" ]
  then
    printf "-!- ./build exists but was not created by ./configure script, continue? [y/N] "
    cont
  fi
  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" ..

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"
%:
	@sh -c "cd build; $exec_command \"\$@\""
EOF