Changed Makefile so everything is beter organised.
This commit is contained in:
parent
747d8bbaf2
commit
82b5773b73
7 changed files with 66 additions and 31 deletions
97
Makefile
97
Makefile
|
|
@ -1,41 +1,76 @@
|
||||||
# Declaration of variables
|
CXX ?= g++
|
||||||
C = clang
|
|
||||||
COMMON_FLAGS = -Wall -MMD
|
|
||||||
C_FLAGS = $(COMMON_FLAGS)
|
|
||||||
CC = clang++
|
|
||||||
CC_FLAGS = $(COMMON_FLAGS) -std=c++17 # -funsafe-math-optimizations
|
|
||||||
LD_FLAGS =
|
|
||||||
INCLUDES =
|
|
||||||
|
|
||||||
# File names
|
# path #
|
||||||
EXEC = run
|
SRC_PATH = src
|
||||||
CSOURCES = $(wildcard *.c)
|
BUILD_PATH = build
|
||||||
COBJECTS = $(CSOURCES:.c=.o)
|
BIN_PATH = $(BUILD_PATH)/bin
|
||||||
SOURCES = $(wildcard *.cpp)
|
|
||||||
OBJECTS = $(SOURCES:.cpp=.o)
|
|
||||||
|
|
||||||
# Main target
|
# executable #
|
||||||
$(EXEC): $(COBJECTS) $(OBJECTS)
|
BIN_NAME = CppQuickStart
|
||||||
$(CC) $(COBJECTS) $(OBJECTS) -o $(EXEC) $(LD_FLAGS)
|
|
||||||
|
|
||||||
# To obtain C++ object files
|
# extensions #
|
||||||
%.o: %.cpp
|
SRC_EXT = cpp
|
||||||
$(CC) $(INCLUDES) $(CC_FLAGS) -o $@ -c $<
|
|
||||||
|
|
||||||
# To obtain C object files
|
# code lists #
|
||||||
%.o: %.c
|
# Find all source files in the source directory, sorted by
|
||||||
$(C) $(INCLUDES) $(C_FLAGS) -o $@ -c $<
|
# most recently modified
|
||||||
|
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
|
||||||
|
# Set the object file names, with the source directory stripped
|
||||||
|
# from the path, and the build path prepended in its place
|
||||||
|
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
|
||||||
|
# Set the dependency files that will be used to add header dependencies
|
||||||
|
DEPS = $(OBJECTS:.o=.d)
|
||||||
|
|
||||||
-include $(SOURCES:%.cpp=%.d)
|
# flags #
|
||||||
-include $(CSOURCES:%.c=%.d)
|
COMPILE_FLAGS = -std=c++17 -Wall -Wextra -g # -O3 -funsafe-math-optimizations
|
||||||
|
INCLUDES = -I include/ -I /usr/local/include
|
||||||
|
# Space-separated pkg-config libraries used by this project
|
||||||
|
LIBS =
|
||||||
|
|
||||||
# To generate the documentation
|
.PHONY: default_target
|
||||||
|
default_target: release
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS)
|
||||||
|
release: dirs
|
||||||
|
@$(MAKE) all
|
||||||
|
|
||||||
|
.PHONY: dirs
|
||||||
|
dirs:
|
||||||
|
@echo "Creating directories"
|
||||||
|
@mkdir -p $(dir $(OBJECTS))
|
||||||
|
@mkdir -p $(BIN_PATH)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@echo "Deleting $(BIN_NAME) symlink"
|
||||||
|
@$(RM) $(BIN_NAME)
|
||||||
|
@echo "Deleting directories"
|
||||||
|
@$(RM) -r $(BUILD_PATH)
|
||||||
|
@$(RM) -r $(BIN_PATH)
|
||||||
|
|
||||||
|
# checks the executable and symlinks to the output
|
||||||
|
.PHONY: all
|
||||||
|
all: $(BIN_PATH)/$(BIN_NAME)
|
||||||
|
@echo "Making symlink: $(BIN_NAME) -> $<"
|
||||||
|
@$(RM) $(BIN_NAME)
|
||||||
|
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
|
||||||
|
|
||||||
|
.PHONY: doc
|
||||||
doc:
|
doc:
|
||||||
doxygen Doxyfile
|
doxygen Doxyfile
|
||||||
|
|
||||||
# To remove generated files
|
# Creation of the executable
|
||||||
clean:
|
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
|
||||||
rm -f $(COBJECTS) $(OBJECTS) $(SOURCES:%.cpp=%.d) $(CSOURCES:%.c=%.d)
|
@echo "Linking: $@"
|
||||||
|
$(CXX) $(OBJECTS) -o $@ ${LIBS}
|
||||||
|
|
||||||
cleaner: clean
|
# Add dependency files, if they exist
|
||||||
rm -f $(EXEC)
|
-include $(DEPS)
|
||||||
|
|
||||||
|
# Source file rules
|
||||||
|
# After the first compilation they will be joined with the rules from the
|
||||||
|
# dependency files to provide header dependencies
|
||||||
|
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
|
||||||
|
@echo "Compiling: $< -> $@"
|
||||||
|
$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue