# ==============================================================================
#  Makefile  for  D
# ==============================================================================
TARGET      = sal.lib
MAKE        = make
DMD         = dmd
INCLUDE     = -Isrc
DFLAGS      = -release -O -w
LFLAGS      = -release -lib
LIB         =
#LIB         = ws2_32.lib

SOURCES     = $(wildcard src/*.d src/*/*.d src/*/*/*.d src/*/*/*/*.d)
BACKUP_OBJS = $(SOURCES:.d=.d~)
DOCDIR      = docs

OBJS        = $(SOURCES:.d=.obj)

.SUFFIXES: .d .obj

# for unittest
ifeq ($(MAKECMDGOALS), test)
DFLAGS = -O -g -unittest -cov -w
LFLAGS = -lib
endif

all: $(TARGET)

$(TARGET): $(OBJS)
	$(DMD) $(LFLAGS) -of$(TARGET) $(OBJS) $(LIB)

.d.obj:
	$(DMD) -Dd$(DOCDIR) $(INCLUDE) -of$@ -c $(DFLAGS) $<

test: $(TARGET)
	cd unittest; $(MAKE)

clean:
	cd unittest; $(MAKE) clean
	rm -rf $(OBJS) $(BACKUP_OBJS) *.map $(TARGET) $(DOCDIR)/*.html
	rm -rf *.lst
	rm -rf *~

