tags:

views:

111

answers:

3

I downloaded a set of source code for a program in a book and I got a makefile. I am quite new to Linux, and I want to know whether there is any way I can see the actual source code written in C?

Or what exactly am I to do with it?

+1  A: 

A Makefile does not contain any source itself. It is simply a list of instructions in a special format which specifies what commands should be run, and in what order, to build your program. If you want to see where the source is, your Makefile will likely contain many "filename.c"'s and "filename.h"'s. You can use grep to find all the instances of ".c" and ".h" in the file, which should correspond to the C source and header files in the project. The following command should do the trick:

grep -e '\.[ch]' Makefile

To use the Makefile to build your project, simply typing make should do something reasonable. If that doesn't do what you want, look for unindented lines ending in a colon; these are target names, and represent different arguments you can specify after "make" to build a particular part of your project, or build it in a certain way. For instance, make install, make all, and make debug are common targets.

You probably have GNU Make on your system; much more information on Makefiles can be found here.

Matt J
thank you sir, but again what is the use of me getting a makefile. i mean i downloaded the file because they told it is the source code for many examples and if i dont get the source code then what am i supposed to study?i am totally new to this thats y, if the que is stupid please bear me. what am i actually supposed to do with this . i did use the command and i got some filenames and all, then what am i supposed to do?
yuneek
The Makefile is no good by itself. It tells the system how to turn the .c and .h *source code* files into object code, and probably link them together into a single executable. The Makefile does not contain any C code. My guess is that those are lurking somewhere on the site you got the Makefile from. If the site is indexed by Google, Google Code Search (http://www.google.com/codesearch) may be helpful. Type in a filename you got from the Makefile or a snippet of code or comment you expect, and append "lang:c" and/or "site:sitewheremycodeis.com" to the query.
Matt J
+1  A: 

It sounds like you may not have downloaded the complete source code from the book web site. As mentioned previously, a Makefile is only the instructions for building the source code, and the source code is normally found in additional files with names ending in .c and .h. Perhaps you could look around the book web site for more files to download?

Or, since presumably the book web site is public, let us know which one it is and somebody will be happy to point you in the right direction.

Greg Hewgill
the book is opengl superbible,and i am having trouble getting the codes in the book to work by typing it myselfso i was wondering if i get the source code i cud find out ma mistakes.the link that i got is http://www.starstonesoftware.com/OpenGL/
yuneek
And which file from that page did you download?
Greg Hewgill
the last one linux make files
yuneek
I just downloaded that and there are zillions of example source files in there. I'm not sure how you could miss them all. For example, the source code for one of the samples in Chapter 2 appears to be in `SB-LinuxSrc/examples/src/chapt02/simple/simple.cpp`.
Greg Hewgill
oh ohi am so sorry i was in the wrong folderi apologize for ma studpiditythank you very much siri appreciate it so muchwont make such stupid mistakes again:) thank you again
yuneek
A: 

It looks like you also need to download the SB-AllSource.zip file. Then use make (with the Makefile that you've already downloaded) to build.

Stephen C
sir, what will happen after i build?what am is supposed to do with it?
yuneek
sir got it thank you for ur help it was just in a different folder :)
yuneek