LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2006, 04:26 PM   #1
kickzha
LQ Newbie
 
Registered: Sep 2004
Location: augsburg homeboy
Distribution: debian sarge/sid
Posts: 17

Rep: Reputation: 0
makefile : understing make


Hello,

again as beginner i have a problem, see that makefile if interested in helping me:
Code:
#Makefile

NAME = exe

INCLUDE = `pkg-config --cflags gtk+-2.0` `pkg-config --cflags gtksourceview-1.0` `pkg-config --cflags gnome-vfs-2.0`

LIBS = `pkg-config --libs gtk+-2.0` `pkg-config --libs gtksourceview-1.0` `pkg-config --libs gnome-vfs-2.0`

OBJECTS = codeview     # could work as an array and for each??

${OBJECT}.o:
	gcc -g -c -o obj/${OBJECT}.o ${INCLUDE} ${OBJECT}/${OBJECT}.c

TARGET = $(${TARGET} obj/${OBJECT}.o)

all:	${OBJECTS}
	gcc -g -o ${NAME} ${INCLUDE} ${LIBS} main.c obj/${OBJECTS}.o
...as it may be seen, i try a 'general' makefile, wherein i best just have to add the a name to OBJECTS if i add a module, and better than this i may but the name in a file wherefrom make it would read.

Implementable by the GNU make ??


thx
chab

Last edited by kickzha; 06-17-2006 at 04:30 PM.
 
Old 06-17-2006, 04:54 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
If I understand your question correctly (and I'm not sure if I do), then you can just add any additional modules you want to compile to the "OBJECTS =" line to get them to compile. However, the one problem I see is that the gcc command in the all target doesn't seem to be set up properly to handle multiple .o files (look at the macro -- it won't expand the way you want it).

Usually I specify the full name of object files, e.g.

OBJECTS = foo.o bar.o spam.o

And then use a target like the following to compile them:

.c.o:
gcc -c $<

The I add a separate line in the target to link them all together. You could add something to the gcc line above to make it dump all of the objects into a special obj directory if you like,

Hope this helps.
 
Old 06-17-2006, 05:01 PM   #3
kickzha
LQ Newbie
 
Registered: Sep 2004
Location: augsburg homeboy
Distribution: debian sarge/sid
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by btmiller
If I understand your question correctly (and I'm not sure if I do)
u did
Quote:
Originally Posted by btmiller
OBJECTS = foo.o bar.o spam.o

And then use a target like the following to compile them:

.c.o:
gcc -c $<
...ok, understood.


Thank you.

chab
 
Old 06-18-2006, 05:35 PM   #4
kickzha
LQ Newbie
 
Registered: Sep 2004
Location: augsburg homeboy
Distribution: debian sarge/sid
Posts: 17

Original Poster
Rep: Reputation: 0
Code:
#Makefile

NAME = exe

all:	${NAME}

INCLUDE = `pkg-config --cflags gtk+-2.0` `pkg-config --cflags gtksourceview-1.0` `pkg-config --cflags gnome-vfs-2.0`

LIBS = `pkg-config --libs gtk+-2.0` `pkg-config --libs gtksourceview-1.0` `pkg-config --libs gnome-vfs-2.0`


OBJECTS = codeview.o desktop.o


$(OBJECTS): $($@:.o=)/$($@:.o=.c)
	gcc -g -c -o obj/$@ ${INCLUDE} $(@:.o=)/$(@:.o=.c)

TARGETS = $(foreach dir,$(OBJECTS),obj/$(dir))

${NAME}:	${OBJECTS}
	gcc -g -o ${NAME} ${INCLUDE} ${LIBS} main.c ${TARGETS}

debug:	all
	gdb -x breaks exe

pp:
	g++ ${INCLUDE} ${LIBS} main.c

edit:
	gedit breaks main.h main.c &
...works pretty fine now, tried to make OBJECTS possible to just give the names (without .o) ... but time expired...

thx all
have fun!
kickzha
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do we make MakeFile...? asahlot Programming 1 10-17-2005 02:25 PM
How to use make? and makefile? markw8500 Linux - Newbie 11 08-08-2005 10:21 PM
how 2 make a makefile? beginner_84 Programming 6 08-29-2004 02:47 PM
Who know what kind of 'make' should be used for this Makefile? pvv Linux - General 3 03-17-2004 09:36 AM
How to Make a Makefile for KDevelop 2.0 ??? shassouneh Programming 7 03-15-2002 01:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:23 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