LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-17-2006, 08:01 AM   #1
vipulc
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Rep: Reputation: 0
Compiling multiple .c file using single command in makefile


Hi,

I want to compile my various .c file using makefile. I dont want to specify my .c file name in my makefile. When I add my .c file in my predefined directory it should be compiled using makefile without changing makefile. That means I want my makefile such that it should be able to compile my .c file dynamically.
 
Old 03-18-2006, 10:46 PM   #2
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
Personally, I fail at making Makefiles. Hopefully someone comes up with something better than this.

You can run a PHP, Bash, Perl or VBScript (etc) script to dynamically generate the Makefile based on the contents of the directory. You could do all kinds of fun things with 'find' and loops.

You could even call your script 'makemake', just for laughs.

EDIT: I just made up what I wrote above on the spot, but thanks to Google, here's an actual concrete example or two:
If you use fam (file alteration monitor?) and/or cron, you can even avoid having to type a command to compile your program. Be wary about compilations at CRAZY CRAZY INTERVALS.

-pcweirdo.
 
Old 03-18-2006, 11:49 PM   #3
bluelightning
Member
 
Registered: Mar 2006
Location: Redmond, WA
Distribution: FC4, WinXP Pro
Posts: 37

Rep: Reputation: 15
It is possible to simply use wildcards in a makefile to tell it to compile all the .c files. The problem is that the whole idea of a makefile is to list dependencies and only recompile parts that depend on things that changed. The dependencies for a .c file aren't simply the .c file itself. You need to list its include files too.

Fortunately, gcc has a -M option to auto generate makefiles. It will correctly identify the include file dependencies. If you follow the directions in the GNU make manual section 4.14, you'll get a makefile that includes other autogenerated makefiles. This means that your main makefile will never change.

Everytime I've used those instructions, I get a makefile that will produce a harmless error the first time it's run (because the submakefiles don't exist yet, and it generates them). I think it would work better if you compromised and allowed your makefile to change. Then you could just run this:
gcc -M *.c > Makefile; make -f Makefile

You could even put that in a script.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling a single source file: hardstyleFX Programming 7 01-12-2006 06:09 AM
single ext3 journal device multiple journaled file systems? reelwylde Linux - General 4 09-08-2005 03:00 PM
Linux shell command for makefile.in to create a text file and write to it alix123 Programming 8 01-07-2005 08:18 AM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 02:38 AM
Copying a single file to multiple directories tgolly Linux - Newbie 3 04-26-2004 03:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration