Skip to content

Instantly share code, notes, and snippets.

@tisyang
Last active December 15, 2017 01:50
Show Gist options
  • Save tisyang/74f349a8db718caf794e8f9c0681c6c6 to your computer and use it in GitHub Desktop.
Save tisyang/74f349a8db718caf794e8f9c0681c6c6 to your computer and use it in GitHub Desktop.
Simple makefile template
TARGET = prog
LIBS = -lm
CC = gcc
CFLAGS = -g -Wall
.PHONY: default all clean
default: $(TARGET)
all: default
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall $(LIBS) -o $@
clean:
-rm -f *.o
-rm -f $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment