Skip to content

Instantly share code, notes, and snippets.

@ork
Last active January 8, 2022 17:29
Show Gist options
  • Save ork/11248510 to your computer and use it in GitHub Desktop.
Save ork/11248510 to your computer and use it in GitHub Desktop.
Generic C Makefile
EXEC = $(shell basename $$(pwd))
CC = gcc
CFLAGS = -std=gnu11 -O3 -Wall -Wextra -Wpedantic -Wstrict-aliasing
CFLAGS += $(shell pkg-config --cflags glib-2.0 gio-2.0)
LDFLAGS = $(shell pkg-config --libs glib-2.0 gio-2.0)
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
all: $(EXEC)
${EXEC}: $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
@rm -rf *.o
mrproper: clean
@rm -rf $(EXEC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment