Click to See Complete Forum and Search --> : Makefile in Linux
kumark
07-31-2001, 05:03 AM
Hi there !
I have little knowledge in 'C'and have done some programming in 'C' in DOS envirnment. What I don't understand is why Makefile is used while compiling source code 'make' command is used. I discussed this with my friends who run computer institute teaching C/C++ but they are not aware of this concept.
I have seen few of the Makefiles but could not understand. Please explain me what is this Makefile and how to make it.
I don't know if I am asking the right question but please try.
Thanks
Thanks.
make is a tool used for building large projects. The main concepts in a makefile are targets and dependencies... targets are the individual things which need to be built; dependencies are the things those targets depend on (they must exist before the target can be built).
A target - dependency line looks like this: (for example)
program.exe: program.o helper.o
then, somewhere else, you would see a line that said
program.o: program.c, program.h
(or something similar)..
The makefile sees that program.o must exist before program.exe can, so it goes and finds that... then it sees that program.c exists before it can make program.o
Now, after a target - dependency line comes one or more 'rules' lines.. these are simply the commands to be executed to make the given target. These lines are always tab-indented. That is part of the format of a makefile.
So, A very simple makefile might look like this:
program: prog.c
gcc -o my_program prog.c
This would suffice if your entire program was contained in the source file prog.c
Makefiles also allow you to use macros, which are great if you know what you're doing and you have a large project. Macros also make them pretty difficult for newbies to read.
For complete in-depth info on makefiles, type 'info make' at the command line.
Btw, makefiles exist in DOS, too. In fact, many IDE's either have makefiles as the underlying project structure or allow users to use makefiles.. I've used makefiles with visual studio, for example.
TacKat
07-31-2001, 09:55 AM
A DOS make file is most often a *.bat. Modern IDE interfaces hide the make process to a certain degree, but it's still there.
you can use batch files as make files, of course, you can use shell scripts as makefiles, too. There are version of make (one called PolyMake, and probably gnu make through Cygwin) for dos.
Niminator
08-02-2001, 06:37 AM
There is a lot to make files; If you set one up to compile your program, it will do things like check date stamps and only compile code that shows as newer than the last time that program was compiled, and if you set up the dependencies properly, it will create the files it needs as it goes. You can also use it to just run some random command, if you want to, like this;
bob:
who | grep bob
If I had this entry in a makefile, I could type "make bob" to execute the command who | grep bob, to check and see if my friend bob is logged in. :cool: