Unit III

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

GNU Assembler (GAS)

The GNU assembler as is primarily intended to assemble the output of


the GNU C compiler for use by the linker. However, it may be called as
a standalone program, and the GNU team tried to make as assemble
everything correctly that other assemblers for the same machine
would assemble. Any exceptions are documented explicitly. This
doesn't mean as always uses the same syntax as other assemblers for
the same architecture; for example, there exist several incompatible
versions of the assembly language syntax, so the syntax used in the
GNU assembler is not exactly the same as in some other assemblers.

The GNU Assembler, commonly known as GAS (even though the


program itself is as), is the assembler used by the GNU Project. It is
the default back-end of GCC. It is used to assemble the GNU operating
system and the Linux kernel, and various other software. It is a part of
the GNU Binutils package.

GAS' executable is named after as, a Unix assembler. GAS is cross-


platform, and both runs on and assembles for a number of different
computer architectures. Released under the GNU General Public
License v3, GAS is free software.

Understanding the build systems

From an end-user's perspective, it first describes how to build the


binary executable of a GNU free and open source software package
from the available source code and install it on your system. Then,
from a programmer's perspective it looks at the GNU Build System for
generating the scripts and makefiles which provide the infrastructure
that enables the end user to build and install the GNU software
executables.

AUTOCONF

One of the major objectives of GNU software packages is that the software may
be distributed as source code and it should possible to make the executable
under various Posix-like systems. Normally, it would be a gigantic task for each
programmer to write makefiles for each conceivable environment. autoconf
makes this a straightforward task. The input to autoconf is a text file named
configure.ac, or configure.in (configure.in is the older name).
autoconf produces configure, which is a shell script to to create makefile(s),
customized to build the software executables as per the local environment. The
input file, configure.ac, contains macros to check a system for features that
a software package might use. autoconf invokes the m4 macro processor to
generate the configure script.

Some of the important autoconf macros are AC_INIT, AC_OUTPUT,


AC_PROG_CC, AC_PROG_INSTALL, AC_CONFIG_SRCDIR,
AC_CONFIG_HEADERS, AC_CONFIG_FILES, etc. Some of the macros accept
arguments. When a macro takes arguments, there should not be any whitespace
between macro name and the open parenthesis. The arguments should be
enclosed in m4 quote characters [ and ] and should be separated by commas. If
an argument can not be a macro call, the quotes may be omitted. We can write
these in our configure.ac file,

AC_INIT[hello],[1.0])
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS(config.h)
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_PROG_INSTALL
AC_OUTPUT

Each configure.ac must start with an AC_INIT. The parameters, here, are
the package name hello and version, 1.0. AC_CONFIG_HEADERS ensures that
–D(definitions) options to the compiler are not passed on the commandline.
A file config.h would be created, containing all the #defines that were being
passed as header files. AC_CONFIG_SRCDIR makes autoconf check for
the presence of given file, in this case hello.c. AC_PROG_CC determines the C
compiler to use. AC_CONFIG_FILES makes AC_OUTPUT create the given files.
AC_PROG_INSTALL checks for the presence of BSD compatible install
program in the current path. If it is found, its path is set to output variable
INSTALL. The last call in configure.ac is AC_OUTPUT. It performs all the
configuration actions, which includes writing all output files.
Constructing make files

The make utility automatically determines which pieces of a large


program need to be recompiled, and issues commands to recompile
them.

You can use make with any programming language whose compiler
can be run with a shell command. Indeed, make is not limited to
programs. You can use it to describe any task where some files must
be updated automatically from others whenever the others change.

Preparing and Running Make

You need a file called a makefile to tell make what to do. Most often,
the makefile tells make how to compile and link a program. To prepare
to use make, you must write a file called the makefile that describes
the relationships among files in your program and provides commands
for updating each file. In a program, typically, the executable file is
updated from object files, which are in turn made by compiling source
files.

Once a suitable makefile exists, each time you change some source
files, this simple shell command:

make

Suffices to perform all necessary recompilations. The make program


uses the makefile data base and the last-modification times of the files
to decide which of the files need to be updated.

When make recompiles the editor, each changed C source file must be
recompiled. If a header file has changed, each C source file that
includes the header file must be recompiled to be safe. Each
compilation produces an object file corresponding to the source file.
Finally, if any source file has been recompiled, all the object files,
whether newly made or saved from previous compilations, must be
linked together to produce the new executable editor.

You might also like