.SILENT:

.SUFFIXES:      .cxx

SHELL=/bin/sh

BASEDIR = ../..
LIBDIR = ../../lib/libO/mingw32
BINDIR = ../../bin/mingw32
LIBNAME = $(LIBDIR)/$(LIBBASE)
INCLUDES = -I../../include  

default: 

depend:
	true $(INCLUDES) *.c *.cxx 2> /dev/null

init: 
	if (test -f .lastbuild.mingw32) then true ; else \
	  rm -f .lastbuild.* ; \
	  touch .lastbuild.mingw32 ; \
	fi
	$(MAKE) -s depend

clean:
	-rm -f .lastbuild.* *.o .libs 
	touch .lastbuild.mingw32

distclean: clean
	-rm -f *~ *.bak \#* *.old *.orig *.rej .\#*
	-rm -f .lastbuild.mingw32
	if (test -f Makefile.in) then rm Makefile; fi

maybeclean:
	if (test -f .lastbuild.mingw32) then true ; else \
	  echo "Host operating system has changed since last configuration.";\
	  echo "Re-run configure in directory ../.. and try again.";\
	  exit 10; \
	fi
	if (test -f .lastbuild.mingw32.O) then true ; else \
          echo "Removing all object files because the optimization level";\
	  echo "has changed since the last time the library was built.";\
	  $(MAKE) -s clean; \
	fi

CC_COMPILE=i686-pc-mingw32-gcc $(INCLUDES) -fPIC -O2  $(EXTRACFLAGS) 
CXX_COMPILE=i686-pc-mingw32-g++ $(INCLUDES) -fPIC -O2 $(EXTRACFLAGS) 

.c.o:
	echo Compiling $*.c
	$(CC_COMPILE) -c $*.c

.cxx.o:
	echo Compiling $*.cxx
	$(CXX_COMPILE) -c $*.cxx

library: $(LIBDIR) maybeclean

.libs: $(OBJECTS)
	echo 'Building $(ID_STRING) libraries'
	echo " "
	touch .lastbuild.mingw32.O
	echo "Creating static library using ar ruv"
	ar ruv $(LIBNAME).a $(OBJECTS)
	echo "Creating TOC for static library using /usr/bin/i686-pc-mingw32-ranlib"
	/usr/bin/i686-pc-mingw32-ranlib $(LIBNAME).a
	echo " "
	if (test "false" != "false") then \
	  echo "Creating shared library using false" ; \
	  rm -f $(LIBNAME).so* ; \
	  false $(LIBNAME).so.0.5.0 $(OBJECTS) ; \
	  echo "Creating links to dynamic library using ln -s" ; \
	  (cd $(LIBDIR) ; ln -s $(LIBBASE).so.0.5.0 $(LIBBASE).so.0.5) ; \
	  (cd $(LIBDIR) ; ln -s $(LIBBASE).so.0.5.0 $(LIBBASE).so.0) ; \
	  (cd $(LIBDIR) ; ln -s $(LIBBASE).so.0.5.0 $(LIBBASE).so) ; \
	  echo " " ; \
	fi
	touch .libs
	echo 'Done building $(ID_STRING) libraries'

$(LIBDIR): ../../lib/libO
	mkdir -p $(LIBDIR)
	touch $(LIBDIR)

../../lib/libO: ../../lib
	mkdir -p ../../lib/libO
	touch ../../lib/libO

../../lib:
	mkdir -p ../../lib

$(BINDIR): ../../bin
	mkdir -p $(BINDIR)
	touch $(BINDIR)

../../bin:
	mkdir -p ../../bin

Makefile: Makefile.in
	CONFIG_FILES=$(THIS_SRCDIR)/Makefile /bin/sh -c "cd $(TOP_SRCDIR) && ./config.status"
