summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: d866bf0fc0935ec6b184dcf1edb90517d32ac66e (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Maintainer: matthiakl <t-m · 42 _strange_curved_character_ mailpost · spdns · org>
# Contributor: dreieck
# Contributor: Gabriel Margiani (gamag) <gabriel _strange_curved_character_ margiani · ch>
# Contributor: matthiaskrgr <matthias · krueger _strange_curved_character_ famsike · de>

_pkgname=widelands
pkgname="${_pkgname}-git"
epoch=1
_pkgver=latest
pkgver=1.2+git26407_6f1730c_20231222
pkgrel=1
pkgdesc="An elaborate realtime multiplayer strategy game with emphasis on economy and transport - development version. In the spirit of BlueByte's 'Siedler II/ Settlers 2'."
url="http://widelands.org/"
arch=(
  'aarch64'
  'i686'
  'x86_64'
)
license=('GPL2')
depends=(
  'asio'
  'gettext'
  'glew'
  'hicolor-icon-theme'
  'libpng'
  'sdl2_image'
  'sdl2_mixer'
  'sdl2_ttf'
  'zlib'
)
makedepends=(
  'cmake'     # For configuring the build
  'coreutils' # For `nproc`
  'git'       # For getting the source
  'python'    # For revision detection
)
optdepends=(
  'minizip: use system minizip instead of embedded one'
  'widelands-maps-rttr: To play the maps from the game "Return to the Roots" in Widelands.'
  'widelands-maps-siedler2: To play the maps from the game "Settlers II" in Widelands.'
)
provides=(
  "${_pkgname}=${pkgver}"
)
conflicts=(
  "${_pkgname}"
  "${_pkgname}-bzr"
  "${_pkgname}-data"
)
replaces=(
  "${_pkgname}-bzr<=${pkgver}" # Previously, the development code was hosted a another location in a bazaar repository.
)
source=(
  "${_pkgname}::git+https://github.com/${_pkgname}/${_pkgname}.git"
)
sha256sums=(
  'SKIP'
)
options=('!strip') # Stripping seems not to reduce the size, but takes a long time.


# The following variable controls if `ccache` should be used for the build -- it switches some variables, also in build().
_ccache=false # true|false

# Check `$USE_CCACHE` environment variable if we should use `ccache`
case "${USE_CCACHE}" in
  [yY]|[yY][eE][sS]|[tR][rR][uU][eE]|[oO][nN])
    _ccache=true
  ;;
esac

if "${_ccache}"; then
  makedepends+=('ccache')
  options+=('ccache')
fi

# Temporary file in "${srcdir}" the git log should be written to -- it will become part of the installed documentation.
_gitlog="_widelands.git.log"

### The following is deactivated, since the corresponding section in package() is commented out.
# # Keep the following translations, remove all other.
# _keep_translations=('en_US' 'en_GB' 'de')


pkgver() {
  cd "${srcdir}/${_pkgname}"

  _get_build_ver() {
    cat NEXT_STABLE_VERSION
  }
  _get_git_commit_count() {
    git rev-list --count HEAD
  }
  _get_git_latest_commit_date() {
    git log -n 1 --format=tformat:%ci | awk '{print $1}' | tr -d '-'
  }
  _get_git_hash() {
    git rev-parse --short=7 HEAD
  }

  _ver="$(_get_build_ver)"
  _rev="$(_get_git_commit_count)"
  _date="$(_get_git_latest_commit_date)"
  _hash="$(_get_git_hash)"

  if [ -z ${_ver} ]; then
    error "Failed to determine build version. Aborting."
    return 11
  fi
  if [ -z ${_rev} ]; then
    error "Failed to determine commit count. Aborting."
    return 12
  fi
  if [ -z ${_date} ]; then
    error "Failed to determine latest commit date. Aborting."
    return 13
  fi
  if [ -z ${_hash} ]; then
    error "Failed to determine git hash. Aborting."
    return 14
  fi

  printf "%s" "${_ver}+git${_rev}_${_hash}_${_date}"
}


prepare() {
  cd "${srcdir}/${_pkgname}"

  msg2 "Creating git log: Executing 'git log' ..."
  git log > "${srcdir}/${_gitlog}"

  msg2 "Creating directories 'build' and 'build/locale' ..."
  test -d build/locale || mkdir -p build/locale
  msg2 "Symlinking 'build/locale/' to the main source base directory ..."
  test -e locale || ln -s build/locale .
}


build() {
  cd "${srcdir}/${_pkgname}/build"

  # If we want to compile with ccache, modify $CC/ $CXX accordingly:
  if "${_ccache}"; then
    msg2 'Build with `ccache` requested. Setting `$CC` and `$CXX` environment variables accordingly ...'
    # If $CC/ $CXX is empty, set a default compiler:
    if [ -z $CC ]; then
      CC=gcc
    fi
    if [ -z $CXX ]; then
      CXX=g++
    fi
    # Only append 'ccache' if it is not already part of $CC/ $CXX:
    if ! grep -wq ccache <(printf '%s' "${CC}"); then
      CC="ccache ${CC}"
    fi
    if ! grep -wq ccache <(printf '%s' "${CXX}"); then
      CXX="ccache ${CXX}"
    fi
    export CC
    export CXX
  fi

  msg2 'Running `cmake` ...'
  # If this failes on an existing build because of an mismatch of src and build cmake files, just delete build and try again.
  cmake \
    -DBUILD_TESTING=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_FLAGS="" \
    -DCMAKE_CXX_FLAGS_RELEASE="${CXXFLAGS} -DNDEBUG" \
    -DCMAKE_C_FLAGS="" \
    -DCMAKE_C_FLAGS_RELEASE="${CFLAGS} -DNDEBUG" \
    -DCMAKE_EXE_LINKER_FLAGS="" \
    -DCMAKE_EXE_LINKER_FLAGS_RELEASE="${LDFLAGS}" \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_STATIC_LINKER_FLAGS="" \
    -DGETTEXT_MSGFMT_EXECUTABLE=/usr/bin/msgfmt \
    -DGETTEXT_MSGMERGE_EXECUTABLE=/usr/bin/msgmerge \
    -DOPTION_ASAN=OFF \
    -DOPTION_BUILD_CODECHECK=OFF \
    -DOPTION_BUILD_TESTS=ON \
    -DOPTION_BUILD_TRANSLATIONS=ON \
    -DOPTION_BUILD_WEBSITE_TOOLS=ON \
    -DOPTION_GLEW_STATIC=OFF \
    -DOPTION_USE_GLBINDING=OFF \
    -DOpenGL_GL_PREFERENCE=LEGACY \
    -DUSE_XDG=OFF \
    -DWL_INSTALL_BASEDIR=/usr/share/doc/${_pkgname} \
    -DWL_INSTALL_DATADIR=/usr/share/widelands \
    -DWL_INSTALL_BINDIR=/usr/bin \
    ..

  msg2 'Running `make` ...'
  make -j "$(nproc)"
  # msg2 'Running `make lang` ...'
  # make lang ## Seems not to be needed; seems to be done already with the general `make`-call.
}


check() {
  cd "${srcdir}/${_pkgname}/build"
  msg2 'Running `make test` ...'
  make test
}


package() {
  cd  "${srcdir}/${_pkgname}/build"

  msg2 'Running `make install` ...'
  make DESTDIR="${pkgdir}" install

  msg2 'Installing additional documentation files ...'
  cd "${srcdir}/${_pkgname}"
  install -D -v -m644 "${srcdir}/${_gitlog}" "${pkgdir}/usr/share/doc/${_pkgname}/git-log.txt"

### When re-activating the following, also uncomment the line which sets ${_keep_translations[]}!
#   msg2 'Removing translations we do not want ...'
#   ls -1d "${pkgdir}/usr/share/widelands/locale"/* | grep -vE $(printf ' -e /%s$' "${_keep_translations[@]}") | while read _line; do
#     rm -R "${_line}"
#   done
}