Skip to content

Instantly share code, notes, and snippets.

@michaelfm1211
Last active July 27, 2023 01:26
Show Gist options
  • Save michaelfm1211/8425e0f3bae0504530f5c3c2ea594075 to your computer and use it in GitHub Desktop.
Save michaelfm1211/8425e0f3bae0504530f5c3c2ea594075 to your computer and use it in GitHub Desktop.
generic makefile for simple c projects
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)
PROG_NAME := example_placeholder
CFLAGS += -Wall -Wextra -c
LDFLAGS +=
# Production
.PHONY: all
all: CLFAGS += -O2
all: $(PROG_NAME)
# Development
.PHONY: debug
debug: CFLAGS += -O0 -g -fsanitize=address
debug:
$(CC) $(CFLAGS) $(LDFLAGS) -o $(PROG_NAME) $(SRCS)
%.o: %.c
@$(CC) $(CFLAGS) -o $@ $?
@echo "[CC] $@"
$(PROG_NAME): $(OBJS)
@$(CC) $(LDFLAGS) -o $(PROG_NAME) $^
@echo "[LD] $@"
.PHONY: clean
clean:
rm -rf $(OBJS) $(PROG_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment