
CFLAGS = -Wall
RESFLAGS = -D__WINDRES__=1

ifdef DEBUG
CFLAGS += -g -O0 -DDEBUG=1
RESFLAGS += -DDEBUG=1
endif

ifdef BETA
CFLAGS += -DBETA=1
RESFLAGS += -DBETA=1
else
ifdef OFFICIAL_BUILD
CFLAGS += -DOFFICIAL_BUILD=1
RESFLAGS += -DOFFICIAL_BUILD=1
endif
endif

SYS_LDFLAGS = -g -e _DriverEntry@8 -nostartfiles -nodefaultlibs -nostdlib -Wl,--subsystem,native,-shared,--image-base,0x10000
SYS_LIBS = -L../../../../lib/win32 -lntoskrnl

all: i386/fbportio.sys makedriver.exe fbportio_ctl.exe writedriver.exe fbportio_driver.h

clean:
	rm -fR *~ i386 *.o *.res *.exe *.sys

fbportio_driver.h: i386/fbportio.sys makedriver.exe
	makedriver

writedriver.exe: writedriver.o 
	gcc -o $@ $^

makedriver.exe: makedriver.o
	gcc -o $@ $^

fbportio_ctl.exe: fbportio_ctl.o
	gcc -o $@ $^

i386/fbportio.sys: fbportio.o fbportio_rc.o
	gcc $(SYS_LDFLAGS) -o $@ $^ $(SYS_LIBS)
ifndef DEBUG
	strip -s $@
endif

writedriver.o: writedriver.c fbportio_driver.h

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

%_rc.o: %.rc
	windres $(RESFLAGS) -o$@ $^
