I use GNU make to compile my C ++ code, and I would like to understand how to make my compilations customizable.
I read in various places that CFLAGS , CCFLAGS and CXXFLAGS are used for this purpose. So how should I use them? If I have additional command line arguments for the compiler, should I add them to CFLAGS or add them? Is there a common practice?
Why are there three different variables? I assume that the C compiler should get CFLAGS and CCFLAGS , while the C ++ compiler should get CFLAGS and CXXFLAGS - did I get it right?
Is the user supposed to set these variables at all? Do you install any automatic tools ( automake , autoconf , etc.)? The linux system that I should use does not define any of these variables - is this typical?
Currently, my Makefile looks like this and I feel this is a bit dirty:
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 $@
I am sure there are no errors; The makefile works very well. But is there anything that goes against the conventions (e.g. CCFLAGSINT - instead of just overwriting CCFLAGS ? Or CXXFLAGS ? FUD!)
Sorry for so many questions; you obviously wonโt answer them, but I hope that the answers will help me understand the general idea of โโthese settings.
gcc naming-conventions makefile
anatolyg Apr 04 '11 at 17:14 2011-04-04 17:14
source share