Skip to content

Instantly share code, notes, and snippets.

@alkavan
Created April 25, 2013 17:16
Show Gist options
  • Save alkavan/5461441 to your computer and use it in GitHub Desktop.
Save alkavan/5461441 to your computer and use it in GitHub Desktop.
# Generic Makefile for compiling an executable, with pkg-config dependencies.
CC := clang
PKGS := gtk+-3.0
SRCDIR := src
BUILDDIR := build
CFLAGS := -g -Wall `pkg-config --cflags $(PKGS)`
LIBS := `pkg-config --libs $(PKGS)`
TARGET := app
SRCEXT = c
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
DEPS := $(OBJECTS:.o=.deps)
$(TARGET): $(OBJECTS)
@echo " Linking..."; $(CC) $^ -o $(TARGET) $(LIBS)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR)
@echo " CC $<"; $(CC) $(CFLAGS) -MD -MF $(@:.o=.deps) -c -o $@ $<
clean:
@echo " Cleaning..."; $(RM) -r $(BUILDDIR) $(TARGET)
-include $(DEPS)
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment