Gnubs pres-foss-cdac-sem

24
Presentation on GNU Build System for (FOSS) From the Open Source Shelf CDAC Monthly Seminar Series Presented by Sagun Baijal Organised by CDAC, Kharghar, Navi Mumbai E-mail: [email protected]

Transcript of Gnubs pres-foss-cdac-sem

Page 1: Gnubs pres-foss-cdac-sem

Presentation on

GNU Build Systemfor

(FOSS) From the Open Source Shelf CDAC Monthly Seminar Series

Presented bySagun Baijal

Organised by

CDAC, Kharghar, Navi MumbaiE-mail: [email protected]

Page 2: Gnubs pres-foss-cdac-sem

WELCOME

Page 3: Gnubs pres-foss-cdac-sem

Overview

BackgroundWhy GNU Build SystemIntroduction to GNU Build SystemUsing GNU Build SystemConclusionReferences

Page 4: Gnubs pres-foss-cdac-sem

Background• Typical Methods of installing a software in Unix- like systems

• Installation by using a package manager• Installtion from source code

• GNU standard method of installation• Packages normally come as a tarball.• Decompress the package.• Run configure script e.g. ...:~$./configure• Run make e.g. ...:~$make• Run make install e.g. ...:~$sudo make install

Page 5: Gnubs pres-foss-cdac-sem

Background contd...• Issues while packaging the system for release

• Naming and Versioning of the package.• Portability of system on a variety of platforms.• Configuration script configure with standrad

configurations options.• Makefile.inS required by configure script.• Conformity of Makefile and directory layout as per

GNU standards.• Necessary documentation files and tests. • Bundling of the package into a tarball.• Licensing of the system.

Page 6: Gnubs pres-foss-cdac-sem

Why GNU Build System

• Creating a configuration script and Makefiles from scratch is a tedious, time-consuming and error-prone task. • Some users may be left unsatisfied due to unavailability of some desired features.• It may be needed to upgrade the overall setup to follow the changes to the GNU Coding Standards.

Page 7: Gnubs pres-foss-cdac-sem

Contd...

• GNU Build System helps:• simplify the development of portable programs.• simplify the building of programs distributed as

source code. • Any bux fixes and improvements can be made at one place.• Users don't require any utilities of build system at their end.

Page 8: Gnubs pres-foss-cdac-sem

Introduction to GNU Build System

• GNU Build System comprises:• autoconf: For generating configuration script configure.• automake: For generating makefile templates

Makfile.inS• libtool: Helps creating the portable compiled libraries.

• Some other auxilary tools:• Autoscan: For generating intial input file for autoconf.• Autoheader: For generating template header for

configure.• aclocal: For generating aclocal.m4.

Page 9: Gnubs pres-foss-cdac-sem

Contd...

• Installation:• To check, if installed in their most recent versions:

• ...:~$autoconf - -version• ...:~$automake - -version• ...:~$libtool - -version

• If not installed, then (on any debian-like system):• ...:~$apt-cache search <tool-name> - searches for the

tool-name in available package list.• ...:~$sudo apt-get install <tool-name> - installs the

<tool-name>.

Page 10: Gnubs pres-foss-cdac-sem

Using GNU Build System

• Basic requirements:• Source and documentation files of the package.• One configure.ac/.in as initial input file for

autoconf.• One Makefile.am for each directory in the package.

• Source and Documentation files:• Files containing source code and necessary

documentation to be distributed in the package.• Ex.: .c, .cpp files, README etc..

Page 11: Gnubs pres-foss-cdac-sem

Contd...• What is configure.ac?

• Initial input file for autoconf to generate configure script. Also used by automake, while creating Makefile.amS.

• Contains macros needed to test the system features required or used by the package.

• Using autoscan:• autoscan scans source files and creates configure.scan.• After making some adjustments, if required,

configure.scan can be renamed to configure.ac.• Adjustments may be like adding some missing macros

or changing the order of some macros etc..

Page 12: Gnubs pres-foss-cdac-sem

Contd...• Common macros:

• AC_PREREQ: specifies the minimum version of autoconf that can successfully compile a given configure.ac.

• AC_INIT: initializes autoconf.• AM_INIT_AUTOMAKE: initializes automake.• AC_PROG_CC: determines a C compiler to use and sets output

variable CC to its value.• AC_PROG_CXX: determines a C++ compiler to use and sets output

variable CXX to its value.• AC_CONFIG_HEADER: causes to create a config.h file gathering

‘#define’s defined by other macros in configure.ac.• AC_CONFIG_FILES: declares the list of files to be created from their

*.in templates.• AC_OUTPUT: generates and runs config.status, which in turn creates

the makefiles and any other files resulting from configuration.

Page 13: Gnubs pres-foss-cdac-sem

Contd...

• Example configure.ac:AC_PREREQ(2.61)AC_INIT([hello], [0.1], [[email protected]]) AM_INIT_AUTOMAKE([-Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([ Makefile src/Makefile])AC_OUTPUT

Page 14: Gnubs pres-foss-cdac-sem

Contd...• What is Makefile.am?

• Initial input file for automake to generate Makefile.in.

• One Makefile.am for each directory in package including root directory.

• Normally contains a list of variable (and rule) definitions required when make is invoked.

• Common Makefile targets:• make all: Build programs, libraries, documentation,

etc.• make install: Install what needs to be installed,

copying the files from the package's tree to system-wide directories.

Page 15: Gnubs pres-foss-cdac-sem

Contd...• make uninstall: The opposite of make install: erase the

installed files.• make clean: Erase from the build tree the files built by

make all.• make distclean: Additionally erase anything

./configure created.• make check: Run the test suite, if any.• make installcheck: Check the installed programs or

libraries, if supported.• make dist: Recreate package-version.tar.gz from all

the source files.

Page 16: Gnubs pres-foss-cdac-sem

Contd...• Common variables for Makefile.am:• bin_PROGRAMS: specifies the <program> to be built

and installed on .../bin directory.• <program>_SOURCES: lists one or more source files

compiled to build the <program>.• SUBDIRS: lists all sub-directories to be built.• dist_doc_DATA: lists documentation files to be

distributed and installed in ../doc directory.• <program>_DEPENDENCIES: specifies dependencies,

if any.• <program>_<FLAGS>: various compilation flags can

be set.

Page 17: Gnubs pres-foss-cdac-sem

Contd...

• <program>_LDADD: specifies extra objects and libraries to be added with <program>.

• <program>_LDFLAGS: specifies extra linker flags for <program>.

• An example Makefile.am:bin_PROGRAMS = hellohello_SOURCES = hello.c

Page 18: Gnubs pres-foss-cdac-sem

Contd...• Some characteristics of GNU Build System:

• VPATH Builds: When source tree and build tree are different, such builds are called VPATH builds.

• Cross-compilation: When a program is built on one platform and run on another platform is called cross-compilation.

• Renaming: GNU build system allows to automatically rename executables etc. before installation.

• Dependency tracking: GNU build system allows to track dependencies automatically.

• Nested packages: Autoconfiscated packages can be nested to arbitrary depth.

Page 19: Gnubs pres-foss-cdac-sem

Contd...• Applying tools to create the package:

• Ensure all necessary source, documentation and Makefiel.amS files have been created.

• Run autoscan to create prelimanary configure.scan.• ..:~/<pkg-dir>$autoscan

• If required, edit configure.scan to update package-name, version, invocation to AM_INIT_AUTOMAKE macro etc. and rename it to configure.ac.

• Run aclocal to create aclocal.m4. This file contains macro definitions not part of standard autoconf macros.• ..:~/<pkg-dir>$aclocal

Page 20: Gnubs pres-foss-cdac-sem

Contd...• Run autoheader to create config.h.in. This file is a

template header for configure.• ..:~/<pkg-dir>$autoheader

• Run autoconf to create configure from configure.ac and aclocal.m4.• ..:~/<pkg-dir>$autoconf

• Run automake to create Makefile.inS from Makefile.amS.• ..:~/<pkg-dir>$automake

• Run configure to create Makefiles from Makefile.inS, config.h from config.h.in and perform various checks about the environment.• ..:~/<pkg-dir>$./configure

Page 21: Gnubs pres-foss-cdac-sem

Contd...

• Now run make to build the system.• ..:~/<pkg-dir>$make

• If make executes successfully, run make distcheck to create the package for distribution as a tarball.• ..:~/<pkg-dir>$make distcheck

• Run make install to install the package.• ..:~/<pkg-dir>$sudo make install

• Run make uninstall to uninstall the package.• ..:~/<pkg-dir>$sudo make uninstall

Page 22: Gnubs pres-foss-cdac-sem

Conclusion

• From User's point of view:• provides a standard procedure for installation.• procedure consists of only a small set of commands.

• From Developer's point of view:• Creating portable distributions become easy.• Updations or improvements, if any, can be done at

one place.

Page 23: Gnubs pres-foss-cdac-sem

References http://autotoolset.sourceforge.net/tutorial.html http://www.gnu.org/software/automake/manual/automake.html http://sources.redhat.com/autobook/ http://www.gnu.org/software/hello/manual/autoconf/autoscan-Invocation.html#autoscan-Invocation http://www.lrde.epita.fr/~adl/autotools.html http://en.wikipedia.org/wiki/GNU_build_system http://www.gnu.org/prep/standards/standards.html http://www.dwheeler.com/essays/releasing-floss-software.html http://www.gnu.org/software/hello/manual/autoconf/Autoconf-Macro-Index.html http://www.devshed.com/c/a/Administration/Linux-Administration-Installing-Software/9/ http://www.control-escape.com/linux/lx-swinstall.html http://www.unixguide.net/linux/faq/05.02.shtml http://www.gnu.org/software/libtool/

Page 24: Gnubs pres-foss-cdac-sem

Thank YouE-mail: [email protected]