Skip to content

Instantly share code, notes, and snippets.

@lithammer
Last active February 7, 2017 21:46
Show Gist options
  • Save lithammer/cd06310c65ff4047928aae3b7623e0b5 to your computer and use it in GitHub Desktop.
Save lithammer/cd06310c65ff4047928aae3b7623e0b5 to your computer and use it in GitHub Desktop.
Basic Makefile for C
TARGET = <binary name>
CFLAGS = -g -Wall -Wextra $(OPTFLAGS)
CC ?= llvm-gcc
BUILDDIR = build
DISTDIR = dist
HEADERS := $(wildcard src/**/*.h src/*.h)
SRC := $(wildcard src/**/*.c src/*.c)
OBJS := $(SRC:.c=.o)
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(OBJS) -Wall $(LIBS) -o $@
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
@$(RM) -v $(OBJS) $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment