tags:

views:

98

answers:

8
+3  Q: 

makefile extension

Hi, I'm writing a C program using gcc in cygwin. My question is, how do you create a makefile? I mean, what file-extension does it have? I know how to write simple rules, but I can't save a file in the text-editor with the right extension? Impossible to find any info about this... This is prolly a super-newbie question. So let the flaming begin. :-P

+1  A: 

They are usually named Makefile, or makefile. No extension. That's just convention, though.

It's not trivial to write a makefile, look up a guide or tutorial =)

Santiago Lezica
A: 

Open your favorite text editor, and create a file named Makefile.

Content might vary, but, provided you have a program called hello.c a very, very simple Makefile to compile it could be:

hello: hello.c
     gcc -Wall hello.c -o hello.exe

After that you run run from cygwin shell:

$ ls
hello.c Makefile
$ make
....

And your Makefile will try to compile hello.c. If everything goes as expected, you can run the hello.exe program by executing the following shell command:

$ ./hello.exe

Here's a nice tutorial on Makefiles.

Pablo Santa Cruz
A: 

A makefile is usually just called Makefile.

klausbyskov
+5  A: 

The default filename for a makefile is Makefile; this is the name that GNU Make looks for when you run it without any options. The -f argument lets you specify an alternate filename if desired.

Ignacio Vazquez-Abrams
Actually the names GNU make looks for are specified [in the manual](http://www.gnu.org/software/make/manual/make.html#Makefile-Names): "it tries the following names, in order: GNUmakefile, makefile and Makefile".
bstpierre
Fair enough. But most people that write makefiles use that name.
Ignacio Vazquez-Abrams
A: 

You can name them whatever you like, but ".mak" looks right.

... google ... http://msdn.microsoft.com/en-us/library/aa380049%28VS.85%29.aspx ... yeah

pmg
+5  A: 

As you are using Cygwin which in turn means that you are using GNU make, I cite the relevant portion of the GNU make manual:

3.2 What Name to Give Your Makefile

By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile. Normally you should call your makefile either makefile or Makefile. (We recommend Makefile because it appears prominently near the beginning of a directory listing, right near other important files such as README.) The first name checked, GNUmakefile, is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU make, and will not be understood by other versions of make. Other make programs look for makefile and Makefile, but not GNUmakefile.

[...]

If you want to use a nonstandard name for your makefile, you can specify the makefile name with the ‘-f’ or ‘--file’ option. The arguments ‘-f name’ or ‘--file=name’ tell make to read the file name as the makefile. If you use more than one ‘-f’ or ‘--file’ option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names GNUmakefile, makefile and Makefile are not checked automatically if you specify ‘-f’ or ‘--file’.

Peter G.
A: 

Makefiles don't usually have an extension. They're typically called 'makefile' or 'Makefile'. Sometimes, when someone writes a complex set of makefiles that include each other, the included files get a .mak extension to indicate that they're makefiles even though they aren't called 'makefile'.

swestrup
+1  A: 

In the few places where I've seen extensions used on makefile names they have generally been either .make or .gmk, and even then those extensions are usually reserved for makefile fragments that are included by master files given one of the default names.

dmckee