CFLAGS, CCFLAGS, CXXFLAGS: ¿qué controlan exactamente estas variables?
Estoy usando GNU make para compilar mi código C ++, y me gustaría entender cómo hacer que mis compilaciones sean personalizables.
Leí en diferentes lugares queCFLAGS
, CCFLAGS
yCXXFLAGS
se utilizan para este propósito. Entonces, ¿cómo debo usarlos? Si tengo argumentos de línea de comandos adicionales para el compilador, ¿debería agregarlos aCFLAGS
o los antepone? ¿Existe una práctica común?
¿Por qué las tres variables diferentes? Supongo que el compilador de C debería obtenerCFLAGS
yCCFLAGS
, mientras que el compilador de C ++ debería obtenerCFLAGS
yCXXFLAGS
- ¿Lo entendí bien
¿Se supone que el usuario humano debe establecer estas variables? Hacer cualquier herramienta automática automake
, autoconf
, etc.) configurarlos? El sistema Linux que se supone que debo usar no define ninguna de estas variables. ¿Es esto típico?
Actualmente mi Makefile se ve así, y siento que está un poco sucio:
ifdef code_coverage
GCOV_FLAG := -fprofile-arcs -ftest-coverage
else
GCOV_FLAG :=
endif
WFLAGS := -Wall
INC_FLAGS := -Istuff -Imore_stuff -Ietc
CCFLAGSINT := -O3 $(WFLAGS) $(INC_FLAGS) $(CCFLAGS)
... (somewhere in the makefile, the command-line for compilation looks like this)
$(CC) $(CCFLAGSINT) -c ifdef code_coverage
GCOV_FLAG := -fprofile-arcs -ftest-coverage
else
GCOV_FLAG :=
endif
WFLAGS := -Wall
INC_FLAGS := -Istuff -Imore_stuff -Ietc
CCFLAGSINT := -O3 $(WFLAGS) $(INC_FLAGS) $(CCFLAGS)
... (somewhere in the makefile, the command-line for compilation looks like this)
$(CC) $(CCFLAGSINT) -c $< -o $@
... (somewhere in the makefile, the command-line for linking looks like this)
$(CC) $(GCOV_FLAG) $(CCFLAGSINT) $(OBJLIST) $(LDFLAGS) -o $@
lt; -o $@
... (somewhere in the makefile, the command-line for linking looks like this)
$(CC) $(GCOV_FLAG) $(CCFLAGSINT) $(OBJLIST) $(LDFLAGS) -o $@
Estoy bastante seguro de que no hay errores aquí; el Makefile funciona muy bien. Pero, ¿hay algo que vaya en contra de las convenciones (comoCCFLAGSINT
- ¿debería sobrescribirCCFLAGS
en su lugar? OCXXFLAGS
? FUD!)
Perdón por tantas preguntas; obviamente no las responderá a todas, pero espero que las respuestas me ayuden a comprender la idea general detrás de estas configuraciones.