#
# Makefile for my4th swiss-knife tool
#


SRC = my4th_microcode.c mynor_microcode.c my4th-xs_microcode.c \
      vcd.c cpu.c ioports.c eeprom.c input.c uart.c timing.c \
      forthfmt.c opsystem.c xfer-uart.c transfer.c main.c

TARGET = $(OUTPUTDIR)my4th

CC = gcc

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -D_DEBUG -DDEBUG
else
  DEBFLAGS = -O2
endif

HOST:= LINUX
ifeq '$(strip $(basename $(notdir $(SHELL))))' 'cmd'
HOST:= WINDOWS
endif
ifeq '$(suffix $(SHELL))' '.exe'
HOST:= WINDOWS
endif

ifeq ($(HOST),WINDOWS)
  CFLAGS = -D_WINDOWS
else
  CFLAGS = -pthread -D_LINUX
endif

CFLAGS += -Wall $(DEBFLAGS)

all: .depend $(TARGET)

$(TARGET): $(SRC:.c=.o)
	$(CC) $(CFLAGS) -o $(TARGET) $^

clean:
	rm -f *.o $(TARGET) $(TARGET).exe *~ core .depend *.bak

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > $@


ifeq (.depend,$(wildcard .depend))
include .depend
endif

