Compiling from source code

Slides:



Advertisements
Similar presentations
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Advertisements

Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
1 CS 201 Makefile Debzani Deb. 2 Remember this? 3 What is a Makefile? A Makefile is a collection of instructions that is used to compile your program.
Add a New System Call to Linux. Hw1 Add a New System Call to Linux and Compile Kernel Add a New System Call to Linux by Kernel Module.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
09/21/081 Ho Chi Minh city University of Technology Linux kernel R.M. Introduction of building Linux kernel from source.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Lecture 2 Linux Basic Commands,Shell and Make September 8, 2015 Kyu Ho Park.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Linux development Lection What we gonna do today Root privileges Software packages Managing software packages Build procedures Build components.
Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Installing Applications in FreeBSD lctseng. Computer Center, CS, NCTU 2 Before we start  Permission issue root: the super user Like administrator in.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
ECE 544 Software Project 1 Kuo-Chun Huang (KC). Environment Linux (Ubuntu or others) Windows with Cygwin
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
OpenMoko Shakthi Kannan October 2007
Multiple file project management & Makefile
Add a New System Call to Linux
The make utility (original presentation courtesy of Alark Joshi)
Lecture 2 Linux Basic Commands,Shell and Make
Operating System Kernel Compilation
Outline Installing Gem5 SPEC2006 for Gem5 Configuring Gem5.
How to Program.
How to Start Programming in Linux Environment
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
OS Homework 1 February 22, 2017.
Brief Intro to Make CST494/ Gannod.
Makefiles.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
linux and related thing
Compiling from source code
The Preprocessor Based on Chapter 1 in C++ for Java Programmers by Weiss When a C compiler is invoked, the first thing that happens is that the code is.
Larger Projects, Object Files, Prototyping, Header Files, Make Files
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Operating System Kernel Compilation
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Data Structures and Programming Techniques
Creating your first C program
Header files.
CMPSC 60: Week 4 Discussion
Kyle Fitzpatrick Konstantin Zak 11/29/2004
SCMP Software Development Spring 2018 James Skon
Palm Application Development & GUI Programming
Preparation for Assignment 2
Homework K&R chapter 4.
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
Operating System Kernel Compilation
Compile and run c files.
SCMP Software Development Spring 2018 James Skon
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Compiling from source code Make a pgm using make*

make* Makefiles are a simple way to organize code compilation. A Simple Example start off with the following three files, 1) hellomake.c 2) hellofunc.c 3) hellomake.h

hellomake.c #include <hellomake.h> int main() { // call a function in another file myPrintHelloMake(); return(0); }

hellofunc.c #include <stdio.h> #include <hellomake.h> void myPrintHelloMake(void) { printf("Hello makefiles!\n"); return; }

hellomake.h /* example include file */ void myPrintHelloMake(void);

compiling Normally, you would compile this collection of code by executing the following command: $ gcc -o hellomake hellomake.c hellofunc.c -I. Create an o/p hellomake The -I. is Included so that gcc will look in the current directory (.) for the include file hellomake.h.

Imp. Of Makefile Without a makefile, the typical approach to the test/modify/debug cycle is to use the up arrow in a terminal to go back to your last compile command, so you don't have to type it each time, especially once you've added a few more .c files to the mix. Unfortunately, this approach to compilation has two downfalls.

Disadvantage of CLI manual 1) if you lose the compile command or switch computers you have to retype it from scratch, which is inefficient at best. 2) if you are only making changes to one .c file, recompiling all of them every time is also time- consuming and inefficient. So, it's time to see what we can do with a makefile.

Makefile / makefile - 1 The simplest makefile you could create would look something like: $vi Makefile hellomake: hellomake.c hellofunc.c // dependency list gcc -o hellomake hellomake.c hellofunc.c -I. $ make

Make* Hellomake: // rule make* with no arguments executes the first rule (hellomake:) in the file. VIMP: tab before the gcc command in the makefile knows that the rule hellomake: needs to be executed if any of those files change.

Makefile - 2 CC=gcc CFLAGS=-I. hellomake: hellomake.o hellofunc.o $(CC) -o hellomake hellomake.o hellofunc.o -I.

Constants we've defined some constants CC and CFLAGS. These are special constants that communicate to make* how we want to compile the files hellomake.c and hellofunc.c CC=gcc // must to use C compiler CFLAGS =-I. // list of flags to pass to the compilation command.

Explanation By putting the object files--hellomake.o and hellofunc.o--in the dependency list and in the rule, make* knows it must first compile the .c versions individually, and then build the executable hellomake. this form of makefile is sufficient for most small scale projects. there is one thing missing:

Makefile impr.. If you were to make a change to hellomake.h, for example, make* would not recompile the .c files, to fix this, we need to tell make that all .c files depend on certain .h files. We can do this by writing a simple rule and adding it to the makefile.

Makefile - 3 CC=gcc CFLAGS=-I. DEPS = hellomake.h %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) hellomake: hellomake.o hellofunc.o gcc -o hellomake hellomake.o hellofunc.o -I.

Explanation macro DEPS, which is the set of .h files on which the .c files depend. rule that applies to all files ending in the .o %.o: %.c $(DEPS) rule says that the .o file depends upon the .c version of the file and the .h files included in the DEPS macro.

Explanation $(CC) -c -o $@ $< $(CFLAGS) rule then says that to generate the .o file, make* needs to compile the .c file using the compiler defined in the CC macro. -c flag says to create/generate the object file, -o $@ says to put the output of the compilation in the file named on the left side of the (:) $< is the first item in the dependencies list, and the CFLAGS macro is defined as above.

Eg:1 For example, consider the following declaration: eg :- all: library.cpp main.cpp In this case: $@ evaluates to all $< evaluates to library.cpp $^ evaluates to library.cpp main.cpp

Eg 2 hello.o: hello.c hello.h gcc -c $< -o $@ Here, hello.o is the output file. This is what $@ exapnds to. The first dependency is hello.c. That's what $< expands to.

Makefile 4 CC=gcc CFLAGS=-I. DEPS = hellomake.h OBJ = hellomake.o hellofunc.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) hellomake: $(OBJ) gcc -o $@ $^ $(CFLAGS)

Explain $@ and $^, which are the left and right sides of the :, hellomake: $(OBJ) gcc -o $@ $^ $(CFLAGS) $@ - o/p must be hellomake (left side) $^ - take all obj files at the right side

IDIR =../include //.h files in an include directory CC=gcc CFLAGS=-I$(IDIR) // dot changes in to .../include dir ODIR=obj // object dir LDIR =../lib // library LIBS=-lm // library modules in os - /etc/ld.so.conf /cache // ldd command // ldconfig - v// _DEPS = hellomake.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ = hellomake.o hellofunc.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) $(ODIR)/%.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) hellomake: $(OBJ) gcc -o $@ $^ $(CFLAGS) $(LIBS) .PHONY: clean clean: rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~

Install a software from src Pidgin – download src from web Check the dependencies apt-get build-dep pidgin Install the dependencies tar -xvf pidgin.tar.gz Cd pidgin Make Make install make uninstall

Kernel compilation apt-get source linux-image-$(uname -r) Tar -xvf linux-image-ver Sudo apt-get install kernel-package Sudo apt-get build-dep linux-image-$(uname -r) For graphical config Sudo apt-get install qt3-dev-tools libqt3-mt-dev Make menuconfig Fakeroot make-kpkg -j N –initrd – append-to- version=my-very-own-keernel kernel-image kernel- headers N = no. Of jobs to run in parallel(cpu based)