# ---------- Variables listed below --------- # # Target directory BUILD = build # Paths to source, include, dependency, and object files SRC = src INC = inc DEP = $(BUILD)/dep OBJ = $(BUILD)/obj ALL = $(SRC) $(INC) $(BUILD) $(DEP) $(OBJ) # Executable TARGET := $(BUILD)/main.out $(BUILD)/demo.so # compiler and compiler flags CC = g++ CFLAGS = -I$(INC) SOFLAG = -fpic -shared -dynamic -ldl # list of static object files SOURCES = $(wildcard $(SRC)/*.cpp) OBJECTS = $(addprefix $(OBJ)/,$(notdir $(SOURCES:.cpp=.o))) # ----------- Targets listed below ---------- # # Some targets aren't real .PHONY: all clean run dump # Don't autodelete object files: .PRECIOUS: $(OBJ)/%.o all: $(DEP) $(OBJ) $(TARGET) dump: @echo "SOURCES: $(SOURCES)" @echo "OBJECTS: $(OBJECTS)" @echo " TARGET: $(TARGET)" @echo " PATHS: $(ALL)" clean: -rm -r $(BUILD) run: $(TARGET) -$(addprefix ./,$(addsuffix ;,$(TARGET))) # Create directories for output $(BUILD) $(DEP) $(OBJ): mkdir -p $@ # Make the executable $(BUILD)/%.out: $(OBJECTS) $(CC) $(CFLAGS) -o $@ $^ # Make the plugins $(BUILD)/%.so: $(OBJ)/%.o $(CC) $(CFLAGS) $(SOFLAG) -o $@ $^ # Make the object and dependency files $(OBJ)/%.o: $(SRC)/%.cpp $(CC) $(CFLAGS) -MMD -MF $(DEP)/$(@F:.o=.d) -o $@ -c $< # --------- Inclusions listed below --------- # # use dependencies when rebuilding -include $(wildcard $(DEP)/*.d)