Professional Documents
Culture Documents
Jan. 2012
Outline
Why we need cross compile How to install a package on linux distribution How to build your own package Some important flags Just do configure
Some tricks
autobuild Reference data
Cross compiler
A cross-compiler is one that compiles binaries for architectures other than its own
apt-get/yum install
configure
make
make install
Download source
Check dependency
configure
make
make install
Installation directories
System types
Optional Features
Optional Packages
10
Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..']
11
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
12
--build
--host --target
The environment your build code Let configure to take care The system on which the tools will run is called the host system
The system for which the tools generate code is called the target system
13
--disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enableFEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-largefile omit support for large files --disable-protochain disable \"protochain\" insn --enable-ipv6 build IPv6-capable version [default=yes, if getaddrinfo available] --enable-optimizer-dbg build optimizer debugging code Turn on/off some package internal features
14
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-gcc don't use gcc --with-sita include SITA support --with-pcap=TYPE use packet capture TYPE --without-libnl disable libnl support [default=yes, on Linux, if present] --with-dag[=DIR] include Endace DAG support ["yes", "no" or DIR; default="yes" on BSD and Linux if present] --with-dag-includes=DIR Endace DAG include directory --with-dag-libraries=DIR
15
CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path GLIB_CFLAGS C compiler flags for GLIB, overriding pkg-config GLIB_LIBS linker flags for GLIB, overriding pkg-config
16
17
CPPFLAGS
-I<include dir> , to let compiler find the headers
LDFAGS
-L<lib dir> , to let compiler find the library
18
CFLAGS
pass some optional arguments to compiler -g -O -Wall
19
20
21
Just do configure
22
Just do configure
libpcap + arp-scan (ARP scanning and fingerprinting tool) libpcap configure arguments RANLIB="/opt/arago/bin/arm-arago-linux-gnueabi-ranlib" \ CXX="/opt/arago/bin/arm-arago-linux-gnueabi-g++" \ CC="/opt/arago/bin/arm-arago-linux-gnueabi-gcc" \ ./configure --host=mips-elf-linux \ --prefix=/home/andy/ti-sdk-am335x-evm05.04.01.00/fakeroot \ --disable-ipv6 \ --disable-universal \ --disable-can \ --disable-canusb \ --disable-bluetooth \ --with-pcap=linux configure , make , make install
Confidential Material for Internal Use Only
23
Just do configure
libpcap + arp-scan (ARP scanning and fingerprinting tool)
arp-scan configure arguments
RANLIB="/opt/arago/bin/arm-arago-linux-gnueabi-ranlib" \ CXX="/opt/arago/bin/arm-arago-linux-gnueabi-g++" \ CC="/opt/arago/bin/arm-arago-linux-gnueabi-gcc" \ ./configure --host=mips-elf-linux \ --prefix=/home/andy/ti-sdk-am335x-evm-05.04.01.00/fakeroot
24
Just do configure
Can not find xxx library ( RUN.1st)
check your library path or dependency
CPPFLAGS="-I/home/andy/ti-sdk-am335x-evm-05.04.01.00/fakeroot/include I/home/andy/ti-sdk-am335x-evm-05.04.01.00/fakeroot/include/pcap" LDFLAGS="-L/home/andy/ti-sdk-am335x-evm-05.04.01.00/fakeroot/lib" LIBS="-lpcap"
PKG_CONFIG_PATH
libpcap did not provide libpcap.pc
25
Just do configure
Can not run test ( cannot run test program while cross compiling ) - RUN.2nd
check config.log (line 448) and trace configure file (line 5750) pre-fill the answer which configure want to check get the answer from x86
--cache-file=arm-linux.cache pgac_cv_snprintf_long_long_int_format=%lld
26
Just do configure
Check your final binary file
file arp-scan arp-scan: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
27
Some tricks
28
Some tricks
RUN file Record your configure parameters prefix Collect the same platform libraries together cache-file
29
Some tricks
CONFIG_SITE
set default values for configure scripts to share Put your default environment values like
CC LD RANLIB
cache_file
prefix host
30
Some tricks
Prefix side effect
conf and binary file will be fixed to your prefix path
prefix = /home/andy/ti-sdk-am335x-evm-05.04.01.00/fakeroot program_transform_name = s,x,x, psdir = ${docdir} sbindir = ${exec_prefix}/sbin sharedstatedir = ${prefix}/com srcdir = . sysconfdir = ${prefix}/etc target_alias = top_builddir = . top_srcdir = .
31
Some tricks
Prefix side effect solution
Fine tune configure argument --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
32
autobuild
33
autobuild
autoconf
Generate configuration scripts
automake
Generate Makefile.in for configure from Makefile.am
aclocal
Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
libtool
Provide some scripts to generate static/shared libraries
34
autobuild step 0
Hello.c
#include <stdio.h> int main() { printf("hello\n"); return 0; }
35
autobuild step 1
autoscan cp configure.scan configure.ac
edit configure.ac
AC_PREREQ([2.67]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_SRCDIR([hello.c]) AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT
Confidential Material for Internal Use Only
autobuild step 2
Create Makefile.am
bin_PROGRAMS=hello hello_SOURCES=hello.c
37
autobuild step 3
aclocal autoconf
Generate configure file
automake a
Required file : NEWS README AUTHORS ChangeLog
./configure
make
38
autobuild step 4
make distcheck
Pack your source into hello-0.1.tar.gz
RELEASE !!!!
39
Reference data
40
Reference data
Books
- GCC GNU Make
41
Homework
Zlib Curl
42