Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / install-gdb-printers
blob3787bec50d79b81ec35706e6b70768860200fd1d
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 -f Do not create subdirs in the autoloader's dir. This option is only
37 used during build.
38 -h Show this help text.
39 -i dir The dir where libreoffice is installed. Defaults to whatever -a is.
40 -p dir The dir where pretty printers are placed.
42 Env. variables:
43 DESTDIR If set, it is prepended to all dir arguments.
45 Examples:
46 1) Install pretty printers into /usr/share/libreoffice/gdb, with
47 autoloaders in /usr/share/gdb/auto-load (run
48 "info gdb 'Extending GDB' Python Auto-loading" to learn more) and
49 installation in /usr/lib64/libreoffice (this is what Fedora does):
51 install-gdb-printers -a /usr/share/gdb/auto-load/usr/lib64/libreoffice -c \\
52 -i /usr/lib64/libreoffice -p /usr/share/libreoffice/gdb
53 EOT
56 make_autoload() {
57 local dir="${DESTDIR}${autoloaddir}"
58 ${flat} || dir="${dir}/$2"
59 local lib="${dir}/$3"
60 local merged="$4"
62 if ! ${flat}; then
63 local resolved="$(readlink "${DESTDIR}${installdir}/$2/$3")"
64 [ -n "$resolved" ] && lib=$resolved
65 dir="${lib%/*}"
68 if ${create}; then
69 mkdir -p "${dir}" || die "cannot create dir '${dir}'"
72 [[ -f ${lib}-gdb.py ]] && rm -f "${lib}-gdb.py"
73 if [[ -n "${merged}" ]]; then
74 sed -e "s!%PYTHONDIR%!${pythondir}!" -e "s!%MODULES%!${*:5}!" \
75 "${GDBDIR}/autoload.template" > "${lib}-gdb.py"
76 else
77 sed -e "s!%PYTHONDIR%!${pythondir}!" -e "s!%MODULES%!$1!" \
78 "${GDBDIR}/autoload.template" > "${lib}-gdb.py"
82 # dir where the autoloaders will be placed
83 autoloaddir=
84 # The installation dir. If only one of these is set, the other is set to
85 # the same value.
86 installdir=
87 # dir where the pretty printers will be placed
88 pythondir="${GDBDIR}"
89 # Create autoload dir if it does not exist. This only makes sense when
90 # installing into system gdb dir, so $autoloaddir must be absolute path.
91 create=false
92 # This option is only here to enable using the script during build of
93 # solenv/gdb . We must (or, better, want to :) avoid using the
94 # installation subpaths (like ure-link), because all libs in solver
95 # are in the same dir.
96 flat=false
98 # b de g jklmno qrstuvwxyzABCDEFGHIJK MNOPQRSTUVWXYZ0123456789
99 while getopts :a:cfhi:p:L opt; do
100 case ${opt} in
101 a) autoloaddir="${OPTARG}" ;;
102 c) create=true ;;
103 f) flat=true ;;
104 h) usage; exit ;;
105 i) installdir="${OPTARG}" ;;
106 p) pythondir="${OPTARG}" ;;
107 *) die "unknown option ${OPTARG}" ;;
108 esac
109 done
111 if [[ -z ${autoloaddir} && -z ${installdir} ]]; then
112 autoloaddir="${INSTALLDIR}"
113 installdir="${INSTALLDIR}"
114 elif [[ -n ${autoloaddir} && -z ${installdir} ]]; then
115 installdir="${autoloaddir}"
116 elif [[ -z ${autoloaddir} && -n ${installdir} ]]; then
117 autoloaddir="${installdir}"
120 if [[ -n ${DESTDIR} ]]; then
121 [[ ${autoloaddir:0:1} = / ]] || die 'the arg to -a must be an absolute path'
122 [[ ${pythondir:0:1} = / ]] || die 'the arg to -p must be an absolute path'
124 if ${create}; then
125 [[ ${autoloaddir:0:1} = / ]] || die 'the arg to -a must be an absolute path'
126 else
127 [[ ! -d ${DESTDIR}${autoloaddir} ]] && die "directory '${DESTDIR}${autoloaddir}' does not exist"
129 [[ ! -d ${DESTDIR}${installdir} ]] && die "directory '${DESTDIR}${installdir}' does not exist"
130 [[ ! -d ${GDBDIR} ]] && die "directory '${GDBDIR}' does not exist"
132 if [[ ${DESTDIR}${pythondir} != ${GDBDIR} ]]; then
133 mkdir -p "${DESTDIR}${pythondir}" || die "cannot create dir '${DESTDIR}${pythondir}'"
134 cp -pr "${GDBDIR}/libreoffice" "${DESTDIR}${pythondir}"
137 # keep in sync with solenv/Package_gdb.mk
138 if [[ -n "${MERGELIBS}" ]]; then
139 make_autoload merged program libmergedlo."$DYLIB" merge svl tl basegfx `[[ ${MERGELIBS} == "ALL" ]] && echo sw`
140 if [[ ${MERGELIBS} == "ALL" ]]; then
141 make_autoload urelibs ure/lib liburelibs."$DYLIB" merge cppu sal
142 else
143 make_autoload cppu ure/lib libuno_cppu."$DYLIB".3
144 make_autoload sal ure/lib libuno_sal."$DYLIB".3
145 make_autoload sw program libswlo."$DYLIB"
147 else
148 make_autoload basegfx program libbasegfxlo."$DYLIB"
149 make_autoload cppu ure/lib libuno_cppu."$DYLIB".3
150 make_autoload sal ure/lib libuno_sal."$DYLIB".3
151 make_autoload svl program libsvllo."$DYLIB"
152 make_autoload sw program libswlo."$DYLIB"
153 make_autoload tl program libtllo."$DYLIB"
155 make_autoload writerfilter program libwriterfilterlo."$DYLIB"
157 # vim:set shiftwidth=4 softtabstop=4 expandtab: