Last active
December 17, 2021 04:58
-
-
Save SeedyROM/56dd3f1a95f9ab325b4adc8e8ca7e130 to your computer and use it in GitHub Desktop.
C Makefile Template (OOS Build)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TARGET_EXEC ?= a.out | |
# Where to build our resources | |
BUILD_DIR ?= ./build | |
# Where our code lives | |
SRC_DIRS ?= ./src | |
# Makefile magic to build object files and deps for our sources | |
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s) | |
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) | |
DEPS := $(OBJS:.o=.d) | |
# Compiler and other tool flags | |
CC := gcc | |
INC_DIRS := $(shell find $(SRC_DIRS) -type d) | |
INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | |
# Build our executable | |
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) | |
$(CC) $(OBJS) -o $@ $(LDFLAGS) | |
# Build the source objects | |
$(BUILD_DIR)/%.c.o: %.c | |
$(MKDIR_P) $(dir $@) | |
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ | |
.PHONY: clean | |
clean: | |
$(RM) -r $(BUILD_DIR) | |
-include $(DEPS) | |
MKDIR_P ?= mkdir -p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment