This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:projects:make [2010/02/19 21:44] – oppenheim | notes:projects:make [2010/02/19 22:18] (current) – oppenheim | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~NOTOC~~ | ||
+ | =====make===== | ||
+ | click on a topic in the concept map | ||
+ | {{map>: | ||
+ | [[.make#the story|the story @ 121, | ||
+ | [[.make# | ||
+ | [[.make# | ||
+ | [[.make# | ||
+ | {{<map}} | ||
+ | |||
+ | ====the story==== | ||
+ | ====grammar==== | ||
+ | ====non-traditional uses==== | ||
+ | ====learning ==== | ||
+ | ok makefiles, to start comments are "#", | ||
+ | |||
+ | < | ||
+ | gcc main.c file1.c file2.c -o hello | ||
+ | </ | ||
+ | |||
+ | is what you normaly would run to complile a program with the gcc compiler and the 3 .c file to an executable called hello. | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # Makefile for hello | ||
+ | # | ||
+ | # compiler: gcc | ||
+ | # to compile type " | ||
+ | # | ||
+ | all : | ||
+ | gcc main.c file1.c file2.c -o hello | ||
+ | </ | ||
+ | |||
+ | this file is saved with the name " | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # Makefile for hello | ||
+ | # | ||
+ | # compiler: gcc | ||
+ | # to compile type " | ||
+ | # | ||
+ | all : hello | ||
+ | |||
+ | hello : main.o file1.o file2.o | ||
+ | gcc main.o file1.o file2.o -o hello | ||
+ | | ||
+ | main.o : main.c | ||
+ | echo main.c is being compiled | ||
+ | gcc -c main.c | ||
+ | |||
+ | file1.o : file1.c | ||
+ | echo file1.c is being compiled | ||
+ | gcc -c file1.c | ||
+ | |||
+ | file2.o : file2.c | ||
+ | echo file2.c is being compiled | ||
+ | gcc -c file2.c | ||
+ | |||
+ | clean : | ||
+ | rm -rf *.o hello | ||
+ | </ | ||
+ | |||
+ | this example builds alittle on what was there before. last time if there was a change to one of the files everything was recompiled. breaking everything up as shown here if only file2.c was modified on file2 would be recompiled. the clean: removes any left over executables and object files that are left over. i've also thrown in some simple echos to show that shell commands can be used as well. | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # Makefile for hello | ||
+ | # | ||
+ | # compiler: gcc | ||
+ | # to compile type " | ||
+ | # | ||
+ | |||
+ | CC = gcc | ||
+ | CFLAGS = -c | ||
+ | OBJ = main.o file1.o file2.o | ||
+ | |||
+ | all : hello | ||
+ | |||
+ | hello : $(OBJ) | ||
+ | $(CC) $(OBJ) -o hello | ||
+ | | ||
+ | main.o : main.c | ||
+ | echo main.c is being compiled | ||
+ | $(CC) $(CFLAGS) main.c | ||
+ | |||
+ | file1.o : file1.c | ||
+ | echo file1.c is being compiled | ||
+ | $(CC) $(CFLAGS) main.c | ||
+ | |||
+ | file2.o : file2.c | ||
+ | echo file2.c is being compiled | ||
+ | $(CC) $(CFLAGS) file2.c | ||
+ | |||
+ | clean : | ||
+ | rm -rf *.o hello | ||
+ | |||
+ | </ | ||
+ | in this extension of the makefile i added variables for everything that repeated throughout the file so that if i wanted to change lets say the compiler all i would have to do is change the CC value at the top. | ||
+ | |||
+ | |||
+ | [[http:// | ||
+ | |||
+ | **NOTE: this documentation is located in two places** [[: | ||
+ | |||
+ | if you add to this one please add to the other one as well. | ||
+ | |||
+ | |||
+ | |||