Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, March 24, 2012

Simple GNU Make File


GNU Make contains many default rules, referred to as implicit rules, to simplify the construction of makefiles. For example, these specify that ‘.o’ files can be obtained from ‘.c’ files by compilation, and that an executable can be made by linking together ‘.o’ files. Implicit rules are defined in terms of make variables, such as CC (the C compiler) and CFLAGS (the compilation options for C programs), which can be set using VARIABLE=VALUE lines in the makefile.

A simple ‘Makefile’ for the project above can be written as follows:

CC=gcc
CFLAGS=-Wall
main: main.o hai.o hello.o
clean:
rm -f main main.o hello.o hai.o


The meaning of make file is like :
1) Using the C compiler gcc, with compilation option -Wall,
2)Build the target executable main from the object files ‘main.o’ ,‘hello.o and’hai.o'
3)These, in turn, will be built from ‘main.c’ ,'hai.c'and ‘hello.c’.
4)The target clean has no dependencies and simply removes all the compiled files.
The option -f (force) on the rm command suppresses any error messages if the files do not exist.
To use the makefile, simply type make.
 When called with no arguments, the first target in the makefile is built, producing the executable ‘main’:
To remove the generated files, type make clean:

Another example of make file:

CC = gcc
CFLAGS = -g -W -Wall
OBJ = main.o hai.o hello.o
.c.o:
$(CC) $(CFLAGS) $<

all: $(OBJ)

clean:

rm -f *.o

Wednesday, March 21, 2012

Linux Makefile

COPY FROM: http://forum.codecall.net ->linux-tutorials-guides-tips->17681-linux-makefile-tutorial
Introduction
The make program essentially is used to update targets (exe or object files) according to the dependency instructions, typically present in a file called makefile. The program automatically can link dependent modules and also decide which files are to be (re)compiled by looking at the object code timestamps. Essentially make allows the compilation process to be a breeze.

Makefile Description
The makefile contains all the dependency information required for compiling. The file is typically denoted as makefile or Makefile. This however can be overridden by specifying the file name with the -f switch. The instructions are written in single lines and interpreted accordingly. A backslash (\) can be used to signify continuation of the line.
The target is the final output that is required at the end of the make process. It typically is reliant on many other files to have compiled successfully. Target compilation are carried out by a series of actions called as command. Rule can be composed of multiple commands but each starting with a tab character.
Makefile has the feature of using variables, like in other programming languages. A variable is defined as:
variable_name = variable_definition
$(variable_name) is used to use its value.
Make software also has set of internal macros:
$+
List of all the defined dependencies, space separated, with duplicates
$^
List of all the defined dependencies, space separated, without duplicates
$@
Contains the name of the current target
$<
Current prerequisite modified later than the current target  ie..  the name of the related file that caused the action.
$* 
the prefix shared by target and dependent files. 
Make Options
The makefile typically has the contents are specified below:
Empty Lines
Lines with no text are ignored
#
Pound acts as a start of comments (single-line) indicator
Dependencies
targets: dependency; commands
Here the targets and their dependencies are specified. If the dependent files have not been created or a newer version of their source code exists, then the files are regenerated. These can be followed by one or more commands. If there are no dependencies then the commands are executed always.

Make Options
-f makefile
The specified makefile is used as the description file
-h
Print the help information
-i
Ignore any errors
-n
Prints the command that will be executed. For testing the flow of the compilation process.
-q
Returns 0 if the target file is up to date; non-zero if otherwise
-p
Prints out the variables and settings existing by default

Running Make
Now to put all the above options to use. We will build a descriptor file to build an exe called sampleexec. Also assume that it needs two source files src1.c and src2.c. To build a descriptor for this and save it in a file called makefile.

The makefile will look like this
Code:
     sampleexec : src1.o src2.o 
             gcc -o sampleexec src1.o src2.o
     src1.o : src1.c 
             gcc -c src1.c
     src2.o : src2.c 
             gcc -c src2.c

To compile just run:
Code:
# make
Steps make takes to compile sampleexec:

sees that sampleexec depends on the object files src1.o src2.o
looks for the target definition of the two object files.
sees that src1.o depends on the file src1.c
executes the commands given in src1.o's rule and compiles src1.c to get the object file.
similarly looks at the target src2.o and compiles the object files
prepares sampleexc by combining the two object files


Common implicit rule is for the construction of .o (object) files out of .cpp (source files):


.o.cpp:
        $(CC) $(CFLAGS) -c $<
alternatively
.o.cpp:
        $(CC) $(CFLAGS) -c $*.c




Friday, January 27, 2012

What Is Embedded Linux?


Embedded Linux typically refers to a complete system, or in the Linux vendor, to a distribution targeted at embedded devices.there is no special form of the Linux kernel targeted at embedded applications. Instead, the same Linux kernel source code is intended to be built for the widest range of devices, workstations,and servers imaginable, although obviously it is possible to configure a variety of op-tional features according to the intended use of the kernel. For example, it is unlikely that your embedded device will feature 128 processors and terrabytes of memory, and so it is possible to configure out support for certain features typically found only on larger Linux systems.

What Is Linux?


Linux was first released into an unsuspecting world in the summer of 1991.Linux refers only to an operating system kernel originally written by Linus Torvalds. The Linux kernel provides a variety of core system facilities required for any system based upon Linux to operate correctly. Application software relies upon specific features of the Linux kernel, such as its handling of hardware devices and its provision of a variety of fundamental abstractions, such as virtual memory, tasks (known to users as processes), sockets, files, and the like. The Linux kernel is typically started by a bootloader or system firmware.

 The term “Linux” has become somewhat overloaded in everyday commu-nication. In large part, this is due to its growing popularity—people might not know what an operating system kernel is or does, but they will have perhaps heard of the term Linux. In fact, Linux is often used interchangeably in reference to the Linux kernel itself, a Linux system, or an entire prebuilt (or source) software distribution built upon the Linux kernel and related software. Such widely varying usage can lead to difficulties when providing technical explanations. For example, if you were to say, “Linux pro-vides TCP/IP networking,” do you mean the TCP/IP stack implementation in the Linux kernel itself, or the TCP/IP utilities provided by a Linux distribution using the Linux kernel, or all of the above?

The broadness of the usage of the term has led to calls for a greater distinction between uses of the term “Linux.” For example, Richard Stallman and the Free Software Foun-dation often prefix “GNU/” (as in “GNU/Linux”) in order to refer to a complete system running a Linux kernel and a wide variety of GNU software. But even terms such as these can be misleading—it’s theoretically possible to build a complete Linux-based system without GNU software (albeit with great difficulty), and most practical Linux systems make use of a variety of both GNU and non-GNU software.

Despite the con-fusion, as more people continue to hear of Linux, the trend is toward a generalization of the term as a reference to a complete system or distribution, running both GNU and non-GNU software on a Linux kernel.  The most famous desktop linux distributions are  Red Hat Enterprise Linux (RHEL), SuSE Linux Enterprise Server (SLES), Ubuntu Linux, or Debian GNU/Linux.And all of these provide the user with a pre-packaged, shrinkwrapped set of files and an installation procedure to get the kernel and various overlaid software installed on a certain type of hardware for a certain pur-pose.

Linux


I am not posting my own work here ,most of the contents about linux taken from Building Embedded Linux Systems by
 Karim Yaghmour, Jon Masters, Gilad Ben-Yossef, and  Philippe Gerum

Followers