Codebase list dwarfutils / upstream/20180724
upstream/20180724

Tree @upstream/20180724 (Download .tar.gz)

At the present time using cmake to build fails, so the
following that worked in November 2016 fails at least as of
March 2018.  Sorry.

Standard builds are done by configure/make as described below.
Cross-Compiles are described below, see CROSS COMPILES.

BUILDING IN SOURCE TREE
To just build libdwarf and dwarfdump if the source tree is
in /a/b/libdwarf-1 one might do:
    cd /a/b/libdwarf-1 ./configure make



LIBRARY REQUIREMENTS
libelf and zlib have to be installed to build libdwarf and
dwarfdump.  For example, in Ubuntu 16.04, install using:
   sudo apt-get install zlib1g zlib1g-dev libelf1 libelf-dev

zlib is available in source from http://zlib.net

libelf is available in source from  
http://www.mr511.de/software/
and
https://github.com/vtorri/libelf

BUILDING OUT OF SOURCE TREE
Or one could  create a new directory, for example,
    mkdir /var/tmp/dwarfex
    cd /var/tmp/dwarfex
    /a/b/libdwarf-1/configure (other options as required)
    make
In this case the source directory is not written-to and all
objects and files created are under /var/tmp/dwarfex

NOTE: When building out of source tree the source tree must
be cleaned of any files created by a build in the source tree
(just in case you tried that) before doing the out-of-source
build.

To build all the tools (including dwarfgen and dwarfexample)
use  a different configure command..
    ./configure --enable-dwarfgen --enable-dwarfexample make

To see all the available options to configure do
   ./configure --help

By default configure compiles and uses libdwarf.a.

With 
    ./configure --enable-shared
both libdwarf.a and libdwarf.so are built. The runtimes built
will reference libdwarf.so.

With 
    ./configure --enable-shared --disable-nonshared
libdwarf.so is built and used; libdwarf.a is not built.

INSTALL AND UNINSTALL

The default install is to /usr/local

So 'make install' (sudo make install) installs into
/usr/local/bin, /usr/local/lib, /usr/local/include, and
/usr/local/share/libdwarf.

Doing 'make uninstall' (sudo make uninstall) deletes
what 'make install' added but does not delete the
/usr/local/share/libdwarf directory that the 'make install'
created.

CHECKING FOR MEMORY CORRUPTION

Recent gcc has some checks that can be done at runtime.
  -fsanitize=address
  -fsanitize=leak
  -fsanitize=undefined
which are turned on here by --enable-sanitize at build time.

CROSS-COMPILES

For those wishing to build libdwarf (and possibly dwarfdump)
for a different machine than the build machine
it is now possible to do that.

It has been tested with host and target set to an ARM with
build on X86_64.  See
  https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
for standard GNU usage of build, host, and target.  See also:
https://www.gnu.org/software/autoconf/manual/autoconf.html#Specifying-Target-Triplets

The autoconf documentation strongly suggests adding --build
to the configure commands and in the example below adding
--build=i686-pc-linux-gnu is known to work on the test machine.

The following is an example. Currently configure figures out
the build environment for itself so we don't use --build here.

On build machine:
sudo apt-get install gcc-arm-linux-gnueabihf
#  Install libelf and zlib (libz) into
#  the gcc cross-build tree too.
#  I cheated: copied from arm machine into 
#  gcc-arm-linux-gnueabihf.

mkdir emptycross
cd emptycross
git clone git://git.code.sf.net/p/libdwarf/code
cd code
cd libdwarf 
./configure --host=arm-linux-gnueabihf
make
cd ../dwarfdump 
./configure --host=arm-linux-gnueabihf
make
# done

------------------ notes on updating ------

To update configure after hand updating a Makefile.am or
the configure.ac do the following command at the top level
(where this file is):
  autoreconf -vif
You will need the autotools installed including autoconf,
automake, and libtool to run autoreconf.

If, for some reason, you wish to run the small
basic checks of individual source files, first
do
  ./configure
  make
Then 
  make check
will run the special test scripts: dwarfdump/runtests.sh
libdwarf/runtests.sh (each must be run in its directory,
neither requires any arguments, just run each).

To create a release file do:
  ./configure --enable-dwarfexample --enable-dwarfgen
  make
  make dist
will generate a libdwarf-yyyymmdd.tar.gz file with the files
needed in a release
  scripts/CPLIBDWARFTAR is an example of generating 
fingerprints for the release file and copying the file.

David Anderson.  Updated July 23, 2018