LIBRARY= libpng16

CC = kos32-gcc
AR = kos32-ar
LD = kos32-ld
STRIP = kos32-strip

INSTALLDIR ?= /home/autobuild/tools/win32/lib

CFLAGS = -UWIN32 -UWindows -U_WINDOWS -U_WIN32 -U__WIN32__ -c -O2 -fno-ident -fomit-frame-pointer

LDFLAGS=$(LDFLAGS_CMD)
LDFLAGS+= -shared -s -T dll.lds --entry _DllStartup --image-base=0
LDFLAGS+=  --out-implib $(LIBRARY).dll.a
 
ARFLAGS:= crs

INCLUDES= -I. -I../newlib/libc/include -I../zlib

LIBS:=  -ldll -lc.dll -lz.dll

DEFS = -DHAVE_CONFIG_H

LIBPNG_DEFINES = -DPNG_CONFIGURE_LIBPNG 

DEFINES= $(DEFS) $(LIBPNG_DEFINES)

ifeq ($(findstring ebox,$(MAKECMDGOALS)),ebox)
CFLAGS+=-march=pentium-mmx
endif


SOURCES = png.c pngerror.c pngget.c pngmem.c pngpread.c	\
	  pngread.c pngrio.c pngrtran.c pngrutil.c	\
	  pngset.c pngtrans.c pngwio.c pngwrite.c 	\
	  pngwtran.c pngwutil.c
 

OBJECTS =  $(patsubst %.c, %.o, $(SOURCES))


# targets 


all:$(LIBRARY).a $(LIBRARY).dll

ebox:$(LIBRARY).a $(LIBRARY).dll

$(LIBRARY).a: $(OBJECTS) Makefile
	$(AR) $(ARFLAGS) $(LIBRARY).a $(OBJECTS)
	mv -f $(LIBRARY).a $(INSTALLDIR)

$(LIBRARY).dll: libpng16.def $(OBJECTS) Makefile
	$(LD) $(LDFLAGS) -o $@  libpng16.def $(OBJECTS) $(LIBS)
	$(STRIP) $@
	#sed -f ../newlib/cmd1.sed libpng16.def > mem
	#sed -f ../newlib/cmd2.sed mem >libpng.inc
	mv -f $@ ../../bin
	mv -f $(LIBRARY).dll.a $(INSTALLDIR)


%.o : %.c Makefile
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<

clean: 
	-rm -f *.o 




