# I'm no expert at makefiles, i tried to keep this as similiar as possible to
# the makefile.linux from which i derived it. 
# Elias Pschernig elias@users.sourceforge.net

# I don't know any simple way to get the install dir, so let the user tell it

CC = mingw32-gcc
AR = mingw32-ar crus # create, replace, update, symbols

INCLUDE = -I../include
OUTPUT = NL.dll
LIBNAME = NL
STATIC = libNL_s.a
IMPORT = libNL.a
OPTFLAGS = -funroll-all-loops -ffast-math -fomit-frame-pointer -O2 -D_REENTRANT
CFLAGS = -Wall $(INCLUDE) $(OPTFLAGS)
LIBFLAGS = -shared -lwsock32
OBJECTS = crc.o errorstr.o nl.o sock.o group.o ipx.o err.o thread.o loopback.o mutex.o condition.o nltime.o

ifeq ($(OS),Windows_NT)
  SYSDIR = $(SystemRoot)/system32 # not sure about this, can someone test it under NT/2K ?
else
  SYSDIR = $(windir)/system # on win95/98/ME this is the path to the DLL dir
endif

LIBDIR = $(MINGDIR)/lib
INCDIR = $(MINGDIR)/include

.PHONY : clean

ifdef STATICLINK

all: $(OBJECTS)	
	@echo building static library
	$(AR) $(STATIC) $(OBJECTS)	
	
install:	
	copy $(STATIC) $(LIBDIR)		
	copy ../include/nl.h $(INCDIR)/nl.h	
	
uninstall:	
	del /f $(LIBDIR)/$(STATIC)
	del /f $(INCDIR)/nl.h	
	
clean:
	del /f $(OBJECTS) $(STATIC)	
	
else

all: $(OBJECTS)
	@echo building dynamic library, set STATICLINK for static lib
	$(CC) -o $(OUTPUT) $(OBJECTS) $(LIBFLAGS) $(CFLAGS) -Wl,--out-implib=$(IMPORT)
		
install:
	copy $(OUTPUT) $(SYSDIR)
	copy $(IMPORT) $(LIBDIR)		
	copy ../include/nl.h $(INCDIR)/nl.h		
	
uninstall:
	del /f $(SYSDIR)/$(OUTPUT)	
	del /f $(LIBDIR)/$(IMPORT)
	del /f $(INCDIR)/nl.h	
	
clean:
	del /f $(OBJECTS) $(OUTPUT) $(IMPORT)	
		
endif
	
crc.o: ../include/nl.h
err.o: nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h 
errorstr.o: wsock.h nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
group.o: nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
ipx.o: wsock.h nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
loopback.o: nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
mutex.o: nlinternal.h ../include/nl.h
nl.o: nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
sock.o: wsock.h nlinternal.h ../include/nl.h sock.h loopback.h serial.h parallel.h ipx.h
thread.o: nlinternal.h ../include/nl.h
condition.o: nlinternal.h ../include/nl.h
nltime: nlinternal.h ../include/nl.h

.PHONY : default
default: all	
