Makefile question

  • Thread starter Matthias Pieroth
  • Start date
M

Matthias Pieroth

Hi NG,

I have the following MakeFile:

# Compiler
#---------------------------------------
CC = g++

APP = snake-client

# Compilerflags
#---------------------------------------
#CFLAGS += -O2

# Libraries
#---------------------------------------
LIB = -lncurses

# Sourcedateien
#---------------------------------------
SRC = snake-client.cpp CCursesWrapper.cpp

# Objektdateien
#---------------------------------------
OBJ = $(SRC:.cpp=.o)

$(APP): $(OBJ)
$(CC) $(OBJ) -o $(APP) $(LIB)

clean:
rm *.o

My problem is, I have a CCursesWrapper.h. I want to add this file to the
MakeFile, so that it will be included and newly compiled if I change the
CCursesWrapper.h. How can I do this?

Thank you

Matthias
 
E

Emanuel Ziegler

Matthias said:
My problem is, I have a CCursesWrapper.h. I want to add this file to the
MakeFile, so that it will be included and newly compiled if I change the
CCursesWrapper.h. How can I do this?

I think you want to recompile CCursesWarpper.o whenever CCursesWarpper.cpp
or CCursesWrapper.h is changed. So, you simply have to add a rule for
CCursesWrapper.o like

CCursesWrapper.o: CCursesWrapper.cpp CCursesWrapper.h
$(CC) -c -o $@ $< $(LIB)

if CCursesWrapper.h is located in the current directory (otherwise you have
to add -I <includedir> to the compiler options, where <includedir> stands
for the directory of CCursesWrapper.h).

HTH
Emanuel
 
G

Gianni Mariani

Matthias said:

Hi NG,

this is off-topic for comp.lang.c++. Try posting to comp.programming.
I have the following MakeFile: ....

My problem is, I have a CCursesWrapper.h. I want to add this file to the
MakeFile, so that it will be included and newly compiled if I change the
CCursesWrapper.h. How can I do this?


you'll need to add the rule

$(OBJ) : CCursesWrapper.h
# no commands...


However - if you want all this to happen automagically, use MakeXS.

(shameless plug)

http://www.makexs.com
 
J

Jorge Rivera

Matthias said:
Hi NG,

I have the following MakeFile:

# Compiler
#---------------------------------------
CC = g++

APP = snake-client

# Compilerflags
#---------------------------------------
#CFLAGS += -O2

# Libraries
#---------------------------------------
LIB = -lncurses

# Sourcedateien
#---------------------------------------
SRC = snake-client.cpp CCursesWrapper.cpp

# Objektdateien
#---------------------------------------
OBJ = $(SRC:.cpp=.o)

$(APP): $(OBJ)
$(CC) $(OBJ) -o $(APP) $(LIB)

clean:
rm *.o

My problem is, I have a CCursesWrapper.h. I want to add this file to the
MakeFile, so that it will be included and newly compiled if I change the
CCursesWrapper.h. How can I do this?

Thank you

Matthias

You can automate this process somewhat...

Do a man on mkdepends. Read carefully. It writes rules, but it changes
your Makefile while doing it. It is nice because it will run a
preprocessor on your source files and determine all the header files it
requires. It then proceeds to create rules and append them to your Makefile
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top