39 lines
669 B
Makefile
39 lines
669 B
Makefile
# Project structure
|
|
SRCDIR = src
|
|
BUILDDIR = build
|
|
TARGET = bin/main
|
|
|
|
# Compiler and flags
|
|
CXX = g++
|
|
CXXFLAGS = -std=c++11 -Wall -Iinclude
|
|
LDFLAGS =
|
|
|
|
# Find all source files
|
|
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
|
|
|
# Generate object file names from source files
|
|
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRCS))
|
|
|
|
# Default target
|
|
all: $(TARGET)
|
|
|
|
# Link the program
|
|
$(TARGET): $(OBJS)
|
|
@mkdir -p $(@D)
|
|
$(CXX) $(LDFLAGS) -o $@ $^
|
|
|
|
# Compile source files into object files
|
|
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
|
|
@mkdir -p $(@D)
|
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
# Clean up
|
|
clean:
|
|
rm -rf $(BUILDDIR) bin
|
|
|
|
# Run the program
|
|
run: $(TARGET)
|
|
./$(TARGET)
|
|
|
|
.PHONY: all clean run
|