[[adv-pkg]]
=== Advanced packaging

Hints for the following can be found in the *debhelper*(7) manpage:

* differences of the *debhelper* tool behavior under ``*compat* \<= 8''
* building several binary packages with several different build conditions
** making multiple copies of the upstream source
** invoking multiple ``*dh_auto_configure -S ...*'' commands in the *override_dh_auto_configure* target
** invoking multiple ``*dh_auto_build -S ...*'' commands in the *override_dh_auto_build* target
** invoking multiple ``*dh_auto_install -S ...*'' commands in the *override_dh_auto_install* target
* building *udeb* packages with ``*Package-Type: udeb*'' in *debian/control* (see https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package-Type[Package-Type])
* excluding some packages for the bootstrapping (see also https://wiki.debian.org/BuildProfileSpec[BuildProfileSpec])
** adding the *Build-Profiles* fields in binary package stanzas in *debian/control*
** building packages with the *DEB_BUILD_PROFILES* environment variable set to the pertinent profile name

Hints for the following can be found in the *dpkg-source*(1) manpage:

* naming convention for the multiple upstream source tarballs
** 'packagename_version'**.orig.tar.gz**
** 'packagename_version'**.orig-**'componentname'**.tar.gz**
* recording the Debian changes to the upstream source package
**  *dpkg-source --commit*

[[other-distro]]
=== Other distros

Although the upstream tarball has all the information to build the Debian package, it is not always easy to figure out which combination of options to use.

Also, the upstream may be more focused on the feature enhancements and may be less eager for backward compatibilities etc. which are important aspect of the Debian packaging practice.

The leveraging of information from other distributions is an option to address above issues.

If the other distribution in interest is a Debian derivative one, it is trivial to reuse it.

If the other distribution in interest is a https://en.wikipedia.org/wiki/RPM_Package_Manager[RPM] based distribution, see https://wiki.debian.org/Repackage_srcrpm[Repackage src.rpm].

Downloading and opening of the *src.rpm* file can be done with the *rget* command.  (Place the *rget* script in your PATH.)

.rget script
----
#!/bin/sh
FCSRPM=$(basename $1)
mkdir ${FCSRPM}; cd ${FCSRPM}/
wget $1
rpm2cpio ${FCSRPM} | cpio -dium
----

Many upstream tarballs contain the SPEC file named as 'packagename'.*spec* or 'packagename'.*spec.in* used by the RPM system.  This can be used as the baseline for the Debian package, too.


[[debug]]
=== Debug

When you face build problems or core dumps of generated binary programs, you need to resolve them yourself.  That's *debug*.

This is too deep a topic to describe here.  So, let me just list few pointers and hints for some typical debug tools.

* https://en.wikipedia.org/wiki/Core_dump[core dump]
** ``*man core*''
** Update the ``*/etc/security/limits.conf*'' file to include the following:
+
-------
* soft core unlimited
-------
** ``*ulimit -c unlimited*'' in *~/.bashrc*
** ``*ulimit -a*'' to check
** Press *Ctrl-\* or ``*kill -ABRT* 'PID''' to make a core dump file
* *gdb* - The GNU Debugger
** ``*info gdb*''
** ``Debugging with GDB'' in */usr/share/doc/gdb-doc/html/gdb/index.html*
* *strace* - Trace system calls and signals
** Use *strace-graph* script found in */usr/share/doc/strace/examples/* to make a nice tree view
** ``*man strace*''
* *ltrace* - Trace library calls
** ``*man ltrace*''
* ``*sh -n* 'script.sh''' - Syntax check of a Shell script
* ``*sh -x* 'script.sh''' - Trace a Shell script
* ``*python -m py_compile* 'script.py''' - Syntax check of a Python script
* ``*python -mtrace --trace* 'script.py''' - Trace a Python script
* ``*perl -I ../libpath -c* 'script.pl''' - Syntax check of a Perl script
* ``*perl -d:Trace* 'script.pl''' - Trace a Perl script
** Install the *libterm-readline-gnu-perl* package or its equivalent to add the input line editing capability with history support.
* *lsof* - List open files by processes
** ``*man lsof*''

TIP: The *script* command helps recording console outputs. 

TIP: The *screen* and *tmux* commands used with the *ssh* command offer the secure and robust remote connection terminal.

TIP: Python and Shell like REPL (=READ + EVAL + PRINT + LOOP) environment for Perl is offered by the *reply* command from the *libreply-perl* (new) and the *re.pl* command from the *libdevel-repl-perl* (old).

TIP: The *rlwrap* and *rlfe* commands add the input line editing capability with history support to any interactive commands.  E.g. ``*rlwrap dash -i*''' .

