Skip to content

Instantly share code, notes, and snippets.

@aprell
Created February 6, 2019 13:06
Show Gist options
  • Select an option

  • Save aprell/a0f53bb3536bcd2fa29ee71f8037917d to your computer and use it in GitHub Desktop.

Select an option

Save aprell/a0f53bb3536bcd2fa29ee71f8037917d to your computer and use it in GitHub Desktop.
A simple Makefile template
CPPFLAGS +=
CFLAGS += -Wall -Wextra -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
ifeq ($(CC),clang)
# ...
else
# Assume gcc
CC := gcc
# ...
endif
SRCS := test.c
OBJS := $(SRCS:.c=.o)
BINS := $(SRCS:.o=)
all: $(BINS)
test: CFLAGS += -O2
test: LDFLAGS += -O2
depend: $(SRCS)
$(CC) $(CFLAGS) $(CPPFLAGS) -MM $^ > depend
clean:
rm -rf depend $(OBJS) $(BINS)
-include depend
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment