User Tools

Site Tools


software_carpentary2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software_carpentary2 [2011/06/20 04:01]
medhamsh
software_carpentary2 [2018/03/24 11:13] (current)
Line 1: Line 1:
 +=== Additional Exercises ===
 +
 +0) Create a simple project with three files: file1.c file2.c and main.c. Define func1() in file1.c and func2 in file2.c. Declare the func1() in file1.h and func2() in file2.h. Include file1.h and file2.h in main.c and call the two functions. Write a makefile for this project. Extra: Make changes in file1.h and file2.h in such a manner that including twice inside main.c will not give compilation errors.
 +
 +1) Download wget source code, compile and install it on the system
 +
 +2) Understand what configure, automake and autoconf are for
 +
 +3) Download and compile the linux kernel
 +
 +4) Understand phony targets inside a makefile
 +
 +5) Browse mozilla firefox source code using mxr.mozilla.org.
 + - Access search functions
 + - Browse for variables declarations and function declarations
 + - Browse for variable and function usages
 +
 +6) Download, read and understand the source of a small and simple free software project as much as possible for some time (such as wget).
 +
 +7) Read the GNU coding standards document and try to analyze the importance of each guideline there.
 +
 +Puzzle:
 +What does the following function do:
 +
 + 
 +  int what_do_i_do(int a)
 +  {
 + a = ((a & 0xAAAAAAAA) >> 1) + (a & 0x55555555);​
 + a = ((a & 0xCCCCCCCC) >> 2) + (a & 0x33333333);​
 + a = ((a & 0xF0F0F0F0) >> 4) + (a & 0x0F0F0F0F);​
 + a = ((a & 0xFF00FF00) >> 8) + (a & 0x00FF00FF);​
 + a = ((a & 0xFFFF0000) >> 16) + (a & 0x0000FFFF);​
 + return a;
 +  }
 +
 +
 +
 ====== Quality Assurance ====== ====== Quality Assurance ======
  
Line 210: Line 247:
 fclose(fp); fclose(fp);
 } }
 +</​code>​
 +
 +====== Make: Automated Builds ======
 +
 +The make utility
 +
 +If you run
 +
 +<​code>​
 +make
 +</​code>​
 +
 +this program will look for a file named makefile in your directory, and then execute it.
 +If you have several makefiles, then you can execute them with the command:
 +
 +<​code>​
 +make -f MyMakefile
 +</​code>​
 +
 +There are several other switches to the make utility. For more info, man make.
 +
 +===== Build Process =====
 +
 +
 +   1. Compiler takes the source files and outputs object files
 +   2. Linker takes the object files and creates an executable
 +
 +==== Compiling by hand ====
 +
 +
 +The trivial way to compile the files and obtain an executable, is by running the command:
 +<​code>​
 +g++ main.cpp hello.cpp factorial.cpp -o hello
 +</​code>​
 +
 +==== The basic Makefile ====
 +
 +
 +The basic makefile is composed of:
 +
 +<​code>​
 +target: dependencies
 +[tab] system command
 +</​code>​
 +
 +This syntax applied to our example would look like:
 +
 +<​code>​
 +all:
 + g++ main.cpp hello.cpp factorial.cpp -o hello
 +</​code>​
 +
 +==== Using variables and comments ====
 +
 +You can also use variables when writing Makefiles. It comes in handy in situations where you want to change the compiler, or the compiler options.
 +<​code>​
 +# I am a comment, and I want to say that the variable CC will be
 +# the compiler to use.
 +CC=g++
 +# Hey!, I am comment number 2. I want to say that CFLAGS will be the
 +# options I'll pass to the compiler.
 +CFLAGS=-c -Wall
 +
 +all: hello
 +
 +hello: main.o factorial.o hello.o
 + $(CC) main.o factorial.o hello.o -o hello
 +
 +main.o: main.cpp
 + $(CC) $(CFLAGS) main.cpp
 +
 +factorial.o:​ factorial.cpp
 + $(CC) $(CFLAGS) factorial.cpp
 +
 +hello.o: hello.cpp
 + $(CC) $(CFLAGS) hello.cpp
 +
 +clean:
 + rm -rf *o hello
 </​code>​ </​code>​
software_carpentary2.1308542495.txt.gz ยท Last modified: 2018/03/24 11:13 (external edit)