Skip to content

Instantly share code, notes, and snippets.

@sidewinder040
Last active July 6, 2024 19:08
Show Gist options
  • Save sidewinder040/d34605f4bccfd3bf1e137de3d913910b to your computer and use it in GitHub Desktop.
Save sidewinder040/d34605f4bccfd3bf1e137de3d913910b to your computer and use it in GitHub Desktop.
A More Elegant Makefile Example
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -pedantic
# Source files
SRCS = datecode.c date_validator_helper.c main.c
# Object files
OBJS = $(SRCS:.c=.o)
# Target executable
TARGET = datecode
# Default target
all: $(TARGET)
# Link object files
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
# Compile source files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up
clean:
rm -f $(OBJS) $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment