Skip to content

Instantly share code, notes, and snippets.

@charles-l
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save charles-l/ab9c2afbf2c5ac208488 to your computer and use it in GitHub Desktop.

Select an option

Save charles-l/ab9c2afbf2c5ac208488 to your computer and use it in GitHub Desktop.
Generic, minimal makefile that should work in most situations
LIBS="libname1 libname2"
IGNOREFILES := file1.c file2.c
BIN=binname
CC=gcc-4.9
###########################################################
#### NOTHING SHOULD NEED TO BE CHANGED BELOW THIS LINE ####
###########################################################
# Compiler options
CFLAGS=`pkg-config --cflags $(LIBS)` -I.
LDFLAGS=`pkg-config --libs $(LIBS)`
# Find project files
SOURCES=$(shell bash -c 'find . -name "*.c" $(foreach i, $(IGNOREFILES), -not -name "$(i)") -type f')
OBJ=$(SOURCES:.c=.o)
all: $(BIN)
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) -c $< -o $@
$(BIN): $(OBJ)
@echo LN $^
@$(CC) -o $@ $^ $(LDFLAGS)
clean:
@-rm -f $(OBJ) $(BIN)
@echo done cleaning
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment