TARGET = vsun86

SRCS =				\
	main.cpp		\
	printf.cpp		\
	cpu.cpp			\
	pic.cpp			\
	irq.cpp			\
	disk.cpp		\
	disk/vdisk.cpp	\
	fs.cpp			\
	fs/fat.cpp		\
	keyboard.cpp	\
	timer.cpp		\
	rtc.cpp			\
	task.cpp		\
	disp.cpp		\
	video.cpp		\
	font.cpp		\
	shell.cpp

OBJS = $(SRCS:.cpp=_sim.o)
DEPS = $(SRCS:.cpp=_sim.d)

INCLUDE = -I.
DEFINES = -D_VSUN86_PCSIM -D__MSVCRT__

CC = gcc
CFLAGS += $(INCLUDE) $(DEFINES) -Werror -Wall -W -O2 `sdl-config --cflags`

CXX = g++
CXXFLAGS += $(INCLUDE) $(DEFINES) -Werror -Wall -W -O2 `sdl-config --cflags`

.PHONY: all
all: $(TARGET)

.PHONY: clean
clean:
	rm -f $(TARGET) $(OBJS) $(DEPS)

.PHONY: depend
depend: $(DEPS)

$(TARGET): $(DEPS) $(OBJS)
	$(CC) -o $@ $(OBJS) `sdl-config --libs`

%_sim.d: %.c
	$(CC) -MM $(CFLAGS) $< | sed 's%^$(*F).o:%$*_sim.o:%' | sed 's%:% $@: Makefile%' > $@

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

%_sim.d: %.cpp
	$(CXX) -MM $(CXXFLAGS) $< | sed 's%^$(*F).o:%$*_sim.o:%' | sed 's%:% $@: Makefile%' > $@

%_sim.o: %.cpp
	$(CXX) -c $(CXXFLAGS) -o $@ $<

-include $(DEPS)
