# General Makefile for small C programs.
# Alexander Hiam
# 1/28/13
#
# Public Domain

# The name of the target executable:
TARGET  = hello_world

# Space seperated list of all source files:
SOURCES = main.c

# Space seperated directories to include:
INCLUDE_DIRS = include

# Compiler flags (e.g. optimization, links, etc.):
CFLAGS = -g -Wall

# Compiler:
CC = gcc
############################################################

# Append -I to eah include dir:
INCLUDES = $(foreach dir, $(INCLUDE_DIRS), -I$(dir))

# Create list of the object files:
OBJECTS = $(SOURCES:.c=.o)

all: $(OBJECTS)
	gcc $(CFLAGS) $(OBJECTS) -o $(TARGET)

%.o: %.c
	echo "Compiling $<"
	$(CC) -c $(CFLAGS) -o $@ $<
	gcc -MM $(CFLAGS) $*.c > $*.d

.PHONY:	clean
clean:
	rm -f *.o *.d