Thursday, October 11, 2012

Compiling software from source

Ex no: 11                       Compiling software from source
Aim:
To learn about the common build systems available in Linux and to use them.

Introduction:

Open source software is distributed in source code form. In case of popular software
Linux distributions will often have the software packaged in their repositories. If the package is
not package is not in the repository the user has to compile the software from source. To do this
the user has to understand about the build system used in the project.

The GNU build system, also known as the Autotools, is a suite of programming tools
designed to assist in making source-code packages portable to many Unix-like systems. It can
be difficult to make a software program portable: the C compiler differs from system to system;
certain library functions are missing on some systems; header files may have different names.
One way to handle this is write conditional code, with code blocks selected by means of
preprocessor directives (#ifdef); but because of the wide variety of build environments this
approach quickly becomes unmanageable. The GNU build system is designed to address this
problem more manageably.

Tools included in the GNU build system

The GNU build system comprises the GNU utility programs Autoconf, Automake, and Libtool.
Other related tools frequently used with the GNU build system are GNU's make program, GNU
gettext, pkg-config, and the GNU Compiler Collection, also called GCC.

GNU Autoconf

Autoconf generates a configure script based on the contents of a configure.ac file which
characterizes a particular body of source code. The configure script, when run, scans the build
environment and generates a subordinate config.statusscript which, in turn, converts other input
files and most commonly Makefile.in into output files (Makefile) which are appropriate for that
build environment. Finally the make program uses Makefile to generate executable programs
from source code.
The complexity of the GNU build system reflects the variety of circumstances under which a
body of source code may be built.
If a source code file is changed then it suffices to re-run make which only recompiles
that part of the body of the source code affected by the change.
● If a .in file has changed then it suffices to re-run config.status and make.
● If the body of source code is copied to another computer then it is suffices to rerun
configure (which runs config.status) and make. (For this reason source code
using the GNU build system is normally distributed without the files thatconfigure
generates.)
● If the body of source code is changed more fundamentally then configure.ac and
the .in files need to be changed and all subsequent steps also followed.
To process files, autoconf uses the GNU implementation of the m4 macro system.
Autoconf comes with several auxiliary programs such as Autoheader, which is used to help
manage C header files; Autoscan, which can create an initial input file for Autoconf; and
ifnames, which can list C pre-processor identifiers used in the program.

GNU Automake

Automake helps to create portable Makefiles, which are in turn processed with the make utility.
It takes its input as Makefile.am, and turns it into Makefile.in, which is used by the configure
script to generate the file Makefile output.

GNU Libtool
Libtool helps manage the creation of static and dynamic libraries on various Unix-like operating
systems. Libtool accomplishes this by abstracting the library-creation process, hiding
differences between various systems (e.g. GNU/Linuxsystems vs. Solaris).

Gnulib
Gnulib simplifies the process of making software that uses Autoconf and Automake portable to awide range of systems.

Make
In software development, make is a utility that automatically builds executable programs andlibraries from source code by reading files called makefiles which specify how to derive thetarget program. Make can decide where to start through topological sorting. Though integrateddevelopment environments and language-specific compiler features can also be used tomanage the build process in modern systems, make remains widely used, especially in Unix.Make is typically used to build executable programs and libraries from source code. Generallythough, any process that involves transforming a dependency file to a target result (by executingsome number of arbitrary commands) is applicable to make. To cite an example, make could beused to detect a change made to an image file (the dependency) and the target actions thatresult might be to convert the file to some specific format, copy the result into a content management system, and then send e-mail to a predefined set of users that the above actions
were performed.

\


Commands:
[root@localhost student]# mkdir gnumake1
[root@localhost student]# cd gnumake1
[root@localhost gnumake1]# vi squareroot.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
if (argc < 2)
            {
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",inputValue, outputValue);
return 0;
}
[root@localhost gnumake1]# cc squareroot.c -o squareroot -lm
[root@localhost gnumake1]# ./squareroot 3
The square root of 3 is 1.73205
[root@localhost gnumake1]# ./squareroot 36
The square root of 36 is 6
[root@localhost gnumake1]# make clean
rm -f squareroot squareroot.o
[root@localhost gnumake1]# make
gcc -g   -c -o squareroot.o squareroot.c
gcc -lm  squareroot.o   -o squareroot
[root@localhost gnumake1]# ./squareroot 64
The square root of 64 is 8
[root@localhost gnumake1]# cd ..
[root@localhost student]# cd cmake
[root@localhost cmake]# cp ../gnumake1/squareroot.c .
[root@localhost cmake]# vi CMakeLists.txt
[root@localhost cmake]# mkdir build
[root@localhost cmake]# cd build
[root@localhost build]# ls
[root@localhost build]# cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/lib/ccache/gcc
-- Check for working C compiler: /usr/lib/ccache/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/ccache/c++
-- Check for working CXX compiler: /usr/lib/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/student/cmake/build
[root@localhost build]# ls
CMakeCache.txt  CMakeFiles  cmake_install.cmake  Makefile
[root@localhost build]# make
Scanning dependencies of target squareroot
[100%] Building C object CMakeFiles/squareroot.dir/squareroot.c.o
Linking C executable squareroot
[100%] Built target squareroot
[root@localhost build]# ls
CMakeCache.txt  cmake_install.cmake  squareroot
CMakeFiles      Makefile
[root@localhost build]# ./squareroot 64
The square root of 64 is 8
[student@localhost ~]$ su
Password:
[root@localhost student]# yum install java-1.6.0-openjdk-devel
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
Setting up Install Process
Package 1:java-1.6.0-openjdk-devel-1.6.0.0-55.1.9.10.fc14.i686 already installed and latest version
Nothing to do
[root@localhost student]# yum install ant
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
Setting up Install Process
Package ant-1.7.1-13.fc13.i686 already installed and latest version
othing to do
[root@localhost student]# cd ../../
[root@localhost /]# mkdir ant
[root@localhost /]# mkdir -p src/hello
[root@localhost /]# vi src/hello/HelloWorld.java
package hello;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
[root@localhost /]# mkdir -p build/classes
[root@localhost /]# javac -sourcepath src -d build/classes/ src/hello/HelloWorld.java
[root@localhost /]# java -cp build/classes hello.HelloWorld
Hello World
[root@localhost /]# vi build.xml
<project>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar"
basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="hello.HelloWorld"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>
</project>
[root@localhost /]# ant clean
Buildfile: build.xml
clean:
   [delete] Deleting directory /build
BUILD SUCCESSFUL
Total time: 0 seconds
[root@localhost /]# ant compile jar run
Buildfile: build.xml
compile:
    [mkdir] Created dir: /build/classes
    [javac] Compiling 1 source file to /build/classes
jar:
    [mkdir] Created dir: /build/jar
     [jar] Building jar: /build/jar/HelloWorld.jar
run:
     [java] Hello World
BUILD SUCCESSFUL
Total time: 0 seconds
[root@localhost /]#

Output:





Result:
            Thus the software was compiled from source packages.





--
Hackerx Sasi
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.

But When you give up,
You lose !
I DONT GIVE UP.....!!!


In three words I can sum up everything I've learned about life - it goes on......
with regards
prem sasi kumar arivukalanjiam

No comments:

Post a Comment

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (88) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (12) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) pdf (1) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin