Skip to content

Instantly share code, notes, and snippets.

@matutter
Created March 17, 2017 15:44
Show Gist options
  • Select an option

  • Save matutter/877ca1aa4a62f57bdfaa6713e2b3c857 to your computer and use it in GitHub Desktop.

Select an option

Save matutter/877ca1aa4a62f57bdfaa6713e2b3c857 to your computer and use it in GitHub Desktop.
A makefile to make all intermediate objects and compile the a main executable
##
# Sources are expected to be layed out like so
# .
# ├── makefile
# └── src
# ├── hashing
# │   ├── hash.c
# │   └── hash.h
# └── main.c
#
.RECIPEPREFIX = |
.PHONE: all info clean setup run
CC = gcc
CINCL = -Isrc
CFLAGS = -g
SOURCES := $(shell find src/ -name *.c -not -path src/*.c)
OBJECTS := $(SOURCES:.c=.o)
EXEC := main.o
all: setup ${EXEC}
${EXEC}: ${OBJECTS} src/main.c
| ${CC} ${CINCL} ${CFLAGS} $^ -o $@
%.o:%.c
| ${CC} -c ${CINCL} ${CFLAGS} $< -o $@
info:
|@ echo "Sources: ${SOURCES}"
|@ echo "Objects: ${OBJECTS}"
clean:
| rm -f ${OBJECTS} ${EXEC}
run: all
|@ ./${EXEC}
setup:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment