Skip to content

Commit b9d8121

Browse files
committed
Added user-friendly compilation script
The script compiles OpenXcom on any distro. It is up to the user to ensure the dependencies are in place. To automatically clone/update git and compile: ./scripts/build-openxcom
1 parent 70aace3 commit b9d8121

1 file changed

Lines changed: 158 additions & 0 deletions

File tree

‎scripts/build-openxcom‎

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env bash
2+
# By Morgan Hardwood
3+
# Version 2018-12-04
4+
# This script gets the latest source code for the given program and compiles it.
5+
6+
# The name of the program, used for the folder names:
7+
prog="openxcom"
8+
9+
# The name of the compiled executable:
10+
exe="${prog}"
11+
12+
# The name of the sub-folder, if any, relative to the folder into which the
13+
# compiled executable is placed.
14+
# e.g. If the executable ends up in:
15+
# ~/programs/someProgram/foo/bar/someExecutable
16+
# then set it to:
17+
# exeRelativePath="foo/bar"
18+
# or if the executable ends up in
19+
# ~/programs/someProgram/someExecutable
20+
# then leave it empty:
21+
# exeRelativePath=""
22+
exeRelativePath=""
23+
24+
# The path to the repository:
25+
repo="https://github.com/SupSuper/OpenXcom.git"
26+
27+
# No touching below this line, with the exception of the "Compile" section
28+
# -----------------------------------------------------------------------------
29+
30+
# The name of the project's standard branch, typically "master":
31+
master="master"
32+
33+
buildOnly="false"
34+
buildType="release"
35+
36+
# Removes the trailing forward-slash if one is present
37+
exeRelativePath="${exeRelativePath/%\/}"
38+
# Append forward-slash to exeRelativePath only if it is not empty.
39+
exePath="${exeRelativePath:+${exeRelativePath}/}${exe}"
40+
41+
# Command-line arguments
42+
OPTIND=1
43+
while getopts "bdh?-" opt; do
44+
case "${opt}" in
45+
b) buildOnly="true"
46+
;;
47+
d) buildType="debug"
48+
;;
49+
h|\?|-) printf '%s\n' "This script gets the latest source code for ${prog} and compiles it." \
50+
"" \
51+
" -b" \
52+
" 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." \
53+
" -d" \
54+
" Optional. Compile a \"debug\" build. If not specified, a \"release\" build will be made." \
55+
""
56+
exit 0
57+
;;
58+
esac
59+
done
60+
shift $((OPTIND-1))
61+
[ "$1" = "--" ] && shift
62+
63+
printf '%s\n' "" "Program name: ${prog}" "Build type: ${buildType}" "Build without updating: ${buildOnly}" ""
64+
65+
# Clone if needed
66+
cloned="false"
67+
updates="false"
68+
if [[ ! -d "$HOME/programs/code-${prog}" ]]; then
69+
mkdir -p "$HOME/programs" || exit 1
70+
git clone "$repo" "$HOME/programs/code-${prog}" || exit 1
71+
pushd "$HOME/programs/code-${prog}" 1>/dev/null || exit 1
72+
cloned="true"
73+
else
74+
pushd "$HOME/programs/code-${prog}" 1>/dev/null || exit 1
75+
git fetch
76+
if [[ $(git rev-parse HEAD) != $(git rev-parse '@{u}') ]]; then
77+
updates="true"
78+
fi
79+
fi
80+
81+
# Pull updates if necessary
82+
if [[ "$updates" = "true" && "$buildOnly" = "false" ]]; then
83+
git pull || exit 1
84+
fi
85+
86+
# Find out which branch git is on
87+
branch="$(git rev-parse --abbrev-ref HEAD)"
88+
89+
# Set build and install folder names
90+
if [[ $branch = $master && $buildType = release ]]; then
91+
buildDir="$HOME/programs/code-${prog}/build"
92+
installDir="$HOME/programs/${prog}"
93+
else
94+
buildDir="$HOME/programs/code-${prog}/build-${branch}-${buildType}"
95+
installDir="$HOME/programs/${prog}-${branch}-${buildType}"
96+
fi
97+
98+
existsExe="false"
99+
if [[ -e "${installDir}/${exePath}" ]]; then
100+
existsExe="true"
101+
fi
102+
103+
# Quit if no updates and build-only flag not set
104+
if [[ "$cloned" = "false" && "$buildOnly" = "false" && "$updates" = "false" && "$existsExe" = "true" ]]; then
105+
printf '%s\n' "No updates, nothing to do."
106+
exit 0
107+
fi
108+
109+
# Determine CPU count
110+
cpuCount="fail"
111+
if command -v nproc >/dev/null 2>&1; then
112+
cpuCount="$(nproc --all)"
113+
fi
114+
if [[ ! ( $cpuCount -ge 1 && $cpuCount -le 64 ) ]]; then
115+
cpuCount=1
116+
fi
117+
118+
# Prepare folders
119+
rm -rf "${installDir}"
120+
mkdir -p "${buildDir}" "${installDir}" || exit 1
121+
cd "${buildDir}" || exit 1
122+
123+
# -----------------------------------------------------------------------------
124+
# Compile
125+
126+
# See:
127+
# http://rawpedia.rawtherapee.com/Linux#Compile_RawTherapee
128+
129+
cmake \
130+
-DCMAKE_CXX_FLAGS="-std=c++11 -Wno-deprecated-declarations -Wno-unused-result" \
131+
-DCMAKE_INSTALL_BINDIR:STRING="${installDir}" \
132+
-DCMAKE_INSTALL_PREFIX:STRING="${installDir}" \
133+
-DCMAKE_BUILD_TYPE="$buildType" \
134+
-DCMAKE_C_FLAGS="-O2 -pipe" \
135+
-DCMAKE_CXX_FLAGS="${CMAKE_C_FLAGS}" \
136+
"$HOME/programs/code-${prog}" || exit 1
137+
138+
make --jobs="$cpuCount" install || exit 1
139+
make install || exit 1
140+
141+
# Finished
142+
143+
printf '%s\n' "" \
144+
"OpenXcom requires resources from the original UFO: Enemy Unknown or Terror from the Deep." \
145+
"" \
146+
"Installation:" \
147+
" 1. Copy the following folders from the original, unpatched games" \
148+
" UFO: Enemy Unknown or Terror from the Deep" \
149+
" to ~/.local/share/openxcom/UFO/" \
150+
" GEODATA, GEOGRAPH, MAPS, ROUTES, SOUND, TERRAIN, UFOGRAPH, UFOINTRO and UNITS" \
151+
" (folders are case-sensitive)" \
152+
"" \
153+
" 2. Overwrite those folders with the ones from the 'OpenXcom UFO Patch':" \
154+
" https://openxcom.org/downloads-extras/"
155+
156+
printf '%s\n' "" "To run ${prog} type:" "${installDir}/${exePath}" ""
157+
158+
popd 1>/dev/null

0 commit comments

Comments
 (0)