Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / solenv / bin / install-gdb-printers
blobaae4020a4532a54045acf0befc057c94de6f84e4
1 #!/usr/bin/env bash
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 GDBDIR="${SRCDIR}/solenv/gdb"
11 INSTALLDIR="${TESTINSTALLDIR}"
12 DYLIB=so
13 if [ "$(uname)" = Darwin ]; then
14 INSTALLDIR=$INSTALLDIR/LibreOffice.app/Contents
15 DYLIB=dylib
18 die() {
19 echo "$1" >&2
20 exit 1
23 usage() {
24 cat <<EOT
25 Install gdb pretty printers and autoloaders for them.
27 Usage:
28 install-gdb-printers [ -a dir ] [ -i dir ] [ -p dir ] [ -c ]
29 install-gdb-printers -h
31 Options:
32 -a dir The dir where autoloaders will be placed. Defaults to whatever -i
33 is.
34 -c Create the autoloader's dir if it does not exist. This option only
35 makes sense if both -a and -i are used.
36 -h Show this help text.
37 -i dir The dir where libreoffice is installed. Defaults to whatever -a is.
38 -p dir The dir where pretty printers are placed.
40 Env. variables:
41 DESTDIR If set, it is prepended to all dir arguments.
43 Examples:
44 1) Install pretty printers into /usr/share/libreoffice/gdb, with
45 autoloaders in /usr/share/gdb/auto-load (run
46 "info gdb 'Extending GDB' Python Auto-loading" to learn more) and
47 installation in /usr/lib64/libreoffice (this is what Fedora does):
49 install-gdb-printers -a /usr/share/gdb/auto-load/usr/lib64/libreoffice -c \\
50 -i /usr/lib64/libreoffice -p /usr/share/libreoffice/gdb
51 EOT
54 make_autoload() {
55 local lib="${DESTDIR}${autoloaddir}/$2/$3"
56 local merged="$4"
58 local resolved;
59 resolved=$(readlink "${DESTDIR}${installdir}/$2/$3")
60 [ -n "$resolved" ] && lib=$resolved
61 local dir="${lib%/*}"
63 if ${create}; then
64 mkdir -p "${dir}" || die "cannot create dir '${dir}'"
67 [[ -f ${lib}-gdb.py ]] && rm -f "${lib}-gdb.py"
68 if [[ -n "${merged}" ]]; then
69 sed -e "s!%PYTHONDIR%!${pythondir}!" -e "s!%MODULES%!${*:5}!" \
70 "${GDBDIR}/autoload.template" > "${lib}-gdb.py"
71 else
72 sed -e "s!%PYTHONDIR%!${pythondir}!" -e "s!%MODULES%!$1!" \
73 "${GDBDIR}/autoload.template" > "${lib}-gdb.py"
77 # dir where the autoloaders will be placed
78 autoloaddir=
79 # The installation dir. If only one of these is set, the other is set to
80 # the same value.
81 installdir=
82 # dir where the pretty printers will be placed
83 pythondir="${GDBDIR}"
84 # Create autoload dir if it does not exist. This only makes sense when
85 # installing into system gdb dir, so $autoloaddir must be absolute path.
86 create=false
88 # b de g jklmno qrstuvwxyzABCDEFGHIJK MNOPQRSTUVWXYZ0123456789
89 while getopts :a:cfhi:p:L opt; do
90 case ${opt} in
91 a) autoloaddir="${OPTARG}" ;;
92 c) create=true ;;
93 h) usage; exit ;;
94 i) installdir="${OPTARG}" ;;
95 p) pythondir="${OPTARG}" ;;
96 *) die "unknown option ${OPTARG}" ;;
97 esac
98 done
100 if [[ -z ${autoloaddir} && -z ${installdir} ]]; then
101 autoloaddir="${INSTALLDIR}"
102 installdir="${INSTALLDIR}"
103 elif [[ -n ${autoloaddir} && -z ${installdir} ]]; then
104 installdir="${autoloaddir}"
105 elif [[ -z ${autoloaddir} && -n ${installdir} ]]; then
106 autoloaddir="${installdir}"
109 if [[ -n ${DESTDIR} ]]; then
110 [[ ${autoloaddir:0:1} = / ]] || die 'the arg to -a must be an absolute path'
111 [[ ${pythondir:0:1} = / ]] || die 'the arg to -p must be an absolute path'
113 if ${create}; then
114 [[ ${autoloaddir:0:1} = / ]] || die 'the arg to -a must be an absolute path'
115 else
116 [[ ! -d ${DESTDIR}${autoloaddir} ]] && die "directory '${DESTDIR}${autoloaddir}' does not exist"
118 [[ ! -d ${DESTDIR}${installdir} ]] && die "directory '${DESTDIR}${installdir}' does not exist"
119 [[ ! -d ${GDBDIR} ]] && die "directory '${GDBDIR}' does not exist"
121 if [[ ${DESTDIR}${pythondir} != ${GDBDIR} ]]; then
122 mkdir -p "${DESTDIR}${pythondir}" || die "cannot create dir '${DESTDIR}${pythondir}'"
123 cp -pr "${GDBDIR}/libreoffice" "${DESTDIR}${pythondir}"
126 if [[ -n "${MERGELIBS}" ]]; then
127 make_autoload merged program libmergedlo."$DYLIB" merge svl tl basegfx vcl
128 make_autoload cppu program libuno_cppu."$DYLIB".3
129 make_autoload sal program libuno_sal."$DYLIB".3
130 make_autoload sw program libswlo."$DYLIB"
131 else
132 make_autoload basegfx program libbasegfxlo."$DYLIB"
133 make_autoload cppu program libuno_cppu."$DYLIB".3
134 make_autoload sal program libuno_sal."$DYLIB".3
135 make_autoload svl program libsvllo."$DYLIB"
136 make_autoload sw program libswlo."$DYLIB"
137 make_autoload tl program libtllo."$DYLIB"
138 make_autoload vcl program libvcllo."$DYLIB"
140 make_autoload writerfilter program libwriterfilterlo."$DYLIB"
142 # vim:set shiftwidth=4 softtabstop=4 expandtab: