Skip to content

Instantly share code, notes, and snippets.

@jkin0
Created August 26, 2023 15:15
Show Gist options
  • Save jkin0/197d1de9e095fa885a6a8933628e92b3 to your computer and use it in GitHub Desktop.
Save jkin0/197d1de9e095fa885a6a8933628e92b3 to your computer and use it in GitHub Desktop.
The perfect C Makefile script.
CC = gcc
CFLAGS = -Wall -Wextra -std=c18 -g
SRC_DIR = src
BUILD_DIR = build
EXE = exe
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
all: $(EXE)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(EXE): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
clean:
rm -rf $(BUILD_DIR)
rebuild: clean all
.PHONY: all clean rebuild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment