Last active
October 22, 2020 22:30
-
-
Save BKreisel/48168f3b3ce2a8ac8a04e3f960de8287 to your computer and use it in GitHub Desktop.
Generic C Project Makefile
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
CC = gcc | |
SRC_DIR = ./src | |
BIN_DIR = ./bin | |
EXE_SRC_DIR = $(SRC_DIR)/bin | |
BUILD_DIR = ./build | |
INCLUDES_DIR = ./include | |
CFLAGS = -Wall -Wextra -pedantic -std=c99 -I$(INCLUDES_DIR) | |
EXES = $(notdir $(patsubst %.c, %, $(wildcard $(EXE_SRC_DIR)/*.c))) | |
ALL = $(addprefix $(BIN_DIR)/, $(EXES)) | |
SRC_LIST = $(wildcard $(SRC_DIR)/*.c) | |
OBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(patsubst %.c, %.o, $(SRC_LIST)))) | |
# Make Directories | |
$(shell mkdir -p $(BUILD_DIR) >/dev/null) | |
$(shell mkdir -p $(BIN_DIR) >/dev/null) | |
.PHONY: all | |
all: $(ALL) | |
.PHONY: debug | |
debug: CFLAGS += -D _DEBUG | |
debug: $(ALL) | |
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | |
$(CC) $(CFLAGS) -c -o $@ $< | |
$(ALL): $(OBJS) | |
$(CC) $(CFLAGS) -o $@ $(addprefix $(EXE_SRC_DIR)/, $(@F).c) $(OBJS) | |
.PHONY: clean | |
clean: | |
rm -f $(BUILD_DIR)/*.o | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment