– General Linux 2 – Make and install programs from source [5] (Linux Professional Institute Certification) a .˜. /V\ // \\ @._.@ by: geoffrey robertson geoffrey@zip.com.au $Id: gl2.102.3.slides.tex,v 1.3 2003/05/30 06:03:32 waratah Exp $ c 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version. a Copyright 1 List of Slides 1 – (2.2) 102 Installation & Package Mgt. [24] . . . . . . . . . . . . 3 2 – Make and install programs from source [5] . . . . . . . . . . . . 4 2.1 – Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.2 – Key files, terms, and utilities . . . . . . . . . . . . . . . . . . 5 2.3 – Resources of interest . . . . . . . . . . . . . . . . . . . . . . 6 3 – Source Code Distribution . . . . . . . . . . . . . . . . . . . . . 7 3.1 – ................................. 7 4 – Installing the trivial database tdb . . . . . . . . . . . . . . . . . 8 4.1 – Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.2 – Unpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.3 – cd into the tree . . . . . . . . . . . . . . . . . . . . . . . . . 10 2 4.4 – ./configure . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.5 – The Makefile . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.6 – make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.7 – make install . . . . . . . . . . . . . . . . . . . . . . . . 16 5 – Using tdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6 – Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 ⇒• • • • • • (2.2) 102 Installation & Package Mgt. [24] . . . . . Make and install programs from source [5] . . . . . Source Code Distribution .............. Installing the trivial database tdb . . . . . . . . . . Using tdb . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . 3 4 7 8 17 19 4 (2.2) 102 Installation & Package Mgt. [24] 2.102.1 Design hard disk layout [2] 2.102.2 Install a boot manager [3] 2.102.3 Make and install programs from source [5] 2.102.4 Manage shared libraries [3] 2.102.5 Use Debian package management [5] 2.102.6 Use Red Hat Package Manager (RPM) [6] 5 √ • (2.2) 102 Installation & Package Mgt. [24] . . . . . Make and install programs from source [5] . . . . . Objective Key files, terms, and utilities Resources of interest 3 4 ⇒• • • • • Source Code Distribution .............. 7 8 17 19 Installing the trivial database tdb . . . . . . . . . . Using tdb . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . 6 Make and install programs from source [5] Objective Candidates should be able to build and install an executable program from source. This objective includes being able to unpack a file of sources. Candidates should be able to make simple customisations to the Makefile, for example changing paths or adding extra include directories. 7 Make and install programs from source [5] Key files, terms, and utilities gunzip gzip bzip2 tar configure make 8 Make and install programs from source [5] Resources of interest LPI Linux Certification in a Nutshell by Jeffrey Dean O’Reilly LPIC 1 Certification Bible Angie Nash and Jason Nash Hungry Minds 9 √ √ • • (2.2) 102 Installation & Package Mgt. [24] . . . . . Make and install programs from source [5] . . . . . Source Code Distribution .............. 3 4 7 8 17 19 ⇒• • • • Installing the trivial database tdb . . . . . . . . . . Using tdb . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . 10 Source Code Distribution To distribute software in the form of source code a source tree is archived into one file using the tar command and then compressed. The resulting file is called a tarball. Source code may also be distributed using the package management tools of a particular distribution. Debian apt-get install kernel-source-2.2.27 Redhat rpm -Uhv at-3.1.8-23.src.rpm Tarball tdb-1.0.6.tar.gz 11 √ √ √ • • • (2.2) 102 Installation & Package Mgt. [24] . . . . . Make and install programs from source [5] . . . . . Source Code Distribution Download Unpack cd into the tree ./configure The Makefile make make install 3 4 7 8 .............. ⇒• Installing the trivial database tdb . . . . . . . . . . • Using tdb . . . . . . . . . . . . . . . . . . . . . . 12 17 • Summary . . . . . . . . . . . . . . . . . . . . . . . 19 13 Installing the trivial database tdb Download Locate and download the tarball • googling for it: http://google.com • search on freshmeat: http://freshmeat.net Download the tarball to a suitable directory such as /tmp. • see if it lives on sourceforge: http://www.sf.net 14 Installing the trivial database tdb Unpack The tarball file is a compressed archived source tree. Most commonly the file will be compressed using either gzip or bzip2 GNU tar can uncompress and unpack the archive: $ tar zxvf tdb-1.0.6.tar.gz ← or $ tar jxvf tdb-1.0.6.tar.bz2 ← 15 Installing the trivial database tdb cd into the tree The unpacked tarball creates a source tree. The base of which is the name of the program $ ls ← tdb-1.0.6 tdb-1.0.6.tar.gz $ cd tdb-1.0.6 ← $ ls ← configure ... tdb.c tdb.h README INSTALL COPYING 16 Installing the trivial database tdb cd into the tree $ ls -w 70 ← acconfig.h aclocal.m4 AUTHORS ChangeLog config.guess config.h.in config.sub configure configure.in COPYING INSTALL install-sh ltconfig ltmain.sh Makefile.am Makefile.in missing mkinstalldirs NEWS README spinlock.c spinlock.h stamp-h.in tdb.3 tdb.c tdb_chainlock.3 tdb_close.3 tdb_delete.3 tdbdump.c tdb_error.3 tdb_exists.3 tdb_fetch.3 tdb_firstkey.3 tdb.h tdbiterate.c tdb_open.3 tdb.spec tdbspeed.c tdb_store.3 tdbtest.c tdbtool.c tdbtorture.c tdb_traverse.3 TODO 17 Installing the trivial database tdb ./configure $ file configure ← configure: Bourne shell script text executable $ head -5 configure ← #! /bin/sh # Guess values for system-dependent variables # Create Makefiles. # Generated automatically using autoconf version 2.13 18 Installing the trivial database tdb ./configure $ ./configure ← creating cache ./config.cache checking for a BSD compat install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets $MAKE... yes checking for working aclocal... found ... creating ./config.status creating Makefile creating config.h 19 Installing the trivial database tdb The Makefile SHELL = /bin/sh CC = gcc CFLAGS = -g -O2 prefix = /usr/local includedir = $prefix/include ... tdbtool: $(tdbtool_OBJECTS) $(tdbtool_DEPENDENCIES) @rm -f tdbtool $(LINK) $(tdbtool_LDFLAGS) $(tdbtool_OBJECTS) ... distclean: distclean-am -rm -f config.status 20 Installing the trivial database tdb make $ make ← /bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c tdb.c mkdir .libs gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c -fPIC -DPIC tdb.c -o .libs/tdb.lo gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c tdb.c -o tdb.o >/dev/null 2>&1 mv -f .libs/tdb.lo tdb.lo /bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c spinlock.c ... 21 Installing the trivial database tdb make install su -c ’make install’ Password: make[1]: Entering directory ‘/tmp/tdb-1.0.6’ /bin/sh ./mkinstalldirs /usr/local/lib /bin/sh ./libtool --mode=install /usr/bin/install -c libtdb.la /usr/local/lib/libtdb.la ... chmod 644 /usr/local/lib/libtdb.a PATH="$PATH:/sbin" ldconfig -n /usr/local/lib 22 Using tdb $ tdbtool ← tdb> ? tdbtool: create open erase dump insert store show delete list free 1 | first n | next q | quit \n tdb> dbname dbname dumpname key data key data key key : : : : : : : : : : : : : : create a database open an existing database erase the database dump the database as strings insert a record store a record (replace) show a record by key delete a record by key print the database hash table and freelist print the database freelist print the first record print the next record terminate repeat ’next’ command 23 Using tdb $ tdbtool ← tdb> create test.tdb tdb> insert 1 thing tdb> insert 2 foo tdb> insert 3 bar tdb> insert 55 whizz tdb> show 3 key 2 bytes 3 data 4 bytes [000] 62 61 72 00 bar 24 Summary • $ tar zxvf my-progy.tar.gz ← 25 Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← 25-a Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← • $ less README INSTALL ← 25-b Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← • $ ./configure ← • $ less README INSTALL ← 25-c Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← • $ ./configure ← • $ make ← • $ less README INSTALL ← 25-d Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← • $ ./configure ← • $ make ← • $ less README INSTALL ← • $ su -c ’make install’ ← 25-e Summary • $ tar zxvf my-progy.tar.gz ← • $ cd my-progy ← • $ ./configure ← • $ make ← • $ less README INSTALL ← • $ su -c ’make install’ ← • $ my-progy ← 25-f The End √ √ √ √ √ √ • • • • • • (2.2) 102 Installation & Package Mgt. [24] . . . . . Make and install programs from source [5] . . . . . Source Code Distribution .............. Installing the trivial database tdb . . . . . . . . . . Using tdb . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . 3 4 7 8 17 19 26