CC = gcc
CFLAGS = -Wall
DFLAGS =
OFLAGS = -O3
WFLAGS =

ifeq ($(debug),1)
	DFLAGS = -g -DDEBUG
	OFLAGS =
endif
ifeq ($(mswindows),1)
	WFLAGS = -DMSWINDOWS
endif

.SUFFIXES:
.SUFFIXES: .c .o
.SUFFIXES: .s .o

.c.o:
	$(CC) -c $(CFLAGS) $(DFLAGS) $(OFLAGS) $(WFLAGS) $<

needle_objs = main.o edit.o chessclock.o kmoves.o \
nmoves.o rmoves.o moves.o zobristkeys.o console.o thinking.o \
evaluate.o board_debug.o xboardclient.o

ifneq ($(asm),1)
	foreign_objs = n_strtok_r.o my_bsf.o
else
ifeq ($(mswindows),1)
	foreign_objs = n_strtok_r.o bsf64_win.o
else
	foreign_objs = n_strtok_r.o bsf64.o
endif
endif

all: needle

needle: $(needle_objs) $(foreign_objs)
ifeq ($(debug),1)
	$(CC) $(CFLAGS) $(DFLAGS) $(OFLAGS) $(WFLAGS) $(needle_objs) $(foreign_objs) -o needle
else
	$(CC) $(CFLAGS) $(DFLAGS) $(OFLAGS) $(WFLAGS) $(needle_objs) $(foreign_objs) -o needle
ifeq ($(mswindows),1)
	-strip --strip-all needle.exe
else
	-strip --strip-all needle
endif
endif

clean:
	rm -f *~
	rm -f *.o
	rm -f needle
	rm -f needle.exe
	rm -f needle.err
	rm -f core
