c hacer archivos, ¿cómo hacer uno que compile cuatro archivos fuente?

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 limpiar functionality. I don't understand what I am being told when the teacher mentioned the "limpiar" 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.

Gracias de antemano.

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?

preguntado el 01 de febrero de 12 a las 03:02

2 Respuestas

(Incidentally, what happens if you run cl timestable.c tablein.c tableout.c timestable.h by hand?)

You'd normally want to write your Makefile para compilar tu .c a archivos .obj archivos usando reglas de patrón that know how to compile a single .c archivar en un .obj file and then another rule that knows how to link all the .obj files into a single executable object. (One important benefit is that this allows rebuilding only the parts that have changed. Your Makefile so far will require recompiling all inputs file any time any one changes.)

Cuando tienes tantos .obj files laying around, you might want a make clean that removes all the object files and executable files that can be rebuilt from sources. That might be as simple as declaring clean to be a phony target and then deleting all the files that can be rebuilt.

Note that Makefiles are by convention named Makefile or makefile or GNUmakefile. (GNU make actually searches for the files in the orden inverso to this list, but Makefile is the only name I like.) If you use one of these names, then you can just run make foo ejecutar el foo target. If you pick a different name for your Makefile then you also need to use the -f filename command line option to pick the other file, and y eso is annoying. Sometimes necessary.)

Respondido 01 Feb 12, 07:02

Thanks for all the information, but I am a little bit confused. How can I run this make file to see if it works? Through the command prompt? Also, that clean you were talking about got me lost. Right now my makefile is a "makefile.txt" file sitting in the same spot as my other four source files. Do I change makefile.txt to something else? sorry. - Robolisk

The only real difference with the fundamentals described your answer is that object files conventionally have the obj extension, rather than o. - Cody Grey

Considering that note, my makefile should just be "makefile" not "makefile.txt" ? And to run it I just open the visual studio cmd prompt and get into the same directory as this makefile, and run the makefile to create timestable.exe? - Robolisk

Sí, makefile is an acceptable name. You could use cmd.exe, or Cygwin's bash, or probably the visual studio command prompt -- though I don't know how that is implemented. - sarnold

So how do I run makefile in the command prompt? just "makefile timestable.exe" ? - Robolisk

Surely your teacher/school provided some course notes, where the basics of make/nmake are explained, if they expect you to use it for your homework; or at the very least some pointers to online material?
You seem to be confused about what exactly a makefile is, and how you use it. You don't directly run it from the commandline like a batch script, but you need a program (called makeo nmake if you're using Visual Studio); the makefile is a sort of input script which is read by that program. The program then uses the info in the makefile to determine what commands it needs to run to update the main target.

You should be able to find some tutorials that describe the basics of make much better than I can do here. A quick search on Google for make tutorial came up with this link: http://www.eng.hawaii.edu/Tutor/Make/ . I glanced through it and it seems like a nice introduction (it uses pictures and short sections, so it must be good, right? ;) ).

Respondido 01 Feb 12, 17:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.