This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
software_carpentary2 [2011/06/20 04:17] medhamsh |
software_carpentary2 [2011/06/20 04:23] medhamsh |
||
---|---|---|---|
Line 260: | Line 260: | ||
all: | all: | ||
g++ main.cpp hello.cpp factorial.cpp -o hello | 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> |