######################################################################
######################################################################
######################################################################
###
### Generic GNU Smalltalk make rules
### Basic rule templates common to all make files
###
### $Revision: 1.7.5$
###
######################################################################
######################################################################
######################################################################


.PHONY : mostlyclean clean distclean maintainer-clean attempt all dist_dir

########################### BUILD RULES ##############################

gst$(EXE): $(OBJECTS) $(srcdir)/lib/libgst.a $(ICON)
	$(CC) $(LDFLAGS) $(LDPATH) -o $@ $(CFLAGS) $(CDEBUG)		\
		$(OBJECTS) $(srcdir)/lib/libgst.a $(ICON) 		\
		$(LIBS)

optimize: # schedule$(EXE)
	if [ -f optimize ]; then true; else				\
	  $(MAKE) mostlyclean;						\
	  $(MAKE) GCC_CFLAGS="$(GCC_OPT_CFLAGS) $(GCC_CFLAGS)"		\
		CFLAGS="$(OPT_CFLAGS) $(CFLAGS)" CDEBUG= 		\
		SCHEDULER=./schedule					\
	     && echo timestamp > optimize;				\
	fi

# schedule$(EXE): schedule.o
# 	$(CC) $(LDFLAGS) $(LDPATH) -o $@ $(CFLAGS) $(CDEBUG)		\
# 		schedule.o
#
# schedule.o: $(srcdir)/schedule.c

main.o: $(srcdir)/main.c

gsticon.o: gsticon.ico
	echo ProgramIcon ICON gsticon.ico | windres -o gsticon.o

$(srcdir)/lib/libgst.a: $(LIBRARY_FILES) $(srcdir)/gstconf.h
	(cd lib; $(MAKE) CFLAGS="$(CFLAGS)" GCC_CFLAGS="$(GCC_CFLAGS)" \
			 CDEBUG="$(CDEBUG)" SCHEDULER="$(SCHEDULER)")

# You can also use this rule with `make attempt TARGET=optimize'
attempt:
	$(MAKE) -k $(TARGET)

########################### AUTOCONF RULES ###########################

config.status: configure
	cd $(srcdir) && ./config.status --recheck

# config.status might not change gstconf.h
gstconf.h: stamp-h
stamp-h: gstconf.hin config.status
	cd $(srcdir) && ./config.status gstconf.h

lib/Makefile: lib/Makefile.in config.status
	cd $(srcdir) && ./config.status $@

Makefile.defs: Makedefs.in config.status
	cd $(srcdir) && ./config.status $@

configure: configure.in aclocal.m4
	cd $(srcdir) && $(AUTOCONF)

# autoheader might not change gstconf.h.in
gstconf.h.in: stamp-h.in
stamp-h.in: configure.in aclocal.m4 acconfig.h
	cd $(srcdir) && $(AUTOHEADER)
	echo timestamp > ${srcdir}/stamp-h.in

aclocal.m4: $(M4_FILES)
	(								      \
	  echo "dnl Copyright 1988-92, 1994-95, 1999, 2000"		     ;\
	  echo "dnl Free Software Foundation, Inc."			     ;\
	  echo "dnl Please see COPYING for a description of your rights and" ;\
	  echo "dnl responsibilities with this software." ;\
	  echo "dnl"							     ;\
	  echo "dnl Automatically generated from files in the m4 directory." ;\
	  echo "dnl Do not edit."					     ;\
	  echo "dnl"							     ;\
	  for i in $(M4_FILES); do					      \
	    echo "dnl"							     ;\
	    echo "dnl From $(srcdir)/$$i --"				     ;\
	    echo "dnl"							     ;\
	    cat $(srcdir)/$$i						     ;\
	    echo "dnl"							     ;\
	  done								      \
	) > aclocal.m4


########################### INSTALL RULES ############################

info:
	(cd docs; $(MAKE) info; cd ..)

dvi:
	(cd docs; $(MAKE) dvi; cd ..)

installdirs:
	$(SHELL) $(srcdir)/mkinstalldirs $(bindir) $(smlibdir) $(infodir) \
		 $(includedir) $(man1dir) $(INSTALLED_DIRS)

install:: installdirs optimize
	$(INSTALL_PROGRAM) gst$(EXE) $(bindir)/gst$(EXE)
	$(INSTALL_DATA) lib/gst.h $(includedir)/gst.h
	-$(INSTALL_DATA) lib/gst.h $(oldincludedir)/gst.h
	$(INSTALL_DATA) gstconf.h $(includedir)/gstconf.h
	-$(INSTALL_DATA) gstconf.h $(oldincludedir)/gstconf.h
	$(INSTALL_DATA) lib/gstpub.h $(includedir)/gstpub.h
	-$(INSTALL_DATA) lib/gstpub.h $(oldincludedir)/gstpub.h
	$(INSTALL_DATA) lib/libgst.a $(smlibdir)/libgst.a
	(cd $(srcdir)/docs; $(MAKE) install; cd ..)
	for file in $(INSTALLED_FILES); do				\
	  $(INSTALL_DATA) $$file $(stdir)/$$file;			\
	done
	(x=`pwd`; cd $(IMAGE_PATH); $$x/gst dummyFile -Vi; cd $$x)

uninstall:
	$(RM) $(bindir)/gst$(EXE)	$(smlibdir)/libgst.a		\
	      $(includedir)/gstpub.h	$(oldincludedir)/gstpub.h	\
	      $(includedir)/gst.h 	$(oldincludedir)/gst.h		\
	      $(includedir)/gstconf.h	$(oldincludedir)/gstconf.h
	$(RM) -r $(stdir)
	(cd docs; $(MAKE) uninstall; cd ..)

install-strip:
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

check:
	(cd test; ./do-check; cd ..)

########################### DISTRIBUTION RULES #######################

dist_dir: info gstconf.h.in configure
	-rm -rf $(BASE_NAME)
	mkdir $(BASE_NAME)
	for f in $(DISTFILES); do		\
	  ln $(srcdir)/$$f $(BASE_NAME)/$$f	\
	done

dist: dist_dir
	tar cvf - $(BASE_NAME) | gzip -9 > $(BASE_NAME).tar.gz
	rm -rf $(BASE_NAME)

########################### MISC. RULES ##############################

# ci_version should be set on the command line
ci_r:
	ci -l -mVersioning "-N$(ci_version)" RCS/*


profile_vm:
	$(MAKE) CFLAGS='$(CFLAGS) -DPROFBLOCK'

profile:
	$(MAKE) CFLAGS='$(CFLAGS) -pg -DUSE_MONCONTROL'


TAGS:   $(SOURCES)
	etags $(SOURCES)
	(cd lib; $(MAKE) TAGS; cd ..)

tags:   $(SOURCES)
	ctags $(SOURCES)
	(cd lib; $(MAKE) tags; cd ..)

ls:
	@echo $(DISTFILES)


########################### CLEANING RULES ###########################

mostlyclean: recursive-mostlyclean here-mostlyclean

clean: recursive-clean here-clean

distclean: recursive-distclean here-distclean


here-mostlyclean:
	-$(RM) *.o core gst.exe.core gst gst.exe optimize

recursive-mostlyclean:
	(cd lib; $(MAKE) mostlyclean; cd ..)
	(cd docs; $(MAKE) mostlyclean; cd ..)


here-clean: here-mostlyclean
	-$(RM) gst.im test/*.log

recursive-clean:
	(cd lib; $(MAKE) clean; cd ..)
	(cd docs; $(MAKE) clean; cd ..)


here-distclean: here-clean
	-$(RM) cfuncs.c Makefile config.status tags TAGS config.log config.cache test/Makefile Makefile.defs gstconf.h

recursive-distclean:
	(cd lib; $(MAKE) distclean; cd ..)
	(cd docs; $(MAKE) distclean; cd ..)


maintainer-clean: here-distclean
	@echo 'This command is intended for maintainers to use; it'
	@echo 'deletes files that may need special tools to rebuild.'
	(cd lib; $(MAKE) do-maintainer-clean; cd ..)
	(cd docs; $(MAKE) do-maintainer-clean; cd ..)

# Tell versions [3.59, 3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
