# Makefile for Spector: A Chessplaying Program
# Steven James Edwards, 1996
#
# Usage:
#   make            build ./spector
#   make clean      remove object files
#   make distclean  remove object files and the spector binary
#   make CC=clang   build with a different compiler
#   make DEBUG=1    build with debug symbols and no optimization

CC      ?= cc
TARGET   = spector

SRCS    := $(wildcard *.c)
OBJS    := $(SRCS:.c=.o)
DEPS    := $(SRCS:.c=.d)

CFLAGS  ?= -O2
CFLAGS  += -MMD -MP
LDLIBS  := -lm

ifdef DEBUG
CFLAGS  += -g -O0
endif

.PHONY: all clean distclean

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS)

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	rm -f $(OBJS) $(DEPS)

distclean: clean
	rm -f $(TARGET)

-include $(DEPS)
