Thursday 15 April 2010

Ant and Make

Both are "builder" of application.

In instance, Make is used by perl, C, ...

To run it : make Makefile
The makefile contain : the target:dependency:script to run

example:

in C, there are file.C and headerfile.h. file.c is source code. headerfile.h is like library in which there are main function,variable that can be used among the file.c (ex. include stdio.h)

in C, you compile and then linking :
gcc -c thesourcecode then gcc -o theresultprevcommandANDsomelib

in C, when you have (at same folder):
file1.c and header1.h
file2.c and header2.h

to compile : gcc -Wall -ansi -o theprogram code1.c code2.c
Note: see @ bottom page, if you are confused why no need out headerfile.h at above command!!


You'll compile it like this if you dont want to compile all-in-once, example if you just modify one of the file, you dont need to compile all files :

gcc -c file1.c ==> resulting file1.o = a machine code file
gcc -c file2.c
gcc -o theprogram file1.o file2.o

Here are example makefile content:

''''''''''''''''''''''''''''
default: theprogram

code1.o: code1.c header1.h
gcc -Wall -ansi -c code1.c

code2.o: code2.c header2.h
gcc -Wall -ansi -c code2.c

prog: code1.o code2.o
gcc -Wall -ansi -o theprogram code1.o code2.o

clean:
rm code1.o code2.o

cleanall: clean
rm prog
'''''''''''''''''''''''''''''''

target : dependency
script to run

Note: if too long in a row use "\" as splitter.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

step beginning : make makefile
will execute the make default, which dependens on theprogram,
so theprogram is run, but dependens on code1.o and code2.o,
so the code1.o and code2.o will be run, the script to get the codeX.c, the dependency.


step final: make clean
to remove the machine code files.


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

in perl, as i remember:

make ==> to prepare the environment
make test ==> to test if any dependency failed
make makefile ==> run the instalation
make clean ==> cleanup some junk during instalation

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Ant, is java-based tool, can be use in vary programming, including replacing Make,
it is more advance with more feature.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Excerpt from http://www.unix.com/programming/47881-help-compiling-header-files-c-file-using-gcc.html

There are two basic ways to compile header files in C:

AAA

If the headers are in the same location as the source you include them like this:
Code:
#include "myheader.h"

if they are standard headers then inlude like this:
Code:
#include


then compile with
Code:
gcc -o myoutputfile myoutputfile.c

BBB

If the headers are located in some other (non-standard) location you would include like standard headers:

Code:

#include
and then use the -I (uppercase i ) flag to include the directory containing them.

Code:
gcc -I/path/to/directory/containing/header_name -o myoutputfile myoutputfile.c

or leave them quoted and use on of:
Code:
gcc -iquote /path/to/directory/containing/header_name -o myoutputfile myoutputfile.c

or
Code:
gcc -include /path/to/directory/containing/header_name/header_name.h -o myoutputfile myoutputfile.c

No comments:

Post a Comment