Reuse rule rule

I am studying make files and I am trying to figure out how to use the rule. Now I have the following:

CPP = cl

CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt

.SUFFIXES: .exe .cpp

Exercise35.exe:
    $(CPP) Exercise35.cpp $(CPPFLAGS)

debug:
    $(CPP) Exercise35.cpp $(CPPFLAGS) /D "_DEBUG"

It seems that the rule debugessentially repeats the rule Exercise35with an additional command line parameter. Is there a better way?

+3
source share
3 answers

Recursive makeand add debug flag to CPPFLAGS.

debug:
    $(MAKE) CPPFLAGS="$(CPPFLAGS) /D _DBEBUG" Exercise35.exe
+3
source

You should check the following make properties and see an example below:

  • $ @ - means the name of the current target file, in which case it corresponds to the APP value.
  • $ <- means one file, which is newer than the target on which the target depends.
  • $? - , , , .
.SUFFIXES: .cpp.exe
CPP = cl
EXTRAFLAGS = 
CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /ZI /TP /errorReport:prompt

FILES = Exercise35
APP = Exercise35.exe

.cpp.exe:
     $(CPP) $(EXTRAFLAGS) $(CPPFLAGS) /c $<

all : $(APP)

$(APP) : $(FILES)
     $(CPP) $(EXTRAFLAGS) $(CPPFLAGS) $@ $(FILES)

clobber : clean mrproper

clean:
     del $(FILES)

mrproper:
     del $(APP)

makefile, , make "" , / make,

make EXTRAFLAGS="/D _DDEBUG"

make _DDEBUG, , EXTRAFLAGS .

Edit: , , , exe , ... makefile AIX ( Linux ...) !

, , , .

+1

G'day,

debug Makefile.

CPP = cl

CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D \
    "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 \
    /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 \
    /nologo /c /ZI /TP /errorReport:prompt

#DEBUG = /D "_DEBUG"
DEBUG =

.SUFFIXES: .exe .cpp

Exercise35.exe:
    ${CPP} Exercise35.cpp ${CPPFLAGS} ${DEBUG}

DEBUG, .

BTW Makefile, ${}, $(), , - .

: make make , " GNU Make". make, . .

, , . .

Edit 2: Here, the link to the Amazon site for the first edition of the book is simply called Project Management with Make . "As I said above, a great description of why you need to behave the way it is.

NTN

amuses

0
source

Source: https://habr.com/ru/post/1727074/


All Articles