File: build-hdrmerge

package info (click to toggle)
hdrmerge 0.5%2Bgit20200117-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 33,872 kB
  • sloc: cpp: 5,026; sh: 175; makefile: 5
file content (142 lines) | stat: -rwxr-xr-x 4,262 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash
# By Morgan Hardwood
# Version 2018-03-04
# This script gets the latest source code for the given program and compiles it.

# The name of the program, used for the folder names:
prog="hdrmerge"

# The name of the compiled executable:
exe="${prog}"

# The name of the sub-folder, if any, relative to the folder into which the
# compiled executable is placed.
# e.g. If the executable ends up in:
#   ~/programs/someProgram/foo/bar/someExecutable
# then set it to:
#   exeRelativePath="foo/bar"
# or if the executable ends up in
#   ~/programs/someProgram/someExecutable
# then leave it empty:
# exeRelativePath=""
exeRelativePath=""

# The path to the repository:
repo="https://github.com/jcelaya/hdrmerge.git"

# No touching below this line, with the exception of the "Compile" section
# -----------------------------------------------------------------------------

# The name of the project's standard branch, typically "master":
master="master"

buildOnly="false"
buildType="release"

# Removes the trailing forward-slash if one is present
exeRelativePath="${exeRelativePath/%\/}"
# Append forward-slash to exeRelativePath only if it is not empty.
exePath="${exeRelativePath:+${exeRelativePath}/}${exe}"

# Command-line arguments
OPTIND=1
while getopts "bdh?-" opt; do
    case "${opt}" in
        b)  buildOnly="true"
            ;;
        d)  buildType="debug"
            ;;
        h|\?|-) printf '%s\n' "This script gets the latest source code for ${prog} and compiles it." \
                "" \
                "  -b" \
                "     Optional. If specified, the script only compiles the source, it does not try to update the source. If not specified, the source will be updated first." \
                "  -d" \
                "     Optional. Compile a \"debug\" build. If not specified, a \"release\" build will be made." \
                ""
        exit 0
        ;;
    esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift

printf '%s\n' "" "Program name: ${prog}" "Build type: ${buildType}" "Build without updating: ${buildOnly}" ""

# Clone if needed
cloned="false"
updates="false"
if [[ ! -d "$HOME/programs/code-${prog}" ]]; then
    mkdir -p "$HOME/programs" || exit 1
    git clone "$repo" "$HOME/programs/code-${prog}" || exit 1
    pushd "$HOME/programs/code-${prog}" 1>/dev/null || exit 1
    cloned="true"
else
    pushd "$HOME/programs/code-${prog}" 1>/dev/null || exit 1
    git fetch
    if [[ $(git rev-parse HEAD) != $(git rev-parse '@{u}') ]]; then
        updates="true"
    fi
fi

# Pull updates if necessary
if [[ "$updates" = "true" && "$buildOnly" = "false" ]]; then
    git pull || exit 1
fi

# Find out which branch git is on
branch="$(git rev-parse --abbrev-ref HEAD)"

# Set build and install folder names
if [[ $branch = $master && $buildType = release ]]; then
    buildDir="$HOME/programs/code-${prog}/build"
    installDir="$HOME/programs/${prog}"
else
    buildDir="$HOME/programs/code-${prog}/build-${branch}-${buildType}"
    installDir="$HOME/programs/${prog}-${branch}-${buildType}"
fi

existsExe="false"
if [[ -e "${installDir}/${exePath}" ]]; then
    existsExe="true"
fi

# Quit if no updates and build-only flag not set
if [[ "$cloned" = "false" && "$buildOnly" = "false" && "$updates" = "false" && "$existsExe" = "true" ]]; then
    printf '%s\n' "No updates, nothing to do."
    exit 0
fi

# Determine CPU count
cpuCount="fail"
if command -v nproc >/dev/null 2>&1; then
    cpuCount="$(nproc --all)"
fi
if [[ ! ( $cpuCount -ge 1 && $cpuCount -le 64 ) ]]; then
    cpuCount=1
fi

# Prepare folders
rm -rf "${installDir}"
mkdir -p "${buildDir}" "${installDir}" || exit 1
cd "${buildDir}" || exit 1

# -----------------------------------------------------------------------------
# Compile

export QT_SELECT="qt5"

cmake \
    -DCMAKE_CXX_FLAGS="-std=c++11 -Wno-deprecated-declarations -Wno-unused-result" \
    -DCMAKE_INSTALL_BINDIR:STRING="${installDir}" \
    -DCMAKE_BUILD_TYPE="$buildType"  \
    -DCMAKE_C_FLAGS="-O2 -pipe" \
    -DCMAKE_CXX_FLAGS="${CMAKE_C_FLAGS}" \
    "$HOME/programs/code-${prog}" || exit 1

make --jobs="$cpuCount" || exit 1
make install || exit 1

# Finished
printf '%s\n' "" "To run ${prog} type:" "${installDir}/${exePath}" ""

popd 1>/dev/null