Cross Compile Hacks Andy Huang 0423
-
Upload
jchuang1977 -
Category
Documents
-
view
61 -
download
0
Transcript of Cross Compile Hacks Andy Huang 0423
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
1/43
Jan. 2012
Cross Compile HacksJNR322 Andy Huang
2013/04/24
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
2/43
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
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
3/43
3Confidential Material for Internal Use Only
Why we need cross compile
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
4/434
Confidential Material for Internal Use Only
Why we need cross compile
Native compile Cross compile
Native compiler
a compiler running and final binary execution on the same architecture
Cross compiler
A cross-compiler is one that compiles binaries for architectures other thanits own
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
5/435Confidential Material for Internal Use Only
How to install a package on linux distribution
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
6/436Confidential Material for Internal Use Only
How to install a package
Do not consider librarydependency
apt-get/yum install
You need to take care librarydependency
Build from source
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
7/437Confidential Material for Internal Use Only
How to build your own package
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
8/438Confidential Material for Internal Use Only
How to build your own package
X86
configure make makeinstall
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
9/439Confidential Material for Internal Use Only
How to build your own package
Embedded system
You need to take care the library dependency by yourself
Downloadsource
Checkdependency
configure make make install
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
10/4310Confidential Material for Internal Use Only
How to build your own package
Understand your config help file content
Configuration
Installation directories
System types
Optional Features
Optional Packages
Some influential environment variables
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
11/4311Confidential Material for Internal Use Only
How to build your own package
configuration
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 `..']
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
12/4312Confidential Material for Internal Use Only
How to build your own package
Installation directories
--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]
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
13/4313Confidential Material for Internal Use Only
How to build your own package
System types
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
The environment your build code
Let configure to take care--buildThe system onwhich the tools will run is called the host system--host
The system forwhich the tools generate code is called the target system--target
--host=arm-elf-linux or arm-elf
buildhosttarget
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
14/4314Confidential Material for Internal Use Only
How to build your own package
Optional Features
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-
FEATURE=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
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
15/4315Confidential Material for Internal Use Only
How to build your own package
Optional Packages
--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
Check package library dependency here
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
16/4316
Confidential Material for Internal Use Only
How to build your own package
influential environment variables
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory
LIBS libraries to pass to the linker, e.g. -lCPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if
you have headers in a nonstandard directory
CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search pathPKG_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
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
17/4317
Confidential Material for Internal Use Only
Some important flags
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
18/4318
Confidential Material for Internal Use Only
Some important flags
CPP - preprocessor
Delete all the #define , and extend all the macro define
process all the condition command , #if , #ifdef , #elif , #else , #endif
process #include command
delete all the comment code , // and /* */
#define __JNR__ is the same as -D__JNR__ CPPFLAGS
-I , to let compiler find the headers
LDFAGS
-L , to let compiler find the library
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
19/4319
Confidential Material for Internal Use Only
Some important flags
LIBS
-l , to pass the reference lib name to the compiler
-lz --> compiler will find libz.xxto link
CFLAGS
pass some optional arguments to compiler
-g
-O
-Wall
CXX - C++ compiler command
Do not confuse with CPP
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
20/4320
Confidential Material for Internal Use Only
Some important flags
PKG_CONFIG
let compiler find the dependency library automatically
pkg-config and xxx.pc (package config)
cat /usr/lib/pkgconfig/openssl.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/libincludedir=${prefix}/include
Name: OpenSSL
Description: Secure Sockets Layer and
cryptography libraries and toolsVersion: 0.9.8o
Requires:
Libs: -L${libdir} -lssl -lcrypto
Libs.private: -ldl -Wl,-Bsymbolic-functions -lz
Cflags: -I${includedir}
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
21/43
21Confidential Material for Internal Use Only
Some important flags
PKG_CONFIG
pkg-config --version ./openssl.pc
pkg-config --libs ./openssl.pc
pkg-config --cflags ./openssl.pc
Before you compile export PKG_CONFIG_PATH=/xxx/xxx/lib/pkgconfig
avoid Makefile to eat your x86 xxx.pc
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
22/43
22Confidential Material for Internal Use Only
Just do configure
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
23/43
23Confidential Material for Internal Use Only
Just do configure
libpcap + arp-scan (ARP scanning and fingerprinting tool)
libpcap configure arguments
configure , make , make install
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 \
--disable-ipv6 \--disable-universal \--disable-can \
--disable-canusb \--disable-bluetooth \--with-pcap=linux
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
24/43
24Confidential Material for Internal Use Only
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
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
25/43
25Confidential Material for Internal Use Only
Just do configure
Can not find xxx library ( RUN.1st)
check your library path or dependency
PKG_CONFIG_PATH libpcap did not provide libpcap.pc
CPPFLAGS=" -I/home/andy/ti-sdk-am335x-evm -05.04.01.00/fakero ot /incl ud e -
I/home/andy /t i-sdk-am335x-evm -05.04.01.00/fakeroo t/ inclu de/pcap"
LDFLAGS=" -L/home/andy/t i-sdk-am335x-evm -05.04.01.00/fakeroo t/ l ib"
LIBS="- lpcap"
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
26/43
26Confidential Material for Internal Use Only
Just do configure
Can not run test ( cannot run test program while crosscompiling ) - 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
Run RUN.3rd again
--cache-fi le=arm-l inux.cache
pgac_cv_snpr intf_ long_long_int_format=%lld
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
27/43
27Confidential Material for Internal Use Only
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
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
28/43
28Confidential Material for Internal Use Only
Some tricks
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
29/43
29Confidential Material for Internal Use Only
Some tricks
Record your configure parameters
RUN file
Collect the same platform libraries together
prefix
Fix the configure issue when cross-compile
cache-file
Help you to debug
config.log
Understand your package
config.help
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
30/43
30Confidential Material for Internal Use Only
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
CONFIG_SITE=/your/file/path
libpcap demo
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
31/43
31Confidential Material for Internal Use Only
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/fakerootprogram_transform_name = s,x,x,psdir = ${docdir}sbindir = ${exec_prefix}/sbinsharedstatedir = ${prefix}/comsrcdir = .sysconfdir = ${prefix}/etctarget_alias =
top_builddir = .top_srcdir = .
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
32/43
32Confidential Material for Internal Use Only
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]
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
33/43
33Confidential Material for Internal Use Only
autobuild
t b ild
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
34/43
34Confidential Material for Internal Use Only
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
t b ild t 0
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
35/43
35Confidential Material for Internal Use Only
autobuild step 0
Hello.c
#include
int main(){printf("hello\n");return 0;
}
t b ild t 1
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
36/43
36Confidential Material for Internal Use Only
autobuild step 1
autoscan
cp configure.scan configure.ac
edit configure.acAC_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 compilercharacteristics.
# Checks for library functions.
AC_OUTPUT
AC_PREREQ([2.67])AC_INIT(hello, 0.1, [email protected])AM_INIT_AUTOMAKEAC_CONFIG_SRCDIR([hello.c])
#AC_CONFIG_HEADERS([config.h])
# Checks for programs.AC_PROG_CCAC_CONFIG_FILES(Makefile)# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compilercharacteristics.
# Checks for library functions.
AC_OUTPUT
t b ild t 2
mailto:[email protected]:[email protected] -
5/28/2018 Cross Compile Hacks Andy Huang 0423
37/43
37Confidential Material for Internal Use Only
autobuild step 2
Create Makefile.am
bin_PROGRAMS=hellohello_SOURCES=hello.c
t b ild t 3
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
38/43
38Confidential Material for Internal Use Only
autobuild step 3
aclocal
autoconf
Generate configure file
automake a
Required file : NEWS README AUTHORS ChangeLog
./configure
make
t b ild t 4
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
39/43
39Confidential Material for Internal Use Only
autobuild step 4
make distcheck
Pack your source into hello-0.1.tar.gz
RELEASE !!!!
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
40/43
40Confidential Material for Internal Use Only
Reference data
Reference data
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
41/43
41Confidential Material for Internal Use Only
Reference data
Books
-
GCC
GNU Make
Homework
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
42/43
42Confidential Material for Internal Use Only
Homework
Zlib
Curl
-
5/28/2018 Cross Compile Hacks Andy Huang 0423
43/43