2 # Copyright © 2007 - 2021 Steve Youngs All rights reserved.
3 # SPDX-License-Identifier: BSD-3-Clause
5 # What lies here is a collection of handy bash shell functions and
6 # aliases that make life a little easier for pkgusr.
12 Always build outside of the source tree if possible. Meson even
13 enforces this, CMake to a lesser degree does as well. This is a good
18 *** KEEP THE BUILD TREE ***
20 A big difference with Meson compared to other build systems is that you
21 should only ever have to run it once per package. You do not have to
22 re-run it every time there is a change in the source tree. To that
23 end, here is a reasonable template to use in the 'configure_commands()'
24 section of the build script...
26 # If you change the options after the build tree has already been
27 # set up and configured, run the build as: 'FORCE=1 ../build'
28 if [[ ! -d meson-info || \${FORCE} -eq 1 ]]; then
29 if [[ \${FORCE} -eq 1 ]]; then
30 _cmd=configure TREE=\${PWD}
31 echo '***' No logs on a FORCE run
32 echo See changes with: \'meson introspect --buildoptions -i\'
40 -Dbuildtype=release \\
43 any other options here \\
47 The Meson equivalent of configure --help
49 meson introspect --buildoptions -i
51 All "path" options (libdir, datadir, etc) are relative to prefix
52 unless the value begins with a '/' and then it is an absolute path.
54 Another nice thing about Meson is that when you set prefix to '/usr',
55 sysconfdir is automatically set to '/etc' and localstatedir to '/var'.
57 One headache that I have with Meson (and also CMake and Ninja) is
58 that file timestamps are very often not updated on install. I use
59 timestamps to help with upgrades (see: Upgrading below) and cleaning
60 out the old stuff that no longer exists in the current version of a
61 package. So here is a template for the 'install_commands()' section
62 of the build script...
65 # Meson builds tend not to update timestamps
66 meson introspect --installed -i |
67 awk '{print \$2}'|tr -d '",'|xargs touch -ch
71 *** KEEP THE BUILD TREE ***
73 Always use Ninja instead of old crusty unix makefiles. Here is a
74 reasonable template for 'configure_commands()'...
77 -DBUILD_SHARED_LIBS=ON \\
78 -DCMAKE_BUILD_TYPE=Release \\
79 -DCMAKE_INSTALL_PREFIX=/usr \\
80 -DCMAKE_INSTALL_LIBDIR=lib \\
81 -DCMAKE_INSTALL_LIBEXECDIR=lib \\
82 -DCMAKE_INSTALL_LOCALSTATEDIR=/var \\
83 -DCMAKE_INSTALL_RUNSTATEDIR=/run \\
84 -DCMAKE_INSTALL_SYSCONFDIR=/etc \\
86 any other options here \\
89 CMake equivalent of configure --help
91 cmake -LAH -G Ninja ../SRCTREE &>,,conf
93 Like Meson, CMake path options are relative to prefix unless the value
94 begins with a '/' and then it is absolute.
96 A nice thing about CMake is that it creates targets to edit and
97 rebuild the cache (think: reconfigure). 'ninja edit_cache' and
98 'ninja rebuld_cache', respectively.
100 Same headache as with Meson... timestamps not being updated on installs.
101 Here is the 'install_commands()' template for CMake builds...
104 # CMake builds tend not to update timestamps
105 if [ -f install_manifest.txt ]; then
106 echo>>install_manifest.txt # we need a final newline
109 done<install_manifest.txt
114 install_commands() template...
117 # Libtool .la files are NOT needed on a modern Linux system
118 find /usr/lib -name \\*.la -user \$(whoami) -delete
123 1) touch ~/timestampfile
124 2) build and install the package
125 3) forall_direntries_from \$(whoami) -not -newer ~/timestampfile
127 If step 3 turns up libraries that are dependencies of other packages
128 and the SO major version has changed move them to /usr/lib/deprecated
129 until everything that needs them has been updated/rebuilt. Remember to
134 BEFORE install root todo-items template:
135 (place at top of run_install() func)
137 echo '*** ROOT INTERVENTION REQUIRED ***'
139 As root in another term, run the following:
140 ----------------------------------------------------------
142 Put any commands you need to run as root before this
143 package is installed here. Watch your shell escapes
144 on backslashes, dollar signs, etc.
146 --------------------[RETURN when completed to continue]---
150 AFTER install root todo-items template:
151 (place at top of run_update() func)
153 echo '*** ROOT INTERVENTION REQUIRED ***'
155 As root in another term, run the following:
156 ----------------------------------------------------------
158 Put any commands you need to run as root after this
159 package is installed here. Watch your shell escapes
160 on backslashes, dollar signs, etc.
162 --------------------[RETURN when completed to continue]---
166 ### End of Build Tips
173 if [ -z "$arg" ]; then
177 (conf) less ${HOME}/configure.err ;;
178 (install) less ${HOME}/install.err ;;
179 (check) less ${HOME}/check.err ;;
180 (make) less ${HOME}/make.err ;;
181 (upd) less ${HOME}/upd.err ;;
182 (ver) less ${HOME}/verupd.err ;;
183 (all) less ${HOME}/*.err ;;
190 if [ -z "$arg" ]; then
194 (conf) less ${HOME}/configure.log ;;
195 (install) less ${HOME}/install.log ;;
196 (check) less ${HOME}/check.log ;;
197 (make) less ${HOME}/make.log ;;
198 (upd) less ${HOME}/upd.log ;;
199 (ver) less ${HOME}/verupd.log ;;
200 (all) less ${HOME}/*.log ;;
207 if [ -z "$arg" ]; then
211 (conf) less ${HOME}/configure.{err,log} ;;
212 (install) less ${HOME}/install.{err,log} ;;
213 (check) less ${HOME}/check.{err,log} ;;
214 (make) less ${HOME}/make.{err,log} ;;
215 (upd) less ${HOME}/upd.{err,log} ;;
216 (ver) less ${HOME}/verupd.{err,log} ;;
217 (all) less ${HOME}/*.{err,log} ;;
224 if [ -z "$arg" ]; then
227 grep --colour=always '^\*\*\*' ${HOME}/install.${arg}|less
233 if [ -z "$arg" ]; then
236 grep --colour=always '^\*\*\*' ${HOME}/check.${arg}|less
242 if [ -z "$arg" ]; then
245 grep --colour=always '^\*\*\*' ${HOME}/make.${arg}|less
250 for log in configure make check install upd verupd; do
251 [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
252 [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
259 sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
260 echo -n "Version updated... "
261 grep --colour Version:.*$ ${HOME}/.project
266 local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
267 local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
268 sed -n ${top},${bot}p ${HOME}/.project|less
273 local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
274 local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
275 sed -n ${top},${bot}p ${HOME}/.project|less
278 ## Check if there is a newer build script, maybe update.
279 # NOTE: Updating needs SXEmacs. It'll work in XEmacs and Emacs too,
280 # but you'll need to change build-update() accordingly.
283 if [ -x $(type -p sxemacs) ]; then
284 sxemacs -l /etc/pkgusr/bld-update.el
286 echo *** Sorry, you do not have SXEmacs installed.
287 echo *** Copying the new build script to ~/build-$(date +%Y%m%d)
288 cp -v /etc/pkgusr/skel-package/build \
289 ${HOME}/build-$(date +%Y%m%d)
295 local sysb=/etc/pkgusr/skel-package/build
296 local pkgb=${HOME}/build
297 local sysbv=$(${sysb} -V|awk '/build:/ {print $2;}')
298 local pkgbv=$(${pkgb} -V|awk '/build:/ {print $2;}')
300 if [[ ${sysbv} > ${pkgbv} ]]; then
301 echo '*****************************************'
303 echo '* B u i l d S c r i p t U p d a t e *'
304 echo '* A v a i l a b l e *'
306 echo '*****************************************'
307 echo ' Your version:' ${pkgbv}
308 echo ' Available Version:' ${sysbv}
310 echo 'For a SXEmacs based interactive update, run: "build-update"'
311 echo 'To turn this notice off, set $CHECKUPDATES to: "0"'
313 echo -n 'Press [RETURN] to continue...'
318 ## Convenience to allow existing pkgusrs to update their git
322 install -vdm755 ${HOME}/.config/git &&
323 ln -svf /etc/pkgusr/gitconfig ${HOME}/.config/git/config &&
324 # Nuke the old ~/.gitconfig
325 rm -v ${HOME}/.gitconfig 2>/dev/null || true
330 alias srepo='grep --colour Repo_Location:.*$ ${HOME}/.project'
331 alias rawrepo='srepo|cut -d" " -f2|tr -d "<>"'
332 alias trepo='grep --colour Repo_Type:.*$ ${HOME}/.project'
333 alias web='grep --colour Web_Site:.*$ ${HOME}/.project'
334 alias rawweb='web|tr -s " "|cut -d" " -f3|tr -d "<>"'
336 alias alogs='ls -l ${HOME}/*.{err,log}'
337 alias lerr='ls -l ${HOME}/*.err'
338 alias llog='ls -l ${HOME}/*.log'
340 ## As of 2021-01-18 nano (v5.5) seems FUBAR'd
341 alias ebld='vi ${HOME}/build'
342 alias epro='vi ${HOME}/.project'
343 alias ebp='vi -a ${HOME}/{build,.project}'
344 # alias ebld='nano -w ${HOME}/build'
345 # alias epro='nano -w ${HOME}/.project'
346 # alias ebp='nano -w ${HOME}/{build,.project}'
347 alias deps='grep --colour "Deps: " ${HOME}/.project'
348 alias listp='pinky -l $(whoami)|less'
349 alias patches='find ${SLACKPKG}/**/$(whoami)|grep -E "(diff|patch)"'
359 alogs List of build logs (showing size)
360 lerr List just the error logs
361 llog List just the .log logs
362 verr [LOG] Display LOG, which can be:
363 \`conf' -- configure.err
364 \`check' -- check.err
365 \`install' -- install.err
369 \`all' -- all error logs (default)
370 vlog [LOG] Same as for \`verr', but for the .log files.
371 verrlog [LOG] Same as for \`verr', but displays both the .err,
373 dlog Removes all build logs
374 instg {err|log} Greps install.err (default) or install.log for
375 pkgusr notifications ("*** some message")
376 chkg {err|log} Greps check.err (default) or check.log for
377 pkgusr notifications ("*** some message")
378 makeg {err|log} Greps make.err (default) or make.log for
379 pkgusr notifications ("*** some message")
381 Package Notes/Content:
383 ipkg Displays the \`Install Notes'.
384 gpkg Displays the \`General Notes'.
385 listp Displays the entire package info (piped through less(1))
386 srepo Display the package's source repo location.
387 rawrepo Output just the repo URL (to use with lynx, curl, etc)
388 trepo Display the type of repo (git, svn, mercurial, tla etc)
389 web Display the package's homepage URL.
390 rawweb Output just the web URL (to use with lynx etc)
391 deps Display the package's dependencies
395 xtar [TARBALL] Extract TARBALL
396 vtar [TARBALL] List the contents of TARBALL
400 ebld Edit the build script.
401 epro Edit the .project file.
402 ebp Edit the build script and the .project file.
403 updver [NEWVER] Updates the version in the .project. It MUST be
404 quoted to protect it from shell expansion.
406 Miscellaneous Bobs & Bits:
408 prep_git Sets up ~/.config/git/config
409 In the normal course of events you shouldn't need to
410 use this as it happens during login if it is needed.
411 patches Check for any Slackware patches. (see SLACKPKG var in
413 B-tips A few build tips. Includes templates for Meson and
414 CMake to use in the build script.