LinuxQuestions.org
Help answer threads with 0 replies.
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 02-19-2004, 07:31 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
help with makefile?


I don't know if this is possible, but I want to list all my .C files and then be able to use the list to make my program. I have this:

Code:
CXX = g++
DEF = -DPRMAN
INC = -I /usr/local/prman/include -I /root/MLInclude

# files:= $(wildcard *.C)

files:= 1.C \
	2.C \
	3.C \
	4.C \
	5.C \
	6.C \
	7.C \
	8.C \
	9.C \

objects:= $(files:%.C=%.o)


all: $(objects)
	$(CXX) $(files:.C=.o) -o program

$(objects ): $(files ) $(files:.C=.h )
	$(CXX) -c $(DEF) $(INC) $(files ) -o $(files:.C=.o )
So I'd like to type "make" and have it make each one of the object files, then the program, but instead of evaluating the variables one at a time, it evaluates all of them at once. Is there a way to make it evaluate the variables one at a time (deliniatd by spaces)? Or is there some other way I can automate the make - so that I can just change the file list and have everything just work?

In other words, how would I make the green stuff evaluate one at a time, but everything else evaluate the entire string?

Thanks

Last edited by BrianK; 02-19-2004 at 07:35 PM.
 
Old 02-19-2004, 10:31 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I'm no Makefile expert by any means, but perhaps some kind of rule like the following would do it:

.C.o:
$(CXX) -c $< -o $@

Basically just telling make how to create an object file out of a C source file. Not too sure about the syntax...
 
Old 03-11-2004, 11:27 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
try something like:
=======================
TARGETS = $(CFILES:.c=)

include include.mk

${TARGETS}:

include.mk:
ls *.c | xargs echo CFILES = > include.mk
 
Old 03-11-2004, 02:23 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally posted by bigearsbilly
try something like:
=======================
TARGETS = $(CFILES:.c=)

include include.mk

${TARGETS}:

include.mk:
ls *.c | xargs echo CFILES = > include.mk
heeeyy! that's pretty slick. I didn't know about "xargs" - looks like that's exactly what I was looking for.

Thanks!
 
Old 03-12-2004, 02:35 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I worked out how to do it properly.
this will automagically find
c files and include the header file dependencies
too. ( a bit cleverer than my previous e.g but
still short and sweet!)

They must be simple single source files though
i.e. each with it's own main() and not linked together.

Assuming you have "makedepend" also.

the standard rule is if you do
"make target" it will assume a "target.c" file and cc it.
You don't even need a make file!

like "make func"

will
cc -c func.c -o func.o
cc func.o -o func




# billy billingham
# Thu Mar 11 22:21:13 GMT 2004
#
# ---------------------------------
# Standard makefile for standalone
# C files (not multifile projects)
# e.g. makes 'func.c' with:
#
# cc -c func.c -o func.o
# cc func.o -o func
#
# end up with 'func'
#
#
# using the built-in rules for
# simple single source programs
#
# recursive call to make, first
# call to create the include'd files
# make cannot find the includes so makes them
# before it does the all: target
# ---------------------------------

INCLUDEFILE=files.mk # contains CFILES=
DEPENDFILE=depend.mk # output of makedepend to add the .h deps
TARGETS=$(CFILES:.c=) # remove .c to make the program name

all:
@echo recursive make
$(MAKE) $(TARGETS)
rm $(DEPENDFILE) $(INCLUDEFILE) # remade next time

$(DEPENDFILE):
touch $@
makedepend -f $@ *.c

$(INCLUDEFILE):
echo CFILES= *.c > $@

clean:
-rm *.o

include $(INCLUDEFILE)
include $(DEPENDFILE)
 
  


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 to modify makefile.in or makefile.am QiangWan Linux - Newbie 1 05-17-2005 11:07 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
@ in makefile m_a61 Linux - General 2 09-08-2004 07:09 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
makefile pessanimahi Programming 6 09-17-2003 02:34 AM

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

All times are GMT -5. The time now is 08:55 PM.

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