Building Existing Software Packages with EMAC OE SDK
It is often necessary to build an existing project from source code. This is the case when a specific program is required to run on the target device and pre-compiled binaries do not exist. In the steps below, the EMAC SDK toolchain will be used to compile an existing
Makefile based project and an
Autotools based project that can be run on the target device.
The GNU make utility uses one or more Makefiles to direct the compiler to what source files to build and what options to use when building. Makefile based projects are generally set up for larger complex projects to simplify the configuration of the project. The example below uses a relatively simple project that can be extended as needed.
HelloMake Project Example
The HelloMake project contains two source files, a header file, and a Makefile. The Makefile will direct make to use the correct target compiler and libraries to compile the source and header files into an executable. The header file is located in the include directory as is common with larger projects. The obj files created will be stored in the obj directory to keep from cluttering the source directory and the executable will be placed in the bin directory. The Makefile also contains a clean target to remove all of the temporary and intermediate files and an upload target to upload the executable to the target device.
Begin by downloading the HelloMake project
Extract the project.
developer@ldc:~$ tar zxvf HelloMake.tar.gz
Modify the first line of Makefile in the src directory to point to the path to the correct global.properties file. Make sure that the setmachine script has been run before attempting to build the project. This allows make to use the correct compiler and compile options for the target machine.
From the command prompt in the src directory type make
developer@EMAC-LDC-32bit:~/EMAC-OE-arm-linux-gnueabi-SDK_4.0/HelloMake/src$ make ../../gcc-4.3.1-arm-emac-linux-gnueabi/bin/arm-emac-linux-gnueabi-gcc -MMD -g -march=armv7-a -mtune=cortex-a8 -mfpu=neon -c -o obj/hellomake.o hellomake.c ../../gcc-4.3.1-arm-emac-linux-gnueabi/bin/arm-emac-linux-gnueabi-gcc -MMD -g -march=armv7-a -mtune=cortex-a8 -mfpu=neon -c -o obj/hellofunc.o hellofunc.c ../../gcc-4.3.1-arm-emac-linux-gnueabi/bin/arm-emac-linux-gnueabi-gcc -lm -o ../bin/hellomake obj/hellomake.o obj/hellofunc.o
After successfully compiling the project, the
uploadmake target can be used to transfer the executable to the target machine as specified by the upload line in Makefile.
developer@ldc:~$ make upload
The GNU build system is known as Autotools. Autotools is a group of applications that are designed to provide a configurable build system to allow compilation on different platforms and environments. A
configure script and set of input files are used to generate makefiles based on options passed to the configure script and deduced from the system environment. This includes tests for compiler options, library functions, install configuration, and other assorted variables.
configure script is the most important step in building an autotools-based project. Although available options for
configure vary depending on the project design, there are common options shared between most autotools projects.
libConfuse Example Project
The libConfuse project is a simple C library written for parsing configuration files. It uses an autotools build system for configuration. The steps below demonstrate how to build libConfuse and should be used as an example for building other autotools-based projects.
The source code for the libConfuse project can be downloaded as described on the project website. For this example, release 2.7 is used. After downloading the source, extract the archive and navigate to the top-level directory of the project.
Read through the
INSTALLfiles for information on the project and general information on how to build it. Also, look at the help output from
configureto see a summary of the available options:
developer@ldc:~$ ./configure --help
In order for autotools to use the correct compiler and compile options, the
CXXvariables need to be set. Open the correct global.properties file to see what the values should be. The example below is for an armv5 processor.
developer@ldc:~$ export CC="/path/to/sdk/gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc" developer@ldc:~$ export CXX="/path/to/sdk/gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-g++" developer@ldc:~$ export CFLAGS="-O2 -march=armv5te -mtune=arm926ej-s" developer@ldc:~$ export DESTDIR=`pwd`/Install
After setting the environment,
configurecan be run with the appropriate options to configure the build system and generate the makefiles. The code below shows an example configuration. Be sure to set the host and target correctly based on the architecture:
developer@ldc:~$ ./configure --build=i686-linux --host=arm-linux-gnueabi --target=arm-linux-gnueabi \ --prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin \ --datadir=/usr/share \ --infodir=/usr/share/info \ --mandir=/usr/share/man --enable-shared
The configuration should complete successfully. If any problems are reported that result in an error, check the environment settings and
configurehas generated all of the makefiles for the project,
makecan be used to compile the source code:
developer@ldc:~$ make all
If any errors are encountered during compilation, examine the output of
configureand make sure that all of the environment variables and
configureoptions were specified correctly.
Once compilation is complete, the
installtarget can be used to package all of the necessary files together so that they can be transferred to the target board.
developer@ldc:~$ make install developer@ldc:~$ ls -R Install
Install: usr Install/usr: include lib share Install/usr/include: confuse.h Install/usr/lib: libconfuse.a libconfuse.la libconfuse.so libconfuse.so.0 libconfuse.so.0.0.0 pkgconfig Install/usr/lib/pkgconfig: libconfuse.pc Install/usr/share: locale Install/usr/share/locale: fr sv Install/usr/share/locale/fr: LC_MESSAGES Install/usr/share/locale/fr/LC_MESSAGES: confuse.mo Install/usr/share/locale/sv: LC_MESSAGES Install/usr/share/locale/sv/LC_MESSAGES: confuse.mo