-
-
Save zobayer1/7265c698d1b024bb7723bc624aeedeb3 to your computer and use it in GitHub Desktop.
| # Pre-compiler and Compiler flags | |
| CXX_FLAGS := -Wall -Wextra -std=c++17 -ggdb | |
| PRE_FLAGS := -MMD -MP | |
| # Project directory structure | |
| BIN := bin | |
| SRC := src | |
| LIB := lib | |
| INC := include | |
| MAINFILE := $(SRC)/main.cpp | |
| # Build directories and output | |
| TARGET := $(BIN)/main | |
| BUILD := build | |
| # Library search directories and flags | |
| EXT_LIB := | |
| LDFLAGS := | |
| LDPATHS := $(addprefix -L,$(LIB) $(EXT_LIB)) | |
| # Include directories | |
| INC_DIRS := $(INC) $(shell find $(SRC) -type d) | |
| INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | |
| # Construct build output and dependency filenames | |
| SRCS := $(shell find $(SRC) -name *.cpp) | |
| OBJS := $(subst $(SRC)/,$(BUILD)/,$(addsuffix .o,$(basename $(SRCS)))) | |
| DEPS := $(OBJS:.o=.d) | |
| # Run task | |
| run: build | |
| @echo "🚀 Executing..." | |
| ./$(TARGET) $(ARGS) | |
| # Build task | |
| build: clean all | |
| # Main task | |
| all: $(TARGET) | |
| # Task producing target from built files | |
| $(TARGET): $(OBJS) | |
| @echo "🚧 Building..." | |
| mkdir -p $(dir $@) | |
| $(CXX) $(OBJS) -o $@ $(LDPATHS) $(LDFLAGS) | |
| # Compile all cpp files | |
| $(BUILD)/%.o: $(SRC)/%.cpp | |
| mkdir -p $(dir $@) | |
| $(CXX) $(CXX_FLAGS) $(PRE_FLAGS) $(INC_FLAGS) -c -o $@ $< $(LDPATHS) $(LDFLAGS) | |
| # Clean task | |
| .PHONY: clean | |
| clean: | |
| @echo "🧹 Clearing..." | |
| rm -rf build | |
| # Include all dependencies | |
| -include $(DEPS) |
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added:
FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServicesand appended it to# Task producing target from built files.I had to remove
$(LDPATHS) $(LDFLAGS)from the# Compile all cpp filesstage as I got warnings about unused flags. Is this normal?
Did you need to remove both or may be just LDPATHS. Are they empty? They are set in the # Library search directories and flags section.
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added:FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServicesand appended it to# Task producing target from built files.
I had to remove$(LDPATHS) $(LDFLAGS)from the# Compile all cpp filesstage as I got warnings about unused flags. Is this normal?Did you need to remove both or may be just LDPATHS. Are they empty? They are set in the
# Library search directories and flagssection.
I had to remove both from the # Compile all cpp files section. I do have them set to something. But it seems those flags were only used in # Task producing target from built files.
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added:
FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServicesand appended it to# Task producing target from built files.I had to remove
$(LDPATHS) $(LDFLAGS)from the# Compile all cpp filesstage as I got warnings about unused flags. Is this normal?