I have the following code in a cpp file that I'm trying to compile
Code:
#include <iostream>
using std::cout;
int main()
{
#if __DO_THIS__
cout << "do this\n";
#endif
#if __DO_THAT__
cout << "do that\n";
#endif
return 0;
}
And I'm trying to use this Makefile:
Code:
CXX = g++
CXXFLAGS = -Wall -c -D__DO_THIS__
CXXFLAGS2 = -Wall -c -D__DO_THAT__
OBJ_DIR =
OBJ_EXT = o86
SOURCES = main.cpp
OBJECTS = $(SOURCES:%.cpp=$(OBJ_DIR)%.$(OBJ_EXT))
main1: $(OBJECTS)
$(CXX) -o $@ $(OBJECTS)
$(OBJ_DIR)%.$(OBJ_EXT): %.cpp
$(CXX) $(CXXFLAGS) -o $@ $<
main2: $(OBJECTS)
$(CXX) -o $@ $(OBJECTS)
$(OBJ_DIR)%.$(OBJ_EXT): %.cpp
$(CXX) $(CXXFLAGS2) -o $@ $<
When I type "make main1" it compiles it using CXXFLAGS2, which I'm pretty sure it's because
Code:
$(OBJ_DIR)%.$(OBJ_EXT): %.cpp
was used twice. Is there a better/correct way to write this makefile so that I can compile the code with one set of compiler flags and then another set of compiler flags?