# Simple Makefile. # # Does not use any macros or anything fancy, just to show the basics of # a Makefile. The file Makefile.Macros has a few macros that would # be typical. ################################################################## # This is a target for a one-file C program, which will use the # defualt binary name a.out. myMainSimple: mainSimple.o cc mainSimple.c ################################################################## # This builds the program myMain. Its main program is in main.c, # but it has functions called from main() in func1.c and func2.c. # Note that, because we are not using macros, we have to type in the # list of .o files twice (and more later) myMain: main.o func1.o func2.o cc -o myMain main.o func1.o func2.o ################################################################## # Here is another rule to try to make the program named myMainOops". # It is just copied from the rule above except it does not include func2.o. # Thus, any symbol defined in func2.o won't be available for the binary # program, and the linker should have an error. myMainOops: main.o func1.o echo "Expect a linker error here...." cc -o myMain main.o func1.o echo "See, what did I (not) tell you?!" ################################################################## # This tells make to rebuild main.o (and func1 and func2) if defs.h # is newer than main.o. By its default rule for the C compler, it knows # that if there is a file "main.c" then "main.o" depends on it. # # Note that usually these definitions will be generated by an external # tool for you, one that looks at the files and sees the dependencies. main.o: defs.h func1.o: defs.h func2.o: defs.h ################################################################## clean: rm -f *.o vclean: rm -f *.o myMain myMainSimple myMainOops