Skip to main content
use environment variables recognized by GCC
Source Link
Eleno
  • 1.9k
  • 4
  • 28
  • 43

I would like recipes in GNU Make to use environment variables instead of command line arguments, to make them shorter, so that I can concentrate better on what changes in each command. For example, instead of seeing:

g++ -g -I/path1 -I/path2 -DFLAG  -Wall -c hello.cpp -o hello.o

I would like to see something like:

g++ -c hello.cpp -o hello.o

where g++ would read include directories and everything else from environment variables. Therefore, instead of using this:

compile.cxx = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

I am using this:

compile.cxx = CXXFLAGS="$CPATH="$(CXXFLAGSCPATH)" CPPFLAGS="$LIBRARY_PATH="$(CPPFLAGSLIBRARY_PATH)" bash -c $(CXX) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

But I get this output:

CXXFLAGS="irrelevant"CPATH="irrelevant" CPPFLAGS="irrelevant"LIBRARY_PATH="irrelevant" bash -c g++ -c hello.cpp -o hello.o
g++: fatal error: no input files

Hence, it seems that g++ does not receive its arguments.

I am also open to alternatives that achieve a similar effect (that is: short recipes).

I would like recipes in GNU Make to use environment variables instead of command line arguments, to make them shorter, so that I can concentrate better on what changes in each command. For example, instead of seeing:

g++ -g -I/path1 -I/path2 -DFLAG  -Wall -c hello.cpp -o hello.o

I would like to see something like:

g++ -c hello.cpp -o hello.o

where g++ would read include directories and everything else from environment variables. Therefore, instead of using this:

compile.cxx = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

I am using this:

compile.cxx = CXXFLAGS="$(CXXFLAGS)" CPPFLAGS="$(CPPFLAGS)" bash -c $(CXX) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

But I get this output:

CXXFLAGS="irrelevant" CPPFLAGS="irrelevant" bash -c g++ -c hello.cpp -o hello.o
g++: fatal error: no input files

Hence, it seems that g++ does not receive its arguments.

I would like recipes in GNU Make to use environment variables instead of command line arguments, to make them shorter, so that I can concentrate better on what changes in each command. For example, instead of seeing:

g++ -g -I/path1 -I/path2 -DFLAG  -Wall -c hello.cpp -o hello.o

I would like to see something like:

g++ -c hello.cpp -o hello.o

where g++ would read include directories and everything else from environment variables. Therefore, instead of using this:

compile.cxx = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

I am using this:

compile.cxx = CPATH="$(CPATH)" LIBRARY_PATH="$(LIBRARY_PATH)" bash -c $(CXX) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

But I get this output:

CPATH="irrelevant" LIBRARY_PATH="irrelevant" bash -c g++ -c hello.cpp -o hello.o
g++: fatal error: no input files

Hence, it seems that g++ does not receive its arguments.

I am also open to alternatives that achieve a similar effect (that is: short recipes).

Source Link
Eleno
  • 1.9k
  • 4
  • 28
  • 43

Using environment variables for shorter recipes in GNU Make

I would like recipes in GNU Make to use environment variables instead of command line arguments, to make them shorter, so that I can concentrate better on what changes in each command. For example, instead of seeing:

g++ -g -I/path1 -I/path2 -DFLAG  -Wall -c hello.cpp -o hello.o

I would like to see something like:

g++ -c hello.cpp -o hello.o

where g++ would read include directories and everything else from environment variables. Therefore, instead of using this:

compile.cxx = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

I am using this:

compile.cxx = CXXFLAGS="$(CXXFLAGS)" CPPFLAGS="$(CPPFLAGS)" bash -c $(CXX) -c

%.o: %.cpp
    $(compile.cxx) $< -o $@

But I get this output:

CXXFLAGS="irrelevant" CPPFLAGS="irrelevant" bash -c g++ -c hello.cpp -o hello.o
g++: fatal error: no input files

Hence, it seems that g++ does not receive its arguments.