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
#!/bin/bash

set -euo pipefail

# --------------------------------------------------------------------------

function require-pkgs() {
    # compute which packages must be newly installed
    # if we simply install existing packages, they might be
    # erroneously removed later
    dpkg-query -f '${db:Status-Abbrev} ${Package}\n' -W \
        | awk '/^ii/ {print $2}' \
        > /tmp/pkgs1

    for pkg in "$@"; 
        do echo ${pkg} >> /tmp/pkgs2; 
    done

    pkgs=$(sort /tmp/pkgs2 | uniq | sort - /tmp/pkgs1 /tmp/pkgs1 | uniq -u | tr '\n' ' '    )

    echo "installing additional build packages: ${pkgs}"
    apt-get -qq -o=Dpkg::Use-Pty=0 --no-install-recommends install ${pkgs}
}

# --------------------------------------------------------------------------

function fetch-src() {
    curl -qL "$1" | tar xz --strip-components 1
}

# --------------------------------------------------------------------------

configure_args=""

function conf_args() {
    configure_args+=" $@"
}

# --------------------------------------------------------------------------

function cmake-default() {
    cmake -B build -S . $@ ${configure_args} 
    cmake --build build
    cmake --install build
}

# --------------------------------------------------------------------------

# build basename
what=$(basename $1 .sh)
echo "---- begin $what ----"

# call build script
_build_dir="/build/${what}"

mkdir -p ${_build_dir}
pushd ${_build_dir} > /dev/null
source $1
popd > /dev/null

# remove build dir and build script
echo "cleaning up build dir"
rm -rf ${_build_dir} $1

echo "collecting shared library dependencies for /usr/local"

update-dlocatedb

(
set +o pipefail

find /usr/local -type f \( -name "*.so" -o -executable \) \
    | file -F" " -f-    \
    | awk '/ELF/ { print $1 }' \
    | xargs ldd \
    | grep -v "not found" \
    | awk '/^\t(.*)=>(.*)/ { print $3 }' \
    | grep -v "^\/usr\/local" \
    | sort | uniq \
    | xargs dlocate -p \
    | sort | uniq \
    > /usr/local/.pkgs
)

echo "---- end $what ----"