FLOAT_DIR := ../../../labs/floating-point
FLOAT_DIR_SRC := $(FLOAT_DIR)/src
FLOAT_DIR_INCLUDE := $(FLOAT_DIR)/include
SF_DIR := ./SoftFloat
SF_BUILD_DIR_LINUX := $(SF_DIR)/build/Linux-x86_64-GCC
SF_A_LINUX = $(SF_BUILD_DIR_LINUX)/softfloat.a
SF_BUILD_DIR_WINDOWS := $(SF_DIR)/build/Win64-MinGW-w64
SF_A_WINDOWS = $(SF_BUILD_DIR_WINDOWS)/softfloat.a

EXTRA_CFLAGS := -static -L$(SF_BUILD_DIR_WINDOWS) -L$(SF_BUILD_DIR_LINUX) -I$(FLOAT_DIR_INCLUDE)
SOURCES := main.c $(FLOAT_DIR_SRC)/internals.c $(FLOAT_DIR_SRC)/f16/print.c $(FLOAT_DIR_SRC)/f32/print.c

all: softfloat softfloat.exe

$(SF_A_LINUX):
	make -C $(SF_BUILD_DIR_LINUX)

$(SF_A_WINDOWS):
	make -C $(SF_BUILD_DIR_WINDOWS)

softfloat: $(SF_A_LINUX) $(SOURCES)
	gcc $(EXTRA_CFLAGS) -l:softfloat.a -o $@ $(SOURCES) $(SF_A_LINUX)

softfloat.exe: $(SF_A_WINDOWS) $(SOURCES)
	x86_64-w64-mingw32-gcc $(EXTRA_CFLAGS) -l:softfloat.a -o $@ $(SOURCES) $(SF_A_WINDOWS)

.PHONY: all
