Autotools

autoreconf -i
 
# delete old generated configuration files and overwrite them
# generate new files with verbose output
autoreconf -f -i -v
 
# Purge all generated files
autoreconf -p
  • autogen.sh is custom script written by developer
#!/bin/sh
set -e
autoreconf -f --install --verbose
  • Generate Makefile from
    • configure.ac
    • Makefile.am
./configure
 
# see all options
./configure --help
 
# change final installation directory
./configure --prefix=$HOME/.local
 
# machine where compilation will happen
./configure --build="aarch64-unknown-linux-gnu"
 
# --enable-<feature> / --disable-<feature>
./configure --disable-gui
 
# --with-<package> / --without-<package>
./configure --with-openssl
 
# pass compilation environment variables
./configure CFLAGS="-O3 -march=native" LDFLAGS="-L/usr/local/custom-lib"
 
# enable debugging
./configure --enable-debug

GNU Make

  • Compile
make
 
# Run 3 jobs in parallel
make -j3
  • Install to your system
sudo make install
 
# install to temporary destination
# see how the software will get installed
sudo make install DESTDIR=/tmp/pkg-root
 
# dry run
# prints all instructions for installation
make install -n
make install --just-print
  • Uninstall if supported
sudo make uninstall

Makefile

  • https://makefiletutorial.com/
  • https://www.gnu.org/software/make/manual/html_node/Makefile-Contents.html
  • It is a configuration file that instructs the make program exactly how to build the program
  • consists of
    • variable definitions
      • srcdir, prefix, CC
    • explicit rules
      • targets, pre-requisites and the commands needed to create the target from components
      targets: prerequisites
      	command
      	command
      	command
    • implicit rules
      • .c.o: tells how to build .o from .c files
    • special target
      • .PHONY: tells which targets are phony
      • .SUFFIXES: tells which suffix based implicit rules are defined
    • directives
      • include, define, ifeq
  • targets can be of two types
    • File target
      • examples: diction, diction.o, getopt.o, misc.o
    • Phony target
      • examples: install, clean, all, check, distclean, tar
  • Sample Makefile
srcdir=		.
 
prefix=		/usr/local
 
CC= gcc
LDFLAGS= -g
 
.PHONY: all check install clean distclean tar
 
all: diction style all-po-no
 
diction:	diction.o sentence.o misc.o getopt.o getopt1.o
		$(CC) -o $@ $(LDFLAGS) diction.o sentence.o misc.o \
		getopt.o getopt1.o $(LIBS)
 
clean:
		rm -f *.out core *.o *.mo diction.html diction.info
 
diction.o:      diction.c config.h getopt.h misc.h sentence.h

Packaging

  • Autotools do not support packaging
  • OS tools are required to perform packaging
  • The following steps are needed for debian packaging
    • Requirements:
      • Your source code (the application files)
      • A debian/ metadata folder (the configuration blueprints)
    • The Required Tools
      • build-essential: Installs compilers (gcc, make) to build the source code
      • dh-make: Generates the initial, blank debian/ metadata templates
      • debhelper: Provides the engine (dh) that converts the source and metadata into a finished .deb file