The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help understanding a program Toxic Shell Programming and Scripting 1 03-20-2006 01:50 AM
A little help understanding FIFOs? deckard Linux 0 11-01-2005 01:46 PM
Understanding traceroutes Bobby IP Networking 2 03-14-2005 05:35 PM
need further understanding of init.d jigarlakhani UNIX for Advanced & Expert Users 1 09-20-2002 04:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2007
the_learner the_learner is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 75
Understanding this Makefile

I have this program which has lots of source files in the directories
Code:
src
src/dir1 
src/dir2
src/dir3... and so on
I am trying to understand the following Makefile:

Code:
CC = gcc
CFLAGS= -g -c -D_REENTRANT
SOURCES = src/main.c src/dir1/a.c src/dir1/b.c src/dir2/x.c src/dir2/y.c ...and so on
OBJS = src/main.o src/dir1/a.o src/dir1/b.o src/dir2/x.o src/dir2/y.o ...and so on
TARGETS = prog.exe

%.o : %.c
        $(CC) $(CFLAGS) -o $@ $?

${TARGETS}:  ${OBJS}
        $(CC) ${OBJS} -o ${TARGETS}
First of all, I am trying to understand what does $@ $? do?? And also what does the wild character % in %.o : %.c stand for ?

And, since I have a lot of source files spread out in multiple directories and lots of corresponding directories.. the macros SOURCES and OBJS are getting quite ugly.. is there any way around this ?

(I couldve also used macros for the directory names, but it is still getting very ugly)
  #2 (permalink)  
Old 06-12-2007
the_learner the_learner is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 75
It would be much better if i could say:

Code:
SOURCES = src/*.c    src/dir1/*.c    src/dir2/*.c
OBJS       = src/*.o    src/dir1/*.o    src/dir2/*.o
But that does not work
  #3 (permalink)  
Old 06-12-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
$@ is the target of the dependancy

$? are the prequisites for each dependancy rule

The %.o: %.c means in order to build a file with this extension from a file of this extension follow this rule.

Personally I think wild cards are bad news in Makefiles. You want to know exactly what you are building.

While we are at it, I also I don't recommend requiring gmake.

Also, personally, I think that objects should be built in a totally different tree to the source.
  #4 (permalink)  
Old 06-13-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,764
And I think that persistent objects be kept in source control along with the primary source. Source control is a must.
  #5 (permalink)  
Old 06-13-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
I was referring to .o files. As in I recommend keeping the compiled objects built in a separate tree to the source especially when you compile for multiple architectures.
  #6 (permalink)  
Old 06-14-2007
ilko_partizan's Avatar
ilko_partizan ilko_partizan is offline
Registered User
  
 

Join Date: Apr 2007
Location: EU, Bulgaria
Posts: 33
This article will help you to understand "make".
An Introduction to the UNIX Make Utility

Best regards,
Iliyan Varshilov

Last edited by ilko_partizan; 06-18-2007 at 09:18 AM..
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0