makefile
#***************************************************************************************************
#                                                                                                  *
# makefile: the makefile of siliconBrain and of all siliconBrain derived projects.                 *
#                                                                                                  *
#***************************************************************************************************

#***************************************************************************************************
#                                                                                                  *
#     Copyright (C) 2003, 2004 Joerg Kunze                                                         *
#                                                                                                  *
#     This file is part of siliconBrain.                                                           *
#                                                                                                  *
#     siliconBrain 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.                                                          *
#                                                                                                  *
#     siliconBrain 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                    *
#                                                                                                  *
#***************************************************************************************************
siliconBrainRelease       := '$$siliconBrainRelease: 0.2.3 $$'
siliconBrainRcsIdentifier := '$$Id: makefile,v 1.108 2004/12/14 23:31:26 joerg Exp $$'
siliconBrainSaveStamp     := '$$siliconBrainSaveStamp: 2004/12/14 22:53:50, Joerg Kunze$$'

#----------------------------#
# echo greetings to the user #
#----------------------------#
#$(shell echo                              1>&2)
#$(shell echo This is siliconBrain generic makefile 1>&2)
#$(shell echo $(siliconBrainRelease)       1>&2)
#$(shell echo $(siliconBrainRcsIdentifier) 1>&2)
#$(shell echo $(siliconBrainSaveStamp)     1>&2)
#$(shell echo                              1>&2)

#----------------------------------------------------------#
# make possible the self compile without installing itself #
#----------------------------------------------------------#
ifeq ($(notdir $(PWD)),siliconBrain)
   export siliconBrainPath := distribution
endif
#$(shell echo siliconBrainPath=$(siliconBrainPath) 1>&2)

VPATH = temporary

#-------------------------------------------------------------------------------#
# we need version 3.0 , because it handles the -MMD in case that the .o's are   #
# in a subdirectory (here "temporary/"). That is it automatically puts the *.d  #
# files into temporary/ and adds the "temporary/" prefix to the object targets. #
#-------------------------------------------------------------------------------#
export CC = gcc-3.4

#--------------------------------------------------------------#
# -Wall           : warn all you find                          #
# -Wno-parentheses: but allow assignments in "if" without "()" #
# -Werror         : treat warnings as errors                   #
# -O3             : optimize for performace: high              #
# -MMD            : create dependency files (eg: tmp/jk.lib.d) #
#--------------------------------------------------------------#
glibIncludeDirectories = $(shell pkg-config --cflags glib-2.0)
includeDirectories := -I. -I distribution/include -I$(siliconBrainPath)/include -I$(siliconBrainLibPath)/include $(glibIncludeDirectories)
# export CFLAGS += $(includeDirectories) -Wall -Wno-parentheses -Werror -g -MMD -D_GNU_SOURCE -pg
export CFLAGS += $(includeDirectories) -Wall -Wno-parentheses -Werror -g -MMD -D_GNU_SOURCE
# export CFLAGS += $(includeDirectories) -Wall -Wno-parentheses -Werror -O3 -MMD -D_GNU_SOURCE

#--------------------------------------------------------#
# some information should be available in called scripts #
#--------------------------------------------------------#
export PATH := ./distribution/programs:$(siliconBrainPath)/programs:$(PATH):~joerg/works:/usr/bin/local/bin/sbin/lib::::::~katja/games

export siliconBrainPackageName   := $(notdir $(PWD))
export siliconBrainDataDirectory := distribution/data
export siliconBrainEmacsLoadPath := (list "./distribution/programs" "$(siliconBrainPath)/programs")
export siliconBrainTemporary     := distribution\|temporary\|.*\.log$$\|TAGS\|.*~$$

#----------------------------------------------------------------------------#
# some files depend on the existens and freshness of siliconBrain components #
#----------------------------------------------------------------------------#
generator                := $(siliconBrainPath)/programs/generate
createInfo               := $(siliconBrainPath)/programs/createInfo
texi2man                 := $(siliconBrainPath)/programs/texi2man
formatHeader             := $(siliconBrainPath)/programs/formatHeader
makeDependencies         := $(siliconBrainPath)/programs/makeDependencies
createReleaseInformation := $(siliconBrainPath)/programs/createReleaseInformation

generators = $(generator) $(createInfo) $(texi2man) $(formatHeader) $(makeDependencies) $(createReleaseInformation)

#***************************************************************************************************
#                                                                                                  *
# source & targets: template created sources                                                       *
#                                                                                                  *
#***************************************************************************************************
licenseToCreateSource := $(wildcard templates/gnu*)
licenseToCreateTarget := $(addprefix distribution/data/, $(notdir $(licenseToCreateSource)))
licenseToGetSource    := $(sort $(wildcard $(siliconBrainPath)/data/gnu*) $(licenseToCreateTarget))
licenseToGetTarget    := $(addprefix distribution/documentation/web/, $(sort $(notdir $(licenseToGetSource))))

templatesToCreateSource  := $(wildcard templates/*.template templates/.*.template)
templatesToCreateTarget  := $(addprefix distribution/data/, $(notdir $(templatesToCreateSource)))
templatesToGetSource     := $(wildcard $(siliconBrainPath)/data/*.template $(siliconBrainPath)/data/.*.template)
templatesToGetTarget     := $(notdir $(basename $(templatesToGetSource)))

#----------------------------------------------------------------------------#
# $siliconBrainPackageName.main.texinfo is made out of document.main.texinfo #
#----------------------------------------------------------------------------#
documentsToCreateSource  := $(wildcard templates/documentation/*.template)
documentsToCreateTarget  := $(addprefix distribution/data/documentation/, $(notdir $(documentsToCreateSource)))
documentsToGetSource     := $(filter-out                                  \
   $(siliconBrainPath)/data/documentation/document.main.texinfo.template, \
   $(wildcard $(siliconBrainPath)/data/documentation/*.template)          \
)
documentsToGetTarget     := $(addprefix documentation/, $(notdir $(basename $(documentsToGetSource))))
ifneq ($(documentsToCreateSource),)
   documentsTemplateDirectory=distribution/data/documentation
endif

#---------------------------------------------------------------#
# filter out template based targets, if the files already exist #
#---------------------------------------------------------------#
templatesToGetTarget       := $(filter-out $(wildcard $(templatesToGetTarget)      ), $(templatesToGetTarget)      )
documentsToGetTarget       := $(filter-out $(wildcard $(documentsToGetTarget)      ), $(documentsToGetTarget)      )
documentsTemplateDirectory := $(filter-out $(wildcard $(documentsTemplateDirectory)), $(documentsTemplateDirectory))

mainDocument := documentation/$(siliconBrainPackageName).main.texinfo
mainDocument := $(filter-out $(wildcard $(mainDocument)), $(mainDocument))

#***************************************************************************************************
#                                                                                                  *
# source & targets: normal                                                                         *
#                                                                                                  *
#***************************************************************************************************
bashSource      := $(wildcard *.bash)
perlSource      := $(wildcard *.perl)
texinfoSource   := $(sort $(wildcard documentation/*.main.texinfo) documentation/$(siliconBrainPackageName).main.texinfo)
emacsSource     := $(wildcard *.el)
awkSource       := $(wildcard *.awk)
snippetSource   := $(sort $(wildcard documentation/*.snippet.texinfo) $(documentsToGetTarget))

perlModuleSource := $(wildcard *.pm)
perlModuleTarget := $(addprefix distribution/, $(perlModuleSource))

recordSource    := $(wildcard *.record.specification.c)
recordStems     := $(basename $(basename $(recordSource)))
recordCommandC  := $(addprefix temporary/, $(addsuffix .command.c, $(recordStems)))

packageSpecification        := $(addprefix temporary/, $(basename $(wildcard $(siliconBrainPackageName).specification.c)) )

configurationReaderStem     := $(addsuffix .configurationReader, $(basename $(basename $(wildcard $(siliconBrainPackageName).specification.c))))
configurationReaderC        := $(addprefix temporary/, $(addsuffix .main.c, $(configurationReaderStem)))
configurationReaderObjects  := $(addprefix temporary/, $(addsuffix .main.o, $(configurationReaderStem)))
configurationReaderBinaries := $(addprefix distribution/programs/, $(configurationReaderStem))

commandStems    := $(basename $(basename $(wildcard *.command.c))) $(recordStems)
commandCFiles   := $(addprefix temporary/, $(addsuffix .main.c, $(commandStems)))
commandObjects  := $(addprefix temporary/, $(addsuffix .main.o, $(commandStems)))
commandHFiles   := $(addprefix distribution/include/, $(commandStems))
commandTexinfo  := $(addprefix temporary/, $(addsuffix .texinfo, $(commandStems)))
commandInfo     := $(addprefix distribution/documentation/, $(addsuffix .info, $(commandStems)))
commandMan      := $(addprefix distribution/documentation/man1/, $(addsuffix .1, $(commandStems)))

hSource         := $(wildcard *.h)
hTarget         := $(addprefix distribution/include/, $(basename $(hSource)))

mainStems       := $(filter-out formatHeader, $(basename $(basename $(wildcard *.main.c))))
mainObjects     := $(addprefix temporary/, $(addsuffix .main.o, $(mainStems)))
mainBinaries    := $(addprefix distribution/programs/, $(mainStems) $(commandStems))

specificationStems     := $(basename $(wildcard *.specification.c))
specificationObjects   := $(addprefix temporary/, $(addsuffix .o, $(specificationStems)))
specificationBinaries  := $(addprefix temporary/, $(specificationStems))

libraryMemberStems    := $(basename $(wildcard *.lib.c)) $(addsuffix .command, $(commandStems))
libraryArchiveMembers := $(addsuffix .o, $(libraryMemberStems))
libraryMemberObjects  := $(addprefix temporary/, $(libraryArchiveMembers))
libraryArchive        := distribution/lib$(siliconBrainPackageName).a
libraries              = $(patsubst lib%, %, $(notdir $(basename $(wildcard distribution/*.a))))

allObjects         := $(commandObjects) $(mainObjects) $(specificationObjects) $(libraryMemberObjects)
objectDependencies := $(addsuffix .d, $(basename $(allObjects)))

executableScripts  := $(addprefix distribution/programs/, $(basename $(bashSource) $(perlSource) $(awkSource)) $(addsuffix c, $(emacsSource)))
executableBinaries := $(mainBinaries) $(specificationBinaries)
executables        := $(executableScripts) $(executableBinaries)

infoStem        := $(addprefix distribution/documentation/, $(basename $(basename $(notdir $(texinfoSource)))))
infoDependency  := $(addprefix temporary/, $(addsuffix .d, $(notdir $(texinfoSource))))
infoTarget      := $(addsuffix .info, $(infoStem))
infoDvi         := $(addsuffix .dvi,  $(infoStem))
infoPs          := $(addsuffix .ps,   $(infoStem))

snippets            := $(addprefix distribution/data/, $(basename $(notdir $(snippetSource))))
snippetTextTarget   := $(addsuffix .text, $(snippets))
snippetHtmlTarget   := $(addsuffix .html, $(snippets))
snippetDependency   := $(addsuffix .texinfo.d, $(addprefix temporary/, $(basename $(notdir $(snippetSource)))))

latexSource := $(wildcard *.latex)
latexDvi    := $(addsuffix .dvi, $(addprefix temporary/, $(basename $(latexSource))))
texSource   := $(wildcard *.tex)
texDvi      := $(addsuffix .dvi, $(addprefix temporary/, $(basename $(texSource))))
psTarget    := $(addsuffix .ps,  $(addprefix temporary/, $(basename $(texSource) $(latexSource))))

isInitialized := $(filter-out $(wildcard temporary/isInitialized), temporary/isInitialized)

#---------------------------------------------#
# we create TAGS, only if there are C sources #
#---------------------------------------------#
tagSources := $(wildcard *.c *.h)
ifneq ($(tagSources),)
   tagTarget := TAGS
endif

capitalFiles := COPYING COPYING.DOC AUTHORS INSTALL INTRODUCTION NEWS README TODO

glibLibraries := $(shell pkg-config --libs glib-2.0)

export LOADLIBES += -lsiliconBrainLib $(glibLibraries)
export LDLIBS    += -L$(siliconBrainPath)  -Ldistribution -L$(siliconBrainLibPath)

#***************************************************************************************************
#                                                                                                  *
# test:                                                                                            *
#                                                                                                  *
#***************************************************************************************************
#----------------------------------------------------------------------------------------#
# default target is ``test''. But call the standard test frame script, only if it exists #
#----------------------------------------------------------------------------------------#
testAction := $(notdir $(filter distribution/programs/makeTest distribution/programs/testMain, $(executables)))

#	testMakeClean
test: all
	testMakeClean
ifneq ($(testAction), )
	date >> $(testAction).time
	command time --append --format="%E elapsed by %C" --output="$(testAction).time" $(testAction)
	tail $(testAction).time
endif

#***************************************************************************************************
#                                                                                                  *
# specific extensions:                                                                             *
#                                                                                                  *
#***************************************************************************************************
-include packageSpecific.makefile

#***************************************************************************************************
#                                                                                                  *
# rules:                                                                                           *
#                                                                                                  *
#***************************************************************************************************
all: step6 \
   $(infoTarget) $(infoDvi) $(tagTarget)                                             \
   $(licenseToCreateTarget)   $(licenseToGetTarget)                                  \
   $(templatesToCreateTarget) $(templatesToGetTarget)                                \
   $(documentsToCreateTarget) $(documentsToGetTarget) $(documentsTemplateDirectory)  \
   documentation/$(siliconBrainPackageName).main.texinfo                             \
   $(capitalFiles)                                                                   \
   $(snippetTextTarget) $(snippetHtmlTarget)                                         \
   distribution/data/releaseInformation siliconBrainInstall                          \
   distribution/setEnvironment                                                       \
   $(specificAll)                                                                    \
   distribution/documentation/dir $(commandMan)                                      \
   $(infoPs) $(psTarget)

step6: step5 $(configurationReaderBinaries) $(executableBinaries)

step5: step4 $(generators)

ifeq ($(libraryArchiveMembers), )
step4: step3
else
step4: step3 $(libraryArchive)($(libraryArchiveMembers))
endif

step3: step2 $(allObjects) $(objectDependencies)

step2: step1 $(perlModuleTarget) $(hTarget) $(executableScripts) $(formatHeader)

step1: $(isInitialized)

#***************************************************************************************************
#                                                                                                  *
# initialize:                                                                                      *
#                                                                                                  *
#***************************************************************************************************
temporary/isInitialized:
	mkdir --parents                              \
	   distribution/programs                     \
	   distribution/documentation/web/index      \
	   distribution/documentation/web/sourceTree \
	   distribution/documentation/web/info       \
	   distribution/documentation/man1           \
	   distribution/data                         \
	   distribution/include                      \
      documentation                             \
      temporary
	touch temporary/isInitialized

#***************************************************************************************************
#                                                                                                  *
# documents:                                                                                       *
#                                                                                                  *
#***************************************************************************************************
$(latexDvi): temporary/%.dvi:%.latex
	cd temporary; latex ../$<

$(texDvi): temporary/%.dvi:%.tex
	cd temporary; tex ../$<

$(psTarget): %.ps: %.dvi
	dvips $< -o $@ 2> /dev/null

#***************************************************************************************************
#                                                                                                  *
# H-files:                                                                                         *
#                                                                                                  *
#***************************************************************************************************
distribution/include/%:%.h
	cp $< $@

#***************************************************************************************************
#                                                                                                  *
# script:                                                                                          *
#                                                                                                  *
#***************************************************************************************************
distribution/programs/%:%.bash
	cp $< $@ ; chmod 775 $@

distribution/programs/%:%.perl
	cp $< $@ ; chmod 775 $@

$(perlModuleTarget): distribution/%.pm:%.pm
	cp $< $@

distribution/programs/%:%.awk
	cp $< $@ ; chmod 775 $@

#***************************************************************************************************
#                                                                                                  *
# data:                                                                                            *
#                                                                                                  *
#***************************************************************************************************
distribution/data/%:%
	cp $< $@

#***************************************************************************************************
#                                                                                                  *
# emacs lisp:                                                                                      *
#                                                                                                  *
#***************************************************************************************************
%.elc:%.el
	emacs --no-init-file --no-site-file --batch --funcall=batch-byte-compile $< # 2> /dev/null

distribution/programs/%.el:%.el
	cp $< $@

#***************************************************************************************************
#                                                                                                  *
# record:                                                                                          *
#                                                                                                  *
#***************************************************************************************************
$(recordCommandC): temporary/%.command.c: temporary/%.specification $(generator)
	$< | generate --command > $@

#***************************************************************************************************
#                                                                                                  *
# command:                                                                                         *
#                                                                                                  *
#***************************************************************************************************
$(commandTexinfo): temporary/%.texinfo: temporary/%.specification $(packageSpecification) $(generator)
	$< | generate --texinfo > $@

$(commandInfo): distribution/documentation/%.info: temporary/%.texinfo
	makeinfo -I./documentation:.:distribution/documentation/web --output=$@ $<

distribution/documentation/dir: $(commandTexinfo) $(createInfo)
	createInfo $(commandTexinfo) > $@

$(commandCFiles): temporary/%.main.c: temporary/%.specification $(packageSpecification) $(generator)
	$< | generate --c > $@

$(commandHFiles): distribution/include/%: temporary/%.specification $(packageSpecification) $(generator)
	$< | generate --h > $@

$(commandMan): distribution/documentation/man1/%.1: temporary/%.texinfo documentation/authors.snippet.texinfo $(texi2man)
	texi2man < $< > $@

$(addprefix temporary/, $(addsuffix .command.o, $(commandStems))): temporary/%.command.o: distribution/include/%
$(addprefix temporary/, $(addsuffix .main.o   , $(commandStems))): temporary/%.main.o   : distribution/include/%

$(commandObjects): temporary/%.o:temporary/%.c
	compile $< $@

#***************************************************************************************************
#                                                                                                  *
# c:                                                                                               *
#                                                                                                  *
#***************************************************************************************************
$(mainObjects) $(specificationObjects): temporary/%.o:%.c
	compile $< $@

# JKJK: $(mainBinaries): distribution/programs/%:temporary/%.main.o $(wildcard $(libraryArchive)) 
$(mainBinaries): distribution/programs/%:temporary/%.main.o
	link $< $@

$(objectDependencies):
	if [ ! -f $@ ]; then    \
		rm --force $(addsuffix .o, $(basename $@)) ;\
		$(MAKE)    $(addsuffix .o, $(basename $@)) ;\
	fi

#***************************************************************************************************
#                                                                                                  *
# specification:                                                                                   *
#                                                                                                  *
#***************************************************************************************************
$(specificationBinaries): temporary/%:temporary/%.o
	link $< $@

$(configurationReaderC): temporary/%.main.c: $(packageSpecification) $(generator)
	$< | generate --configurationReader > $@

$(configurationReaderObjects): temporary/%.o:temporary/%.c
	compile $< $@

# JKJK: $(configurationReaderBinaries): distribution/programs/%:temporary/%.main.o $(wildcard $(libraryArchive))
$(configurationReaderBinaries): distribution/programs/%:temporary/%.main.o
	link $< $@

#***************************************************************************************************
#                                                                                                  *
# library:                                                                                         *
#                                                                                                  *
#***************************************************************************************************
$(libraryMemberObjects): temporary/%.o:%.c
	compile $< $@

# JKJK: $(mainBinaries): $(libraryArchive)($(libraryArchiveMembers))

ifneq ($(libraryArchiveMembers), )
$(libraryArchive)($(libraryArchiveMembers)):$(libraryArchive)(%.o):temporary/%.o
	ar r $@ $^
endif

#-----------------------------------------------------------------------------#
# conditionally include the dependency files, which are generated by the -MMD #
# compiler option (which C file depends on what H file).                      #
#-----------------------------------------------------------------------------#
-include temporary/*.d

#***************************************************************************************************
#                                                                                                  *
# texinfo:                                                                                         *
#                                                                                                  *
#***************************************************************************************************
$(infoTarget): distribution/documentation/%.info:documentation/%.main.texinfo temporary/%.main.texinfo.d temporary/commands.texinfo temporary/releaseInformation.texinfo
	makeinfo -I./documentation:.:distribution/documentation/web:temporary --output=$@ $< ; \
	makeinfo -I./documentation:.:distribution/documentation/web:temporary --html  --output=distribution/documentation/web/info $< ; \

$(infoDvi): distribution/documentation/%.dvi:documentation/%.main.texinfo distribution/documentation/%.info
	texi2dvi -e -I distribution/documentation/web/:documentation:.:temporary --quiet --output=$@ $< 2> temporary/$*.main.texinfo.log
	cat temporary/$*.main.texinfo.log
	error=$$(wc --bytes < temporary/$*.main.texinfo.log); if [ $$error -gt 0 ]; then rm $@; exit 42; fi

$(infoDependency): temporary/%.main.texinfo.d: documentation/%.main.texinfo $(snippetSource) $(licenseToGetTarget) temporary/releaseInformation.texinfo temporary/commands.texinfo $(makeDependencies)
	makeDependencies --assign target="distribution/documentation/$*.info temporary/$*.main.texinfo.d" $<  > temporary/$*.main.texinfo.d

$(infoPs): %.ps: %.dvi
	dvips $< -o $@ 2> /dev/null

temporary/commands.texinfo: $(commandTexinfo) $(formatHeader)
	formatHeader "@c"                     \
	   $(siliconBrainRelease)             \
	   $(siliconBrainRcsIdentifier)       \
	   $(siliconBrainSaveStamp)           \
	   "The texinfo menu of all commands" \
	   $(siliconBrainRelease)             \
	   $(siliconBrainRcsIdentifier)       \
	   $(siliconBrainSaveStamp) > $@;     \
	echo "@menu"     >> $@; for command in $(commandStems)  ; do echo "* $${command}:: $$command" >> $@; done;\
	echo "@end menu" >> $@;	for command in $(commandTexinfo); do echo "@include $$command"        >> $@; done

#***************************************************************************************************
#                                                                                                  *
# TAGS:                                                                                            *
#                                                                                                  *
#***************************************************************************************************
TAGS: $(tagSources)
	etags $(tagSources)

#***************************************************************************************************
#                                                                                                  *
# template:                                                                                        *
#                                                                                                  *
#***************************************************************************************************
$(templatesToCreateTarget): distribution/data/%:templates/%
	cp $< $@

#-----------------------------------------------------------------------------------#
# the `test -f $@ || ' is to prevent creation of this target, if it already exists, #
# but the make-rules say it should be rebuild.                                      #
#-----------------------------------------------------------------------------------#
$(templatesToGetTarget):
	test -f $@ || cp $(siliconBrainPath)/data/$@.template $@

$(documentsTemplateDirectory):
	test -d $@ || mkdir $@

$(documentsToCreateTarget): $(documentsTemplateDirectory)

$(documentsToCreateTarget): distribution/data/documentation/%:templates/documentation/%
	cp $< $@

$(documentsToGetTarget):
	test -f $@ || cp $(siliconBrainPath)/data/$@.template $@

$(mainDocument):
	cp $(siliconBrainPath)/data/documentation/document.main.texinfo.template $@

$(licenseToCreateTarget): distribution/data/%:templates/%
	cp $< $@

$(licenseToGetTarget): distribution/documentation/web/%:$(siliconBrainPath)/data/%
	cp $< $@

#***************************************************************************************************
#                                                                                                  *
# capital:                                                                                         *
#                                                                                                  *
#***************************************************************************************************
COPYING: $(siliconBrainPath)/data/gnuGpl.text
	cp $< $@

COPYING.DOC: $(siliconBrainPath)/data/gnuFdl.text
	cp $< $@

AUTHORS: distribution/data/shortCopyingDoc.snippet.text distribution/data/authors.snippet.text
	cat $^ > $@

INSTALL: distribution/data/shortCopyingDoc.snippet.text distribution/data/install.snippet.text
	cat $^ > $@

INTRODUCTION: distribution/data/shortCopyingDoc.snippet.text distribution/data/introduction.snippet.text
	cat $^ > $@

NEWS: distribution/data/shortCopyingDoc.snippet.text distribution/data/news.snippet.text
	cat $^ > $@

README: distribution/data/shortCopyingDoc.snippet.text distribution/data/readme.snippet.text
	cat $^ > $@

TODO: distribution/data/shortCopyingDoc.snippet.text distribution/data/todo.snippet.text
	cat $^ > $@

$(snippetTextTarget): distribution/data/%.text: documentation/%.texinfo temporary/%.texinfo.d temporary/releaseInformation.texinfo
	makeinfo -I./documentation:.:distribution/documentation/web --no-split --no-header --output $@ < $<

$(snippetHtmlTarget): distribution/data/%.html: documentation/%.texinfo temporary/%.texinfo.d temporary/releaseInformation.texinfo
	makeinfo -I./documentation:.:distribution/documentation/web --no-split --no-header --html < $< | \
        gawk '/<body>/,/<\\\/body>/{if( ! /.*<.?body>.*/ ) print $$0}' > $@

$(snippetDependency): temporary/%.texinfo.d: documentation/%.texinfo $(makeDependencies)
	makeDependencies --assign target="distribution/data/$*.text distribution/data/$*.html temporary/$*.texinfo.d" $<  > temporary/$*.texinfo.d

#***************************************************************************************************
#                                                                                                  *
# environment:                                                                                     *
#                                                                                                  *
#***************************************************************************************************
distribution/data/releaseInformation: $(createReleaseInformation) RELEASE
	createReleaseInformation --bash > $@

temporary/releaseInformation.texinfo: $(createReleaseInformation) RELEASE
	createReleaseInformation --texinfo > $@

siliconBrainInstall: $(siliconBrainPath)/programs/siliconBrainInstall
	cp $< $@

distribution/setEnvironment: $(siliconBrainPath)/programs/setEnvironment
	$< > $@

#***************************************************************************************************
#                                                                                                  *
# clean:                                                                                           *
#                                                                                                  *
#***************************************************************************************************

#----------------------------------------------------------#
# --force: don't complain about nonexisting files. eg "*~" #
# We do not delete capitalFiles, because they are very     #
# important!                                               #
#----------------------------------------------------------#
clean:
	-rm --force --recursive $$(ls | grep $$siliconBrainTemporary)

#***************************************************************************************************
#                                                                                                  *
# install:                                                                                         *
#                                                                                                  *
#***************************************************************************************************

#---------------------------------------------------------------------------------------------#
# IMPORTANT: ``public'' does *not* depend on ``all'' or ``web'', because inside publish there #
# is a call to ``make web'', so that the automatic changes made by ``publish'' are inside the #
# newly created webified version. So there is a kind of hidden dependency. A dependency here  #
# would result in doing the ``make web'' twice.                                               #
#---------------------------------------------------------------------------------------------#
public:
	publish

web: all
	webify

install: all web
	siliconBrainInstall

#------------------------------------------------------------------------------------------------#
# In case that a command fails, the target file should be deleted. So in a subsequent invocation #
# of "make" the file is rebuild. Otherwise a currupt target file is assumed to be an up to date  #
# target.                                                                                        #
#------------------------------------------------------------------------------------------------#
.DELETE_ON_ERROR:

# $Log: makefile,v $
# Revision 1.108  2004/12/14 23:31:26  joerg
# published for new release 0.2.3
#
# Revision 1.107  2004/12/14 23:17:05  joerg
# published for new release 0.2.2
#
# Revision 1.106  2004/12/14 22:55:09  joerg
# do the testMakeClean even, if there are no other tests.
#
# Revision 1.105  2004/12/14 22:20:09  joerg
# pipe output of make command into stringSearch c-function
# without creating a process for stringSearch. The later is used as a C-function command, not as a main.
#