This is my homework. I’m looking for help on how to a make a “makefile” that will compile three source files. Of which will be named “timestable.c tablein.c tableout.c timestable.h”. Those are the four source files. I have created a makefile to do this, which I believe is correct, but I’m not sure how to test it to see if it will compile? Here is the content of my makefile:
timestable.exe: timestable.c tablein.c tableout.c timestable.h
cl timestable.c tablein.c tableout.c timestable.h
Is this correct? This makefile has to build a program called timestable.exe using the Visual Studio cl command and to provide the clean functionality. I don’t understand what I am being told when the teacher mentioned the “clean” functionality. I’m not sure if this makefile actually works to create this file, because I’m not sure how to run it.
Also, if you guys don’t mind giving me a link or telling me some more info on makefile commands for a windows based system. I wish to create and “extra feature” in my makefile because doing so will grant me better marks, and I do not know what more I could do.
Thanks ahead of time.
BIG EDIT:
So, after playing around a bit, I figured out that if I change the makefile.txt file to makefile.bat and I open my visual studio cmd prompt, get into the correct directory and type in (I’m aware I do not have to run the cmd promt in order to run the .bat file) :
makefile.bat
it will attempt to compile all the files. The issue, is it does not work with the “.h” file, specifitcly the timestable.h file. Also, the “timestable.exe” command didn’t work. Any idea on what to do here?
(Incidentally, what happens if you run
cl timestable.c tablein.c tableout.c timestable.hby hand?)You’d normally want to write your
Makefileto compile your.cfiles to.objfiles using pattern rules that know how to compile a single.cfile into an.objfile and then another rule that knows how to link all the.objfiles into a single executable object. (One important benefit is that this allows rebuilding only the parts that have changed. YourMakefileso far will require recompiling all inputs file any time any one changes.)When you have so many
.objfiles laying around, you might want amake cleanthat removes all the object files and executable files that can be rebuilt from sources. That might be as simple as declaringcleanto be a phony target and then deleting all the files that can be rebuilt.Note that Makefiles are by convention named
MakefileormakefileorGNUmakefile. (GNUmakeactually searches for the files in the reverse order to this list, butMakefileis the only name I like.) If you use one of these names, then you can just runmake footo run thefootarget. If you pick a different name for your Makefile then you also need to use the-f filenamecommand line option to pick the other file, and that is annoying. Sometimes necessary.)