C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2013, 02:25 AM
ccsr ccsr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 13 ccsr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 m 57 sec
Reputation Power: 0
Makefile

I am trying to write makefile after going through some tutorial here:
http://www.gnu.org/software/make/manual/make.html#Wildcard-Examples

My objective is to create makefile which reads the files from specified directories using VPATH variable and vpath directive, but i am getting error

gcc -o foo
gcc: no input files
make: *** [foo] Error 1

My directory structure is as below:

+Project (Makefile)
+Libraries(some .c files)
+Application(some .c files)
+Headers(some .h files)

where Project is a parent directory which has Makefile and other directories like Libraries, Application and Headers.

I would like to compile files in those directories by using a makefile present in Project Directory.

My Makefile is as below:

VPATH = Lib:App:Head
#vpath %.c Lib:Head:App
objs := $(patsubst %.c,%.o,$(wildcard *.c))
foo: $(objs)
gcc -o foo $(objs)


Please help.

Reply With Quote
  #2  
Old February 19th, 2013, 06:51 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,836 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 16 h 15 m 5 sec
Reputation Power: 1774
wildcard doesn't search vpath, it's only used for resolving target:dependency lookups.

Try
objs := $(patsubst %.c,%.o,$(wildcard Lib/*.c))
objs += $(patsubst %.c,%.o,$(wildcard App/*.c))
objs += $(patsubst %.c,%.o,$(wildcard Head/*.c))
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old February 19th, 2013, 07:34 AM
ccsr ccsr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 13 ccsr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by salem
wildcard doesn't search vpath, it's only used for resolving target:dependency lookups.

Try
objs := $(patsubst %.c,%.o,$(wildcard Lib/*.c))
objs += $(patsubst %.c,%.o,$(wildcard App/*.c))
objs += $(patsubst %.c,%.o,$(wildcard Head/*.c))


But , the link provided says if the file is not found in current directory, make will search the paths provide in VPATH or vpath.
And also if i want to compile all the files with -Wall, what is the correct place to add and how.

Reply With Quote
  #4  
Old February 19th, 2013, 08:55 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,836 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 16 h 15 m 5 sec
Reputation Power: 1774
> But , the link provided says if the file is not found in current directory, make will search the paths provide in VPATH or vpath.
Yes, but only for
foo.o : foo.c
type rules.

If foo.c isn't in the current directory, then the directories in VPATH are searched.

VPATH isn't used for everything.
In fact, wildcard searches on VPATH could result in an uncontrollable mess of 100's of files you really didn't expect.

IMO, you're trying to bend the tool into a shape it wasn't designed for. There are ways of doing multi-level makes - read up on them.

Reply With Quote
  #5  
Old February 19th, 2013, 11:40 PM
ccsr ccsr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 13 ccsr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by salem
> But , the link provided says if the file is not found in current directory, make will search the paths provide in VPATH or vpath.
Yes, but only for
foo.o : foo.c
type rules.

If foo.c isn't in the current directory, then the directories in VPATH are searched.

VPATH isn't used for everything.
In fact, wildcard searches on VPATH could result in an uncontrollable mess of 100's of files you really didn't expect.

IMO, you're trying to bend the tool into a shape it wasn't designed for. There are ways of doing multi-level makes - read up on them.



Thanks, I am actually going through various methods used , but i could not find any makefile which deals with multiple directories.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Makefile

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap