Skip to content

Instantly share code, notes, and snippets.

@Diviector
Last active January 10, 2024 10:02
Show Gist options
  • Save Diviector/1d23b2c022197f2b9ed80fe4549e2e04 to your computer and use it in GitHub Desktop.
Save Diviector/1d23b2c022197f2b9ed80fe4549e2e04 to your computer and use it in GitHub Desktop.
EXECUTABLE := app
ARGUMENTS := one two
BUILD_DIR := ./build
SRC_DIR := ./
INC_DIRS := ./
LIB_DIRS := ./
SRCS := $(shell find $(SRC_DIR) -name '*.cpp' -or -name '*.c')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
LIB_FLAGS := $(addprefix -L,$(LIB_DIRS))
CPPFLAGS := $(INC_FLAGS)
LDFLAGS := $(LIB_FLAGS)
CCFLAGS := $(INC_FLAGS)
CXXFLAGS := $(LIB_FLAGS)
$(BUILD_DIR)/$(EXECUTABLE): $(OBJS)
$(CXX) $^ $(LDFLAGS) -o $@
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CCFLAGS) -c $< -o $@
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
run: $(BUILD_DIR)/$(EXECUTABLE)
$< $(ARGUMENTS)
clean: $(BUILD_DIR)
rm -rf $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment