LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-24-2011, 03:28 AM   #1
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 217

Rep: Reputation: 30
Automatic make dependency generation and "clean"


Hello,
I recently found out about g++'s ability to automatically generate makefiles and I'm trying to make advantage of it, however I have a small problem; that is, I have:
Code:
# Include dependency files
-include $(DEP_TARGETS)

# Rule for dependency files
%.d:    %.cpp %.h
        $(CXX) $< $(CXXFLAGS) -MMD -MP -c

# Cleaning rule
clean:
        ...
The problem is that, as far as I have understood, if "include" can't find a .d file, it looks for a rule to create it, and applies the rule. This could be ok, however if I want to run "clean" I don't want dependency files to be rebuilt (i.e. objects to be compiled) if they don't exist.

Well, yeah, there probably is no need to "make clean" if no .d/.o files exist, however this kind of annoys me anyway.

Is there any way to perform makefile inclusion conditionally on the rule given from the command-line?

Thanks! :-)


Here are the relevant (I think) parts of my Makefile:
 
Old 11-25-2011, 12:16 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,455

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Quote:
Is there any way to perform makefile inclusion conditionally on the rule given from the command-line?
Yes it's possible to do this but there is a better way: remove the the rule to create .d files, just create them when compiling. The .o and .d files always need to be updated at the same time anyway. Furthermore, g++ has the ability to create the depenency file during compilation, saving even more time.
 
1 members found this post helpful.
Old 11-28-2011, 08:54 AM   #3
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 217

Original Poster
Rep: Reputation: 30
Thank you very much!
I knew I could update the .d file while compiling, but I just hadn't thought of removing the .d rule in the Makefile Thanks again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless works but have to "make load" each time? Is there a way to start automatic? jdruin Linux - Laptop and Netbook 4 12-28-2008 01:15 PM
What is the difference between "make deinstall clean" and "pkg_delete"? Mr_Shameless *BSD 3 04-20-2007 07:41 PM
"make clean" caused system freeze, kernel panic on reboot jwhill2000 Linux - General 3 02-08-2005 07:59 PM
When "make install clean" ports fails everytime! Devboy *BSD 9 08-11-2004 07:46 PM
how to write a recursive "make clean"? clockworks Programming 2 01-20-2004 11:19 AM


All times are GMT -5. The time now is 02:53 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration