简体   繁体   中英

What does this part mean in Makefile?

What does this part mean in Makefile?

    1 CC=gcc
    2 CXX=g++
    3 RM=rm
    4 PROTOC=protoc
    5 ODB=odb

Sorry, I'm a beginner

They're setting up substitutions so that you can later have a command like:

$(RM) x.o

and it will magically become, when executing:

rm x.o

It allows you to (for example) change it later to be rm -rf and you only change it in one place.

Typically you'll see things like:

$(CC) $(CFLAGS) -c -o object_file.o source_file.c

If you compile a compile of hundred C source files, and you suddenly discover they all needed a new -I directive, you probably want that in one single place :-)

See the "variables" section of the GNU Make manual for (much) more detail, if you wish.


We also use it in our shop for making our builds somewhat more "readable", things like:

PERM_FOR_EXE=chmod 700
PERM_FOR_CFG=chmod 400
PERM_FOR_DATA=chmod 500

RM=rm
FORCE_RM=rm -f
RM_DIR_AND_BELOW=rm -rf

PROTO_FOR_PY=protoc --output=betterproto
PROTO_FOR_CPP=protoc --output=cpp
PROTO_FOR_BCPL=echo FAT CHANCE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM