By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Makefile design

P: n/a
Hi,

If this is off-topic for this group, please let me know a better place
to post (I searched Google groups and couldn't find one myself).

My question is about designing Makefiles. If your application is made
up of A.cpp, B.cpp, C.cpp, etc, is the following a good design for a
Makefile:

<code>

#compile and link
CC=bcc32
#compile only
CCc=bcc32 -c

OBJS=Main.obj A.obj B.obj C.obj

all: $(OBJS)
$(CC) $(OBJS)

Main.obj: Main.cpp
$(CCc) Main.cpp

A.obj: A.cpp A.h
$(CCc) A.cpp

B.obj: B.cpp B.h
$(CCc) B.cpp

C.obj: C.cpp C.h
$(CCc) C.cpp

</code>

I'm just learning about Makefiles, and my real question is, When you
would you ever have a design that is significantly different from the
one above. I know that people often do, but I'm having a hard time
imagining why they would.

Are there any good articles I should read on the subject of designing
Makefiles?

Thanks for any ideas,
cpp

Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"cppaddict" <he***@hello.com> wrote...
If this is off-topic for this group,
Yes, it is. It has nothing to do with the language. Next time
you have a doubt whether a question is on topic, think whether
it can be answered in _terms_ of C++ language. Also, get yourself
a copy of the Standard to see what is included in the language.
It should help with dismissing doubts about threads, networking,
graphics, etc.
please let me know a better place
to post (I searched Google groups and couldn't find one myself).

My question is about designing Makefiles. [...]


Try gnu.g++.* or gnu.utils.help.

V
Jul 22 '05 #2

P: n/a
cppaddict wrote:
Are there any good articles I should read on the subject of designing
Makefiles?


Have you read the 'GNU Make Manual', even? The Automatic Prerequisites
section can help you save a lot of time when you reorganise a project or
begin a new one.

--
Regards,
Buster.
Jul 22 '05 #3

P: n/a
cppaddict wrote:
Hi,

If this is off-topic for this group, please let me know a better place
to post (I searched Google groups and couldn't find one myself).

My question is about designing Makefiles. If your application is made
up of A.cpp, B.cpp, C.cpp, etc, is the following a good design for a
Makefile:


You can make it a little friendlier than that... I like not having to
list my sources explicitly. (This assumes GNU make, of course.)
You may want to google for "autotools"; automake, autoconf, etc. are
worth knowing.

CC=g++
CCFLAGS=-Wall -ansi -pedantic -g -trigraphs
LDFLAGS=-g
SOURCES=$(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
TARGET=myprogram

all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^

%.o: %.cpp %.hpp
$(CC) $(CCFLAGS) -c $<

%.o: %.cpp
$(CC) $(CCFLAGS) -c $<

clean:
rm -f *.o $(TARGET)
Regards,
Jacques.
Jul 22 '05 #4

P: n/a
Le 29/05/2004 à 19:25:07, cppaddict <he***@hello.com> a écrit:
Hi,


Hi

Here is "my" Makefile. It's supposed not to use GNU specific feature
(the %). Some tradition:
* in UNIX world, object file extenion is .o
* c++ file extension is... subject of religious troll
* when you look at the internal GNU make rule database, you see that
CXX and CXXFLAGS are the most "standard".
* the *~, ... files in the clean rule are generated by emacs, so you
may don't need them
* the dependencies are written by hands

NAME = test
SRC = A.cpp \
B.cpp \
C.cpp
OBJ = $(SRC:.cpp=.o)

..PHONY: all clean
..SUFFIXES: .cpp .o

CXX = g++

#PERF = -O2
PERF = -ggdb

CXXFLAGS = -W -Wall -std=c++98 -pedantic $(PERF)
LDFLAGS = $(PERF)

all: $(NAME)

$(NAME): $(OBJ) Makefile
$(CXX) $(LDFLAGS) -o $@ $(OBJ)

..cpp.o: Makefile
$(CXX) -c $(CXXFLAGS) $< -o $@

clean:
rm -f *~ .*~ \#* .\#*
rm -f $(OBJ)

# deps
A.cpp: A.hh
B.cpp: B.hh
C.cpp: C.hh
HTH

--
TheDD
Jul 22 '05 #5

P: n/a
"cppaddict" <he***@hello.com> wrote in message news:df********************************@4ax.com...

| I'm just learning about Makefiles, and my real question is, When you
| would you ever have a design that is significantly different from the
| one above. I know that people often do, but I'm having a hard time
| imagining why they would.

Please stop using make-files and save your'self a lot of time. Boost.Jam rocks :-)
for more detail see www.boost.org

br

Thorsten
Jul 22 '05 #6

P: n/a
> | I'm just learning about Makefiles, and my real question
| is, When you would you ever have a design that is
| significantly different from the one above. I know
| that people often do, but I'm having a hard time
| imagining why they would.

Please stop using make-files and save your'self a
lot of time. Boost.Jam rocks :-) for more detail see
www.boost.org.


I agree, but why use the Boost version when regular Jam
might do the trick:

http://www.perforce.com/jam/jam.html

I'm not sure what Boost modified in Jam, but standard Jam
has worked very well for me.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.