summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/scripts/build.sh
blob: aad8370b0bd18c9d55a6b7c863c0e0b607b19f4d (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
#!/usr/bin/env bash
# shellcheck source=./rebash/core.sh
source "$(dirname "${BASH_SOURCE[0]}")/rebash/core.sh"
core.import logging

build_compile_qemu_xmount() {
    # Compiles qemu libxmount.
    # NOTE: expects xmount installation under
    # $1/../xmount/trunk/build/release_build/
    #
    # Provides the following file:
    # "$1/libxmount_input_qemu.so"
    pushd "$1"
    local xmount_installation="../xmount/trunk/build/release_build"
    [ ! -z "$2" ] && xmount_installation="$2"
    ./configure --enable-xmount-input --python="$(which python2)" \
        --extra-cflags="-fPIC" \
        --extra-cflags="-I${xmount_installation}/include" \
        --extra-cflags="-I${xmount_installation}/include/xmount" \
        --disable-fdt --target-list=""
    make libxmount_input_qemu.so
    local ret=$?
    popd
    return $ret
}
build_clean_qemu_xmount() {
    pushd "$1"
    make clean
    popd
    return $?
}
build_compile_xmount() {
    # Compiles xmount
    #
    # Provides the xmount installation under:
    # "$1/trunk/build/release_build/"
    pushd "$1"

    local destination_directory="./release_build"
    [ ! -z "$2" ] && destination_directory="$2"
    local install_prefix="/"
    [ ! -z "$3" ] && install_prefix="$3"

    mkdir --parents trunk/build
    cd trunk/build || return 1
    cmake -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX="$install_prefix" ..
    make
    make install DESTDIR="$destination_directory"
    local ret=$?
    popd
    return $ret
}
build_clean_xmount() {
    rm --recursive --force "$1/trunk/build"
}
build_clean_qemu_nbd() {
    pushd "$1"
    git clean --force -x || make clean
    popd
    return $?
}
build_compile_qemu_nbd() {
    # Downloads and compiles qemu-nbd.
    #
    # Examples:
    #
    # >>> build_compile_qemu_nbd path/to/nbd/directory/
    # ...
    # Provides the following file:
    # "$1/qemu-nbd"
    logging.info 'Compiling static qemu-nbd binary. This takes a while,' \
        'grab a cup of coffee...'
    # TODO check if need all, after disabling features
    # TODO check dependencies
    #su -s /bin/bash nobody
    #yaourt --noconfirm -S glib2-static glibc-static pcre-static
    #exit
    pushd "$(dirname "$1")"
    # TODO check what other features can be disabled
    # --static
    ./configure --target-list=x86_64-linux-user \
        --python="$(which python2)" --disable-docs --disable-gtk --disable-vnc \
        --disable-kvm --disable-libssh2 --enable-user --disable-system \
        --disable-fdt --disable-libnfs --disable-glusterfs --disable-libiscsi \
        --disable-gcrypt --disable-nettle
    make qemu-nbd
    local ret=$?
    popd
    return $ret
}
build_compile_nbd() {
    # Downloads and compiles nbd.
    #
    # Examples:
    #
    # >>> build_compile_nbd path/to/nbd/directory/
    # ...
    # Provides the following file:
    # "$1/nbd.ko"
    pushd "$1"
    logging.info 'Compile the nbd kernel module.'
    make
    popd
    return $?
}
build_clean_nbd() {
    # Cleans nbd specific generated files
    #
    # Examples:
    #
    # >>> build_clean_nbd path/to/nbd/directory/
    # ...
    # Removes the following file:
    # "$1/nbd.ko"
    pushd "$1"
    make clean
    popd
    return $?
}
build_compile_dnbd3() {
    # Downloads and compiles dnbd3.
    #
    # Examples:
    #
    # >>> build_compile_dnbd3 path/to/dnbd3/directory/
    # ...
    # Provides the following file:
    # "$1/build/dnbd3.ko"
    pushd "$1"
    # NOTE: The generic way would be: "./build.sh" but this tries to build
    # more than we really need and takes more time.
    mkdir --parents build
    pushd build
    cmake ../
    make dnbd3 dnbd3-client
    popd
    ##
    popd
    return $?
}
build_clean_dnbd3() {
    # Removes generated dnbd3 specific files.
    #
    # Examples:
    #
    # >>> build_clean_dnbd3 path/to/dnbd3/directory/
    # ...
    # Removes the following directory:
    # "$1/build"
    rm --recursive --force "$1/build"
    return $?
}
build_compile_systemd_preserve_process_marker() {
    # Compiles simple c program.
    #
    # Examples:
    #
    # >>> build_compile_systemd_preserve_process_marker path/to/program/folder
    pushd "$1"
    make
    popd
    return $?
}
build_clean_systemd_preserve_process_marker() {
    # Removes compiled simple c program.
    #
    # Examples:
    #
    # >>> build_clean_systemd_preserve_process_marker path/to/program/folder
    pushd "$1"
    make clean
    popd
    return $?
}