#*---------------------------------------------------------------------*/
#*   A pratical implementation for the Scheme programming language     */
#*                                                                     */
#*                                    ,--^,                            */
#*                              _ ___/ /|/                             */
#*                          ,;'( )__, ) '                              */
#*                         ;;  //   L__.                               */
#*                         '   \\   /  '                               */
#*                              ^   ^                                  */
#*                                                                     */
#*   Copyright (c) 1992-1999 Manuel Serrano                            */
#*                                                                     */
#*     Bug descriptions, use reports, comments or suggestions are      */
#*     welcome. Send them to                                           */
#*       bigloo-request@kaolin.unice.fr                                */
#*       http://kaolin.unice.fr/bigloo                                 */
#*                                                                     */
#*   This program is free software; you can redistribute it            */
#*   and/or modify it under the terms of the GNU General Public        */
#*   License as published by the Free Software Foundation; either      */
#*   version 2 of the License, or (at your option) any later version.  */
#*                                                                     */
#*   This program is distributed in the hope that it will be useful,   */
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of    */
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     */
#*   GNU General Public License for more details.                      */
#*                                                                     */
#*   You should have received a copy of the GNU General Public         */
#*   License along with this program; if not, write to the Free        */
#*   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   */
#*   MA 02111-1307, USA.                                               */
#*---------------------------------------------------------------------*/
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/xlib/Makefile                        */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Mon Dec  4 10:25:59 1995                          */
#*    Last change :  Sun Jan 25 10:21:19 1998 (serrano)                */
#*    -------------------------------------------------------------    */
#*    This makefile build the X11 Bigloo declaration and the examples  */
#*    using the Xlib with Bigloo.                                      */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*     Les flags ...                                                   */
#*---------------------------------------------------------------------*/
INCLUDEDIR	= /usr/include
XINCLUDEDIR	= $(INCLUDEDIR)/X11
CC              = gcc
BIGLOO          = bigloo
CIGLOO		= cigloo
CGFLAGS		= -w -type Status -type Bool -type wchar_t -no-directives -macro -no-define-fun
CPPFLAGS	= -DNeedFunctionPrototypes=1 -D_Xconst= -I$(XINCLUDEDIR) -I$(INCLUDEDIR)
AFILE           = .afile
SHELL           = /bin/sh
CLEAN		= cleaning
BACKUPDIR	= $$HOUSE/backup
BACKUPNAME	= xlib
POPULATION	= Makefile README xlib-macro.sch example include
                  
#*---------------------------------------------------------------------*/
#*    Les flags par defauts (pour pouvoir faire make *.o)              */
#*---------------------------------------------------------------------*/
BDBGFLAGS	= -afile $(AFILE) -g2 -cg -O -cc $(CC) +rm -fsharing
DOPTFLAGS	= -afile $(AFILE) -O2 -cc $(CC) -rm -fsharing -unsafe
BFLAGS		= $(BDBGFLAGS)
CFLAGS          = 

#*---------------------------------------------------------------------*/
#*    examples                                                         */
#*---------------------------------------------------------------------*/
XEXAMPLES	= hello

#*---------------------------------------------------------------------*/
#*    The sources                                                      */
#*---------------------------------------------------------------------*/
#*--- Xincludes -------------------------------------------------------*/
XINCLUDE	= X Xlib Xutil Xatom Xresource cursorfont keysym

XINCLUDE_H	= $(XINCLUDE:%=include/%.h)
XINCLUDE_EH	= $(XINCLUDE:%=include/%.eh)

#*---------------------------------------------------------------------*/
#*     Les suffixes ...                                                */
#*---------------------------------------------------------------------*/
.SUFFIXES:
.SUFFIXES: .scm .sch .c .h .eh .o

#*---------------------------------------------------------------------*/
#*    lib                                                              */
#*---------------------------------------------------------------------*/
lib: include

#*---------------------------------------------------------------------*/
#*    include                                                          */
#*---------------------------------------------------------------------*/
include: $(XINCLUDE_H) $(XINCLUDE_EH) xlib.sch

#*---------------------------------------------------------------------*/
#*    xlib.sch                                                         */
#*---------------------------------------------------------------------*/
xlib.sch: Makefile xlib-macro.sch 
	@ echo xlib.sch:
	@ \rm -f xlib.sch
	@ echo "(directives " > xlib.sch
	@ echo " (extern  (type status long \"long\")" >> xlib.sch
	@ echo "          (type wchar_t short \"short\")" >> xlib.sch
	@ echo "          (include \"/usr/include/sys/types.h\")" >> xlib.sch
	@ echo "          (include \"stdio.h\")" >> xlib.sch
	@ echo "          (include \"X11/Xlib.h\")" >> xlib.sch
	@ echo "          (include \"X11/Xutil.h\")" >> xlib.sch
	@ echo "          )" >> xlib.sch
	@ $(CIGLOO) -v $(CGFLAGS) $(XINCLUDE_EH) >> xlib.sch
	@ cat xlib-macro.sch >> xlib.sch
	@ echo "   )" >> xlib.sch

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*---------------------------------------------------------------------*/
distrib:
	@ if [ `pwd` = $$HOME/prgm/project/bigloo/xlib ]; then       \
             echo "*** ERROR:Illegal dir to make a distrib `pwd`";   \
             exit 1;                                                 \
          fi
	@ $(MAKE) clean
	@ $(BIN)/copyright $(POPULATION)

#*---------------------------------------------------------------------*/
#*    install                                                          */
#*---------------------------------------------------------------------*/
install: xlib.sch
	@ cp xlib.sch `$(BIGLOO) -s -eval '(begin (print *lib-dir*) (exit -1))'`

#*---------------------------------------------------------------------*/
#*    clean                                                            */
#*---------------------------------------------------------------------*/
clean:
	@ echo $(CLEAN)...
	@- find include \( -name '*~' -o -name '*.BAK' \) -exec \rm -f {} \;
	@- \rm -f xlib.sch *~ *.BAK
	@ echo "done."

Dclean: clean

#*---------------------------------------------------------------------*/
#*    Clean                                                            */
#*---------------------------------------------------------------------*/
Clean:
	@ $(MAKE) clean CLEAN=Cleaning
	@ - find include \( -name '*.eh' -o -name '*.h' \) -exec \rm -f {} \;
	@ ( for p in ${XEXAMPLES} ;\
            do (cd example/$$p; $(MAKE) clean) ; done )

DClean: Clean

#*---------------------------------------------------------------------*/
#*    backup                                                           */
#*---------------------------------------------------------------------*/
backup:
	@ echo "Backuping $(BACKUPNAME) in $(BACKUPDIR)"
	@ (\rm -f $(BACKUPDIR)/$(BACKUPNAME).tar.gz;            \
	   cleanup;                                             \
           tar cf $(BACKUPDIR)/$(BACKUPNAME).tar $(POPULATION); \
           gzip $(BACKUPDIR)/$(BACKUPNAME).tar)
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    restore ...                                                      */
#*---------------------------------------------------------------------*/
restore:
	@ echo "Restoring $(BACKUPNAME) from $(BACKUPDIR)"
	@ (gzip -d --to-stdout $(BACKUPDIR)/$(BACKUPNAME).tar.gz | tar xfp -)
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    pop                                                              */
#*---------------------------------------------------------------------*/
pop:
	@ echo $(POPULATION:%=xlib/%)

#*---------------------------------------------------------------------*/
#*    .h --> .eh                                                       */
#*---------------------------------------------------------------------*/
.h.eh:
	@ echo $*.h:
	@ gcc $(CPPFLAGS) -E -dD -P $*.h > $*.eh

#*---------------------------------------------------------------------*/
#*     .scm --> .o                                                     */
#*---------------------------------------------------------------------*/
.scm.o:
	@ $(BIGLOO) -c $(BFLAGS) $*.scm -o $*.o

#*---------------------------------------------------------------------*/
#*    .h --> .h                                                        */
#*---------------------------------------------------------------------*/
include/X.h: $(XINCLUDEDIR)/X.h
	@ echo $(XINCLUDEDIR)/X.h:
	@ cp $(XINCLUDEDIR)/X.h include

include/Xatom.h: $(XINCLUDEDIR)/Xatom.h
	@ echo $(XINCLUDEDIR)/Xatom.h:
	@ cp $(XINCLUDEDIR)/Xatom.h include

include/Xlib.h:  $(XINCLUDEDIR)/Xlib.h
	@ echo $(XINCLUDEDIR)/Xlib.h:
	@ cat $(XINCLUDEDIR)/Xlib.h | egrep -v "#include <(sys|X11/X.h|stddef)" > include/Xlib.h

include/Xresource.h: $(XINCLUDEDIR)/Xresource.h
	@ echo $(XINCLUDEDIR)/Xresource.h:
	@ cat $(XINCLUDEDIR)/Xresource.h | egrep -v "_XFUNCPROTO(BEGIN|END)" > include/Xresource.h

include/Xutil.h:  $(XINCLUDEDIR)/Xutil.h
	@ echo $(XINCLUDEDIR)/Xutil.h:
	@ cat $(XINCLUDEDIR)/Xutil.h | egrep -v "_XFUNCPROTO(BEGIN|END)" >> include/Xutil.h

include/cursorfont.h:  $(XINCLUDEDIR)/cursorfont.h
	@ echo $(XINCLUDEDIR)/cursorfont.h:
	@ cp $(XINCLUDEDIR)/cursorfont.h include

include/keysym.h:  $(XINCLUDEDIR)/keysym.h
	@ echo $(XINCLUDEDIR)/keysym.h:
	@ cp $(XINCLUDEDIR)/keysym.h include

