#
#  wxWindows/Unix main source makefile
#
#  Copyright 1998, Markus Holzhem and Robert Roebling
#

# wxWindows base directory
WXBASEDIR=@WXBASEDIR@

# set the OS type for compilation
OS=@OS@

# compile a library only
RULE=gslib

# define source file for odbc
IODBC_C_SRC=\
  iodbc/catalog.c \
  iodbc/connect.c \
  iodbc/dlf.c \
  iodbc/dlproc.c \
  iodbc/execute.c \
  iodbc/fetch.c \
  iodbc/hdbc.c \
  iodbc/henv.c \
  iodbc/herr.c \
  iodbc/hstmt.c \
  iodbc/info.c \
  iodbc/itrace.c \
  iodbc/misc.c \
  iodbc/prepare.c \
  iodbc/result.c

# define source file for jpeg
JPEG_C_SRC=\
  jpeg/jcapimin.c \
  jpeg/jcapistd.c \
  jpeg/jccoefct.c \
  jpeg/jccolor.c \
  jpeg/jcdctmgr.c \
  jpeg/jchuff.c \
  jpeg/jcinit.c \
  jpeg/jcmainct.c \
  jpeg/jcmarker.c \
  jpeg/jcmaster.c \
  jpeg/jcomapi.c \
  jpeg/jcparam.c \
  jpeg/jcphuff.c \
  jpeg/jcprepct.c \
  jpeg/jcsample.c \
  jpeg/jctrans.c \
  jpeg/jdapimin.c \
  jpeg/jdapistd.c \
  jpeg/jdatadst.c \
  jpeg/jdatasrc.c \
  jpeg/jdcoefct.c \
  jpeg/jdcolor.c \
  jpeg/jddctmgr.c \
  jpeg/jdhuff.c \
  jpeg/jdinput.c \
  jpeg/jdmainct.c \
  jpeg/jdmarker.c \
  jpeg/jdmaster.c \
  jpeg/jdmerge.c \
  jpeg/jdphuff.c \
  jpeg/jdpostct.c \
  jpeg/jdsample.c \
  jpeg/jdtrans.c \
  jpeg/jerror.c \
  jpeg/jfdctflt.c \
  jpeg/jfdctfst.c \
  jpeg/jfdctint.c \
  jpeg/jidctflt.c \
  jpeg/jidctfst.c \
  jpeg/jidctint.c \
  jpeg/jidctred.c \
  jpeg/jquant1.c \
  jpeg/jquant2.c \
  jpeg/jutils.c \
  jpeg/jmemmgr.c \
  jpeg/jmemnobs.c 

# define source file for png
PNG_C_SRC=\
 png/png.c \
 png/pngset.c \
 png/pngget.c \
 png/pngrutil.c \
 png/pngtrans.c \
 png/pngwutil.c \
 png/pngread.c \
 png/pngrio.c \
 png/pngwio.c \
 png/pngwrite.c \
 png/pngrtran.c \
 png/pngwtran.c \
 png/pngmem.c \
 png/pngerror.c \
 png/pngpread.c
 
# define source file for zlib
Z_C_SRC=\
 zlib/adler32.c \
 zlib/compress.c \
 zlib/crc32.c \
 zlib/gzio.c \
 zlib/uncompr.c \
 zlib/deflate.c \
 zlib/trees.c \
 zlib/zutil.c \
 zlib/inflate.c \
 zlib/infblock.c \
 zlib/inftrees.c \
 zlib/infcodes.c \
 zlib/infutil.c \
 zlib/inffast.c
 
# include gtk.inc, qt.inc or motif.inc here
include @MAKEINCLUDE@

# determine library names
STATIC_LIBRARY=lib$(LIB_TARGET).a
SHARED_LIBRARY=lib$(LIB_TARGET).so.$(LIB_MAJOR).$(LIB_MINOR)

LIB_CPP_ALL_SRC=$(LIB_CPP_SRC) @UNIX_THREAD@
# @GTK_JOYSTICK@

LIB_C_ALL_SRC=$(LIB_C_SRC) @IODBC_C_SRC@ @PNG_C_SRC@ @Z_C_SRC@ @JPEG_C_SRC@ parser.c

#define library objects
LIB_OBJ=\
 $(LIB_CPP_ALL_SRC:.cpp=.o) \
 $(LIB_C_ALL_SRC:.c=.o)

all::
	@if test ! -d gtk; then mkdir gtk; fi
	@if test ! -d qt; then mkdir qt; fi
	@if test ! -d motif; then mkdir motif; fi
	@if test ! -d motif/xmcombo; then mkdir motif/xmcombo; fi
	@if test ! -d common; then mkdir common; fi
	@if test ! -d unix; then mkdir unix; fi
	@if test ! -d generic; then mkdir generic; fi
	@if test ! -d png; then mkdir png; fi
	@if test ! -d jpeg; then mkdir jpeg; fi
	@if test ! -d zlib; then mkdir zlib; fi
	@if test ! -d iodbc; then mkdir iodbc; fi

install::
	@echo " "
	@echo "Installing library files and headers.."
	@echo " "
	@echo "  Creating directories.."
	@$(WXBASEDIR)/mkinstalldirs \
	   $(includedir)/wx \
	   $(includedir)/wx/gtk \
	   $(includedir)/wx/motif \
	   $(includedir)/wx/unix \
	   $(includedir)/wx/generic \
	   $(includedir)/wx/protocol \
	   $(libdir)/wx/include/wx/gtk \
	   $(libdir) \
	   $(bindir)
	@echo "  Copying headers from /include/wx"
	@cd $(WXBASEDIR)/include/wx ; \
	$(INSTALL) -d $(includedir)/wx ; \
	for f in *.h ; do \
	  rm -f $(includedir)/wx/$$f ; \
	  $(INSTALL_DATA) $$f $(includedir)/wx/$$f ; \
	done ; \
	for f in *.cpp ; do \
	  rm -f $(includedir)/wx/$$f ; \
	  $(INSTALL_DATA) $$f $(includedir)/wx/$$f ; \
	done
	@if test "@TOOLKIT@" = "GTK" ; then \
	  echo "  Copying headers from /include/wx/gtk" ; \
	  cd $(WXBASEDIR)/include/wx/gtk ; \
	  $(INSTALL) -d $(includedir)/wx/gtk ; \
	  for f in *.h ; do \
	    rm -f $(includedir)/wx/gtk/$$f ; \
	    $(INSTALL_DATA) $$f $(includedir)/wx/gtk/$$f ; \
	  done ; \
	fi
	@if test "@TOOLKIT@" = "MOTIF" ; then \
	  echo "  Copying headers from /include/wx/motif" ; \
	  cd $(WXBASEDIR)/include/wx/motif ; \
	  $(INSTALL) -d $(includedir)/wx/motif ; \
	  for f in *.h ; do \
	    rm -f $(includedir)/wx/motif/$$f ; \
	    $(INSTALL_DATA) $$f $(includedir)/wx/motif/$$f ; \
	  done ; \
	fi
	@echo "  Copying headers from /include/wx/generic"
	@cd $(WXBASEDIR)/include/wx/generic ; \
	$(INSTALL) -d $(includedir)/wx/generic ; \
	for f in *.h ; do \
	  rm -f $(includedir)/wx/generic/$$f ; \
	  $(INSTALL_DATA) $$f $(includedir)/wx/generic/$$f ; \
	done
	@echo "  Copying headers from /include/wx/protocol"
	@cd $(WXBASEDIR)/include/wx/protocol ; \
	for f in *.h ; do \
	  rm -f $(includedir)/wx/protocol/$$f ; \
	  $(INSTALL_DATA) $$f $(includedir)/wx/protocol/$$f ; \
	done
	@echo "  Copying headers from /include/wx/unix"
	@cd $(WXBASEDIR)/include/wx/unix ; \
	for f in *.h ; do \
	  rm -f $(includedir)/wx/unix/$$f ; \
	  $(INSTALL_DATA) $$f $(includedir)/wx/unix/$$f ; \
	done
	@echo "  Moving setup.h to library path"
	@if test "@TOOLKIT@" = "GTK" ; then \
	  cd $(WXBASEDIR)/src ; \
	  $(INSTALL) -d $(libdir)/wx/include/wx/gtk ; \
	  mv $(includedir)/wx/gtk/setup.h $(libdir)/wx/include/wx/gtk/setup.h ; \
	fi
	@if test "@TOOLKIT@" = "MOTIF" ; then \
	  cd $(WXBASEDIR)/src ; \
	  $(INSTALL) -d $(libdir)/wx/include/wx/motif ; \
	  mv $(includedir)/wx/motif/setup.h $(libdir)/wx/include/wx/motif/setup.h ; \
	fi
	@echo "  Copying wx-config"
	@cd $(WXBASEDIR)/src ; \
	  $(INSTALL) -d $(bindir) ; \
	  rm -f $(bindir)/wx-config ; \
	  $(INSTALL_PROGRAM) $(WXBASEDIR)/wx-config $(bindir)/wx-config
	@echo "  Copying static library"
	@cd $(WXBASEDIR)/src ; \
	  rm -f $(libdir)/$(STATIC_LIBRARY) ; \
	  $(INSTALL_DATA) $(WXBASEDIR)/lib/$(OS)/$(STATIC_LIBRARY) $(libdir)/$(STATIC_LIBRARY)
	@if test -f $(WXBASEDIR)/lib/$(OS)/$(SHARED_LIBRARY) ; then \
	  echo "  Copying shared library" ; \
	    rm -f $(libdir)/lib$(LIB_TARGET).so* ; \
	    $(INSTALL_PROGRAM) $(WXBASEDIR)/lib/$(OS)/$(SHARED_LIBRARY) $(libdir)/$(SHARED_LIBRARY) ; \
	    $(STRIP) $(libdir)/$(SHARED_LIBRARY) ; \
	    $(LN_S) $(SHARED_LIBRARY) $(libdir)/lib$(LIB_TARGET).so.$(LIB_MAJOR) ; \
	    $(LN_S) $(SHARED_LIBRARY) $(libdir)/lib$(LIB_TARGET).so ; \
	    echo " " ; \
	    echo "  You may have to run ldconfig!" ; \
	    echo " " ; \
	fi
	@echo " "
	@echo "Installation complete."
	@echo " "
	
clean::
	$(RM) -rf gtk
	$(RM) -rf qt
	$(RM) -rf motif
	$(RM) -rf common
	$(RM) -rf unix
	$(RM) -rf generic
	$(RM) -rf png
	$(RM) -rf jpeg
	$(RM) -rf zlib
	$(RM) -rf iodbc
	@$(RM) lexer.c parser.c

#additional things needed for compile
ADD_COMPILE=

# include the definitions now
include ../../template.mak

# things for the prolog stuff

parser.c: ../common/parser.y lexer.c 
	@if test ! -f parser.y; then \
	  cp -f ../common/parser.y . ; \
	fi
	@$(YACC) parser.y
	@sed -e "s/y.tab.c/parser.y/g"       < y.tab.c | \
	sed -e "s/BUFSIZ/5000/g"            | \
	sed -e "s/YYLMAX 200/YYLMAX 5000/g" | \
	sed -e "s/yy/PROIO_yy/g"            | \
	sed -e "s/input/PROIO_input/g"      | \
	sed -e "s/unput/PROIO_unput/g"      > parser.c
	@$(RM) y.tab.c
	@$(RM) parser.y

lexer.c: ../common/lexer.l
	@if test ! -f lexer.l; then \
	  cp -f ../common/lexer.l . ;\
	fi
	@$(LEX) lexer.l
	@sed -e "s/lex.yy.c/lexer.l/g"       < lex.yy.c | \
	sed -e "s/yy/PROIO_yy/g"            | \
	sed -e "s/input/PROIO_input/g"      | \
	sed -e "s/unput/PROIO_unput/g"      > lexer.c
	@$(RM) lex.yy.c
	@$(RM) lexer.l

clean::