summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b87088475a9d57d640a48ea52c3c0012a0ffb5e2 (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
# Maintainer: 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=0
_pkgver=latest
pkgver=21+r24821_20200828_7f72ddf
pkgrel=2
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=('i686' 'x86_64')
license=('GPL2')
depends=(
  'boost-libs'
  'gettext'
  'glew'
  'hicolor-icon-theme'
  'libpng'
  'sdl2_image'
  'sdl2_mixer'
  'sdl2_ttf'
  'zlib'
)
makedepends=(
  'boost'
  'cmake'     # For configuring the build
  'coreutils' # For `nproc`
  'doxygen'   # For documentation (?)
  'git'       # For getting the source
  'graphviz'  # For documentation (?)
  'python'
)
optdepends=()
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+git://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() {
    grep -Ei 'build[[:space:]]+[0-9]+' "ChangeLog" | head -n 1 | sed -E 's|^.*[Bb]uild[[:space:]]+([0-9]+).*$|\1|'
  }
  _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}+r${_rev}_${_date}_${_hash}"
}


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` ...'
  # YES, -DCMAKE_INSTALL_PREFIX="/usr/bin" is corrent (nothing ${pkgdir}-related!!).
  # 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/bin" \
    -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_STATIC_LINKER_FLAGS="" \
    -DGETTEXT_MSGFMT_EXECUTABLE=/usr/bin/msgfmt \
    -DGETTEXT_MSGMERGE_EXECUTABLE=/usr/bib/msgmerge \
    -DICU_CONFIG_EXECUTABLE=/usr/bin/icu-config \
    -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_DATADIR=/usr/share/widelands \
    ..

  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}"
  for _docfile in CREDITS ChangeLog; do
    install -D -v -m644 "${_docfile}" "${pkgdir}/usr/share/doc/${_pkgname}/${_docfile}"
  done
  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
}