Here is a simple Tutorial of Make:
source file (helloworld.c)
========
#include ...
using namespace std;
cout<<"hello world\n"; return 0;
}
simple makefile(gnumakefile/makefile)
===========
helloworld: helloworld.c
command
=======
make TARGET
make helloworld
Example 2
========
/* sum.c */
int sum(int a, int b) {
return a+b;
}
/* diff.c */
int diff(int a, int b) {
return a-b;
}
/* main.c */
int main() {
...
c=sum(20,30);
...
d=diff(30,23);
...
}
/* Make file */
CC = g++ /* which compiler*/
CFLAGS = -Wall -g -ansi /* compiler flags */
sum.o: sum.c
$(CC) $(CFLAGS) -c -o $@ $<
diff.o: diff.c
$(CC) $(CFLAGS) -c -o $@ $<
main: sum.o diff.o main.c
$(CC) $(CFLAGS) -o $@ $^
clean:
-rm core *.o main
Special Tags
=========
$@ -- current target name
$LT -- First name of the prerequisite
$^ -- List of all prerequisite
$* -- List of all prerequisite (without prefix)
So, dudes, start using make. It is cool, it makes life a lot easier for c/c++ programmers.
No comments:
Post a Comment