0

i was reading this post on makefile. I found that I cannot find where are the compiler and compilation flags defined. Normally they are defined as CXX and CFLAGS

i copied this makefile for my own testing project:

BUILD_DIR := /home/ubuntu/workspace/common/bin

vpath %.cpp /home/ubuntu/workspace/common/src

SRCS := basic_types.cpp

OBJS := ${SRCS:%.cpp=${BUILD_DIR}/%.o}  
foo: ${OBJS}
        @echo Linking $@ using $?
        @touch $@

${BUILD_DIR}/%.o: %.cpp      # <-- I had thought there will be some more specific 'rules' here
        @mkdir -p $(dir $@)
        @echo Compiling $< ...
        @touch $@

${SRCS}:
        @echo Creating $@
        @mkdir -p $(dir $@)
        @touch $@

.PHONY: clean

it compiles well, but i still cannot find any where to specify the complier. Is Make intelligently select the compiler (g++) for me based on surffix?

could anyone take a look and enlight me a bit? thanks a lot!

the original post on makefile

Community
  • 1
  • 1
James Bond
  • 7,533
  • 19
  • 50
  • 64
  • There don't appear to be any being set there but that's not a problem per-se. They may not have any that need specifying or, as they were out of scope, they may just not have bothered including them. What's your real question? – Etan Reisner Nov 19 '13 at 18:54
  • Do you mean that you want a list of predefined variables used in implicit rules in GNUMake, along with their default values? – Beta Nov 19 '13 at 19:00
  • Thanks guys. I have re-phased my question – James Bond Nov 19 '13 at 19:05

1 Answers1

1

Your question is a little unclear, since you've written a rule for object files that doesn't actually compile anything, but you say that "it compiles well".

There is an implicit rule that acts like this:

%.o: %.cpp
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

You can specify the compiler with a line like this:

CXX = g++

But g++ is already the default value of CXX.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • but there is no CXX in this makefile, right? so you mean make implicitely puts CXX in the rules? – James Bond Nov 19 '13 at 19:09
  • Make doesn't put CXX in the rules you write. If you write a rule for `${BUILD_DIR}/%.o`, and you want it to have a command that calls a compiler, you must put that command in the rule yourself. – Beta Nov 19 '13 at 19:18