install.sh 5.27 KB
Newer Older
Ciro Santilli's avatar
Ciro Santilli committed
1
2
3
#!/usr/bin/env bash

# Build and install to a local prefix under this repository.
4
export OSTYPE
Ciro Santilli's avatar
Ciro Santilli committed
5
6
7
8

# Flags:

  # -g: install globally instead for all users
9
  # -s: link everything statically, no D-Bus communication. More likely to work!
Alexandre Lision's avatar
Alexandre Lision committed
10
  # -c: client to build
Alexandre Lision's avatar
Alexandre Lision committed
11
  # -p: number of processors to use
12
  # -u: disable use of privileges (sudo) during install
Ciro Santilli's avatar
Ciro Santilli committed
13
14
15

set -ex

16
17
18
# Qt_MIN_VER required for client-qt
QT5_MIN_VER="5.14"

19
debug=
Ciro Santilli's avatar
Ciro Santilli committed
20
global=false
21
static=''
Alexandre Lision's avatar
Alexandre Lision committed
22
client=''
Andreas Traczyk's avatar
Andreas Traczyk committed
23
24
qt5ver=''
qt5path=''
25
proc='1'
26
priv_install=true
27
while getopts gsc:dq:Q:P:p:u OPT; do
Ciro Santilli's avatar
Ciro Santilli committed
28
29
30
31
  case "$OPT" in
    g)
      global='true'
    ;;
32
33
34
    s)
      static='-DENABLE_STATIC=true'
    ;;
Alexandre Lision's avatar
Alexandre Lision committed
35
36
37
    c)
      client="${OPTARG}"
    ;;
38
39
40
    d)
      debug=true
    ;;
Andreas Traczyk's avatar
Andreas Traczyk committed
41
42
43
44
45
46
    q)
      qt5ver="${OPTARG}"
    ;;
    Q)
      qt5path="${OPTARG}"
    ;;
47
48
49
    P)
      prefix="${OPTARG}"
    ;;
Alexandre Lision's avatar
Alexandre Lision committed
50
51
52
    p)
      proc="${OPTARG}"
    ;;
53
54
55
    u)
      priv_install='false'
    ;;
Ciro Santilli's avatar
Ciro Santilli committed
56
57
58
59
60
61
    \?)
      exit 1
    ;;
  esac
done

62
63
# $1: global-install?
# $2: private-install?
Ciro Santilli's avatar
Ciro Santilli committed
64
make_install() {
65
  if [ "$1" = "true" ] && [ "$2" != "false" ]; then
Ciro Santilli's avatar
Ciro Santilli committed
66
    sudo make install
Ciro Santilli's avatar
Ciro Santilli committed
67
68
69
    # Or else the next non-sudo install will fail, because this generates some
    # root owned files like install_manifest.txt under the build directory.
    sudo chown -R "$USER" .
Ciro Santilli's avatar
Ciro Santilli committed
70
71
72
73
74
75
76
77
  else
    make install
  fi
}

TOP="$(pwd)"
INSTALL="${TOP}/install"

78
if [ "${global}" = "true" ]; then
aviau's avatar
aviau committed
79
80
81
82
83
    BUILDDIR="build-global"
else
    BUILDDIR="build-local"
fi

Andreas Traczyk's avatar
Andreas Traczyk committed
84
# dring
85
86
87
88
89
90
91
92
93
94
95
96
DAEMON=${TOP}/daemon
cd "$DAEMON"

# Build the contribs.
mkdir -p contrib/native
(
    cd contrib/native
    ../bootstrap ${prefix:+"--prefix=$prefix"} ${debug:+"--enable-debug"}
    make -j"${proc}"
)

# Build the daemon itself.
97
test -f configure || ./autogen.sh
98
99

if [[ "$OSTYPE" != "darwin"* ]]; then
100
    # Keep the shared libaries on MAC OSX.
101
102
103
    sharedLib="--disable-shared"
fi

104
if [ "${global}" = "true" ]; then
105
106
107
108
109
  if [ "${prefix+set}" ]; then
    ./configure $sharedLib $CONFIGURE_FLAGS --prefix="${prefix}"
  else
    ./configure $sharedLib $CONFIGURE_FLAGS
  fi
Ciro Santilli's avatar
Ciro Santilli committed
110
else
111
  ./configure $sharedLib $CONFIGURE_FLAGS --prefix="${INSTALL}/daemon"
Ciro Santilli's avatar
Ciro Santilli committed
112
fi
113
make -j"${proc}"
114
make_install "${global}" "${priv_install}"
Ciro Santilli's avatar
Ciro Santilli committed
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
# For the client-qt, verify system's version if no path provided
if [ "${client}" = "client-qt" ] && [ -z "$qt5path" ]; then
    sys_qt5ver=""
    if command -v qmake &> /dev/null; then
        sys_qt5ver=$(qmake -v)
    elif command -v qmake-qt5 &> /dev/null; then
        sys_qt5ver=$(qmake-qt5 -v)   # Fedora
    else
        echo "No valid Qt found"; exit 1;
    fi

    sys_qt5ver=${sys_qt5ver#*Qt version}
    sys_qt5ver=${sys_qt5ver%\ in\ *}

    installed_qt5ver=$(echo $sys_qt5ver| cut -d'.' -f 2)
    required_qt5ver=$(echo $QT5_MIN_VER| cut -d'.' -f 2)

    if [[ $installed_qt5ver -ge $required_qt5ver ]] ; then
        # Disable qt5path and qt5ver in order to use system's Qt
        qt5path=""
        qt5ver=""
    else
        echo "No valid Qt found"; exit 1;
    fi
fi

Andreas Traczyk's avatar
Andreas Traczyk committed
142
# libringclient
Ciro Santilli's avatar
Ciro Santilli committed
143
cd "${TOP}/lrc"
144
145
146
mkdir -p "${BUILDDIR}"
cd "${BUILDDIR}"
if [ "${global}" = "true" ]; then
147
  if [ "${prefix+set}" ]; then
Andreas Traczyk's avatar
Andreas Traczyk committed
148
149
150
    cmake .. -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
             -DCMAKE_BUILD_TYPE=Debug \
             -DCMAKE_INSTALL_PREFIX="${prefix}" $static \
151
             -DQT5_VER="${qt5ver}" \
Andreas Traczyk's avatar
Andreas Traczyk committed
152
             -DQT5_PATH="${qt5path}"
153
  else
Andreas Traczyk's avatar
Andreas Traczyk committed
154
155
    cmake .. -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
             -DCMAKE_BUILD_TYPE=Debug $static \
156
             -DQT5_VER="${qt5ver}" \
Andreas Traczyk's avatar
Andreas Traczyk committed
157
             -DQT5_PATH="${qt5path}"
158
  fi
Ciro Santilli's avatar
Ciro Santilli committed
159
else
160
  cmake ..  -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
161
162
            -DCMAKE_BUILD_TYPE=Debug \
            -DCMAKE_INSTALL_PREFIX="${INSTALL}/lrc" \
Andreas Traczyk's avatar
Andreas Traczyk committed
163
            -DRING_BUILD_DIR="${DAEMON}/src" $static \
164
            -DQT5_VER="${qt5ver}" \
Andreas Traczyk's avatar
Andreas Traczyk committed
165
            -DQT5_PATH="${qt5path}"
Ciro Santilli's avatar
Ciro Santilli committed
166
fi
167
make -j"${proc}"
168
make_install "${global}"  "${priv_install}"
Ciro Santilli's avatar
Ciro Santilli committed
169

Andreas Traczyk's avatar
Andreas Traczyk committed
170
# client
Alexandre Lision's avatar
Alexandre Lision committed
171
cd "${TOP}/${client}"
172
173
mkdir -p "${BUILDDIR}"
cd "${BUILDDIR}"
Andreas Traczyk's avatar
Andreas Traczyk committed
174
if [ "${client}" = "client-qt" ]; then
175
176
177
178
179
180
    if [ "${global}" = "true" ]; then
        if [ "${prefix+set}" ]; then
            cmake .. -DQT5_VER="${qt5ver}" \
                     -DQT5_PATH="${qt5path}" \
                     -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
                     -DCMAKE_INSTALL_PREFIX="${prefix}" $static
181
        else
182
183
184
            cmake .. -DQT5_VER="${qt5ver}" \
                     -DQT5_PATH="${qt5path}" \
                     -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" $static
185
        fi
Andreas Traczyk's avatar
Andreas Traczyk committed
186
    else
187
188
189
190
191
        cmake ..  -DQT5_VER="${qt5ver}" \
                  -DQT5_PATH="${qt5path}" \
                  -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
                  -DCMAKE_INSTALL_PREFIX="${INSTALL}/${client}" \
                  -DLRC="${INSTALL}/lrc"
192
    fi
Ciro Santilli's avatar
Ciro Santilli committed
193
else
Andreas Traczyk's avatar
Andreas Traczyk committed
194
    if [ "${global}" = "true" ]; then
195
196
197
198
199
200
        if [ "${prefix+set}" ]; then
            cmake .. -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
                     -DCMAKE_INSTALL_PREFIX="${prefix}" $static
        else
            cmake .. -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" $static
        fi
Andreas Traczyk's avatar
Andreas Traczyk committed
201
    else
202
203
204
205
        cmake ..  -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
                  -DCMAKE_INSTALL_PREFIX="${INSTALL}/${client}" \
                  -DRINGTONE_DIR="${INSTALL}/daemon/share/ring/ringtones" \
                  -DLibRingClient_DIR="${INSTALL}/lrc/lib/cmake/LibRingClient" $static
Andreas Traczyk's avatar
Andreas Traczyk committed
206
    fi
Ciro Santilli's avatar
Ciro Santilli committed
207
fi
208
make -j"${proc}"
209
make_install "${global}" "${priv_install}"