Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 On "makefiles"
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Roman




PostPosted: Fri Jan 16, 2009 10:11 am   Post subject: On "makefiles"

Hey,

I noticed that in the whirlwind tour, it is mentioned that makefiles should be created for every program you compile.
What exactly is a makefile? I did a quick wikipedia search, and it seems that it's something like instructions on how to compile the program (?), but that it is done automatically in modern compilers. The textbook we're using (C Programming, A modern Approach by K.N. King) does not mention makefiles until later on, when it discusses building multiple-file programs. Is it better to make makefiles for smaller programs as well? Or is it a skill best left for somewhat later?

Thanks in advance,
-RZ
Sponsor
Sponsor
Sponsor
sponsor
jernst




PostPosted: Fri Jan 16, 2009 11:27 am   Post subject: Re: On "makefiles"

Makefiles give some automation to compiling your projects, its especially helpful when you have to compile and link together many files. You set up some "targets" which are sort of rules and options on how to compile particular files or groups of files in your project. In these rules you can set which compiler you want to use and pass any arguments you want to the compiler. Then you can type make and if your Makefile is set up properly, it will compile everything. It saves you from having to type in "gcc/g++ filename -options" etc... to compile. Its also useful if you are working on things with other people, or are distributing the source since the others might not be familiar with what is required for your code to compile.
Clayton




PostPosted: Fri Jan 16, 2009 1:09 pm   Post subject: RE:On "makefiles"

To put simply, and with a trivial example, it's the difference between:

code:
>> gcc -o foo foo.c foo2.c foo3.c


multiple times, or the above once (more or less), and then just:
code:
>> make


every time you wish to compile your code afterwards. Obviously the benefits are more as the size of a project increases, but it's still a good idea to get into the habit of having a makefile for each project you write.
wtd




PostPosted: Fri Jan 16, 2009 1:10 pm   Post subject: RE:On "makefiles"

Also handy is a good "clean" rule. Any decently large project will be built about a bajillion times, and while compiling everything manually every time might not be awful, cleaning up the generated files in between would be. Smile
btiffin




PostPosted: Fri Jan 16, 2009 1:23 pm   Post subject: Re: On "makefiles"

I think everyone is missing one the key reasons for the invention of make and Makefile. Dependency graphs.
A simple build script for
code:
$ gcc -o foo foo.c foo2.c foo3.c
is trivial. But what if foo2.c and foo3.c rarely change? make is smart enough to not recompile foo2 and foo3 by comparing the modification times. Without that feature, I doubt make would have ever been developed in the first place.

On a GNU/Linux box with build-essentials installed, you can try make without a Makefile. GNU make has default rules that know how to create executables when it sees a .c file. So for simple things; just type $ make filename. For more complex things, dig in and create the dependency list in a Makefile. Then life is sweet.

After that, get used to automake, autoconf, and libtool and most of the crap involved with POSIX enabled cross-platform issues are taken care of for you and you'll look and feel like a real pro.

Cheers
OneOffDriveByPoster




PostPosted: Fri Jan 16, 2009 3:32 pm   Post subject: Re: On "makefiles"

btiffin @ Fri Jan 16, 2009 1:23 pm wrote:
After that, get used to automake, autoconf, and libtool and most of the crap involved with POSIX enabled cross-platform issues are taken care of for you and you'll look and feel like a real pro.
What? You mean my strictly conforming POSIX application will not work on all POSIX implementations? Smile
Zeroth




PostPosted: Fri Jan 16, 2009 4:51 pm   Post subject: Re: On "makefiles"

OneOffDriveByPoster @ Fri Jan 16, 2009 12:32 pm wrote:
btiffin @ Fri Jan 16, 2009 1:23 pm wrote:
After that, get used to automake, autoconf, and libtool and most of the crap involved with POSIX enabled cross-platform issues are taken care of for you and you'll look and feel like a real pro.
What? You mean my strictly conforming POSIX application will not work on all POSIX implementations? Smile
They may "conform", but the POSIX implementation doesn't define where the more recent kinds of apps store their configuration settings... ie, X and beyond! It also doesn't define access standards for different directories, so what works on say Linux won't on FreeBSD because the access settings are different.
btiffin




PostPosted: Sat Jan 17, 2009 2:42 am   Post subject: Re: On "makefiles"

By the way; I'm relatively new to automake myself, but became a fan with the first Makefile.in. The auto generated targets are a boon.

It's a fair load of crap to read through the first time, but after that ... Smooth.

Comes with the Old Guy ramble on recommendation.

Cheers
Sponsor
Sponsor
Sponsor
sponsor
jain.rani




PostPosted: Mon Jul 13, 2009 10:32 pm   Post subject: Re: On "makefiles"

A makefile is the set of instructions that you use to tell makepp how to build your program. Makepp can accept most makefiles written for the standard unix make, but if you're starting from scratch, it is often much simpler to use some of makepp's advanced features. This is an introduction for writing makefiles that are specific to makepp.


A simple makefile

Suppose you are writing a C++ program which has two source modules, processing.cxx and gui.cxx, along with numerous include files. If you were to build your program from scratch, you would need to execute something like these commands:

c++ -c processing.cxx -o processing.o
c++ -c gui.cxx -o gui.o
c++ processing.o gui.o -o my_program


Thanks
[url] http://supermanhelp.com [/url][/url]
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: