Makefile design

C

cppaddict

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
 
V

Victor Bazarov

cppaddict said:
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
 
B

Buster

cppaddict said:
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.
 
G

Gianni Mariani

cppaddict said:
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:

Nothing to do with C++. Off topic here.
Thanks for any ideas,

<off topic response>

Check out www.makexs.com <shameless plug> !

In my opinion, you don't want to do what the Makefile can do for you.
If you read the MakeXS doc, you'll get the idea of what I'm talking about.
 
J

Jacques Labuschagne

cppaddict said:
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.
 
T

TheDD

Le 29/05/2004 à 19:25:07 said:

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
 
T

Thorsten Ottosen

| 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
 
D

Derek

| 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top