2.3. Build Environment
The assessment of the application continues by examining its build environment. When porting applications, it is important to see what tools are used to build the application. In most circumstances, you will find that the build tools used on other UNIX platforms will have similar counterparts on Linux. When examining the build environment, it is also necessary to take note of the build process. Some build processes are straightforward, and others are complex. Complex build processes add to porting difficulty and should be factored in when creating the schedules for the project.
The make development tool in Linux is the GNU make or gmake. As of this writing, the latest version of gmake is version 3.8, which this section is based on. The gmake home page is located at www.gnu.org/software/make/. Note that gmake 3.8 is also available on Solaris, AIX, and HP-UX. Porting the build environment from other UNIX platforms to Linux means using gmake and making sure the makefiles to build the application are correctly ported to build all necessary application modules.
Because gmake conforms to the POSIX standard similarities between other UNIX operating platforms, makefiles and GNU makefiles abound. However, there are still some differences, which are covered in more detail in Chapters 4, 5 and 6.
2.3.2. GNU Binutils
The development tool chain for Linux is made up of other GNU tools known as the GNU binutils. The most commonly used tool in the GNU binutils is the GNU linker, ld, and the GNU assembler, as.
184.108.40.206. The GNU ld
Running ld is usually the last step when compiling source code to produce a program executable. The ld command is responsible for combining object and archive files as well as for reconciling symbol references within the program executable. The GNU linker provides more diagnostic information than other linkers. Although other linkers simply abandon execution when an error is encountered, the GNU ld tries to continue execution whenever possible to further identify the cause of the error.
Although GNU ld has a lot of features to offer, including the use of linker scripts, most of the discussion around GNU ld focuses on the linker command-line options. A simple command-line option that shows how ld links an object file follows:
$ ld -o output /lib/crt0.o foo.o -lc
This tells ld to produce a file called output as the result of linking the file /lib/crt0.o with foo.o and the library libc.a, which will come from the standard search directories.
GNU ld can also be invoked indirectly through a GNU compiler, such as gcc. When invoking indirectly, all command-line options to the linker must be prefixed by the -Wl option, as in the following example:
$ gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
GNU ld supports many options that are compatible with linker options from other operating systems such as Solaris, AIX, and HP-UX. In each of the main porting chapters for the different operating systems (Chapters 4, 5 and 6), GNU ld options are compared side by side so that the porting engineer has a reference of what linker flags to use when porting from other platforms.
For more information about the ld options, consult the latest GNU ld manual, available from www.gnu.org/software/binutils/manual/ld-2.9.1/ld.html.
2.3.3. The GNU as
GNU as is a family of assemblers. If you use (or have used) the GNU assembler on one architecture, you should find a fairly similar environment when you use it on another architecture. Each version has much in common with the others, including object file formats, most assembler directives (often called pseudo-ops), and assembler syntax.
as is primarily intended to assemble the output of the GNU C compiler gcc for use by the linker ld. Nevertheless, GNU has tried to make as assemble correctly everything that other assemblers for the same machine would assemble. Any exceptions are documented explicitly in the Machine Dependent Features of the GNU as manual. This does not mean that as always uses the same syntax as another assembler for the same architecture; for example, GNU is aware of several incompatible versions of the 680x0 assembly language syntax.
Unlike older assemblers, as is designed to assemble a source program in one pass of the source file. This has a subtle impact on the .org directive.
The GNU assembler can be configured to produce several alternative object file formats. For the most part, this does not affect how you write assembly language programs, but directives for debugging symbols are typically different in different file formats. For instance, on some Intel machines (80960, for example), as can be configured to produce either a COFF or an a.out format. On other machines, as can be configured to produce either a COFF or a b.out format. On HPPA systems, as can be configured to produce either SOM or ELF. The default format on Linux systems is ELF.
After the assembler invocation as, the command line may contain options and filenames. Options may appear in any order, and may be before, after, or between filenames. The order of filenames is significant.
A command-line argument that begins with a hyphen (-) is an option. Each option changes the behavior of as. No option changes the way another option works. An option is a - followed by one or more letters; the case of the letter is important. The following shows the syntax used by as:
as f o foo.o foo.s as --help
The command-line argument of -- (two hyphens) by itself names the standard input file explicitly as one of the files for as to assemble. The following example shows the syntax for --:
as -- [files]
Some options expect exactly one filename to follow them. The filename may either immediately follow the option's letter (compatible with older assemblers) or it may be the next command argument (GNU standard). These two command lines are equivalent:
as -o my-object-file.o mumble.s as -omy-object-file.o mumble.s
For more details on each command-line option, refer to the GNU as documentation available from www.gnu.org/software/binutils/manual/gas-2.9.1/as.html.
Another useful feature of GCC is to invoke the GNU assembler from the gcc compiler. To do this, you use the following command:
gcc -c -g -O -Wa,-alh,-L file.c
The assembler arguments must be separated from each other (and the -Wa) by commas. The preceding command causes a listing to be emitted to standard output with high-level messaging on an assembly source. Notice that two options (-alh and L) are passed on to as with one invocation of Wa. Also, the c option is needed so that the file is compiled without linking.
Other tools included in the binutils package are as follows:
For more detailed information about the GNU binutils, refer to www.gnu.org/software/binutils/.
2.3.4. Integrated Development Environment
In some instances, some applications are built using integrated development environments (IDEs). For those who need to use an IDE for C, C++, or Java, an open-source IDE called Eclipse is available. Eclipse is an open-extensible IDE that works well when developing applications. You can download it from www.eclipse.org/. Another open-source IDE for Java that works on Linux is NetBeans. You can download it from www.netbeans.org.