#!/usr/bin/make
# Dies ist das coldformix Makefile


# Zur Erstellung des Debian-Pakets notwendig (make DESTDIR=/root/problectix)
DESTDIR=

#
#
# To create an update *.ps with selected pages:
# psselect -p 12,14,18 input.ps output.ps
#
# To create a new refsym.zip: 
#    cd coldformix-source/refsym
# and use the Makefile there
#
# To create a new rltsym.zip: 
#    cd coldformix-source/rltsym
# and use the Makefile there
#
#
# What language to use
LANG=
CONFIG=all
VERSION=x.x

# Where the generated latex-files are
LATEX=coldformix-generated/$(LANG)/latex
WWW=/var/www/coldformixhtdoc/download/stable-1.0


help:
	@echo ' '
	@echo 'Most common options of this Makefile:'
	@echo '-------------------------------------'
	@echo ' '
	@echo '   Create an official collection of formula :'
	@echo '     make LANG=de CONFIG=bszleo VERSION=2.0.4 clean'
	@echo '     make LANG=de CONFIG=bszleo VERSION=2.0.4 dina4 dina5 ohp'
	@echo ' '


# End-Dokumente erzeugen
# DIN A4-Datei
dina4: ps
	cd $(LATEX); ps2pdf coldformix-$(LANG)-$(CONFIG)-$(VERSION).ps
	cd $(LATEX); gv coldformix-$(LANG)-$(CONFIG)-$(VERSION).ps

# Folien fr OHP auf DIN A4
ohp: ps
	cd coldformix-scripts; ./coldformix-ohp --l $(LANG) --v $(VERSION) --c $(CONFIG) 
	cd $(LATEX); ps2pdf coldformix-$(LANG)-$(CONFIG)-$(VERSION)-ohp.ps
	cd $(LATEX); gv --scale=1 coldformix-$(LANG)-$(CONFIG)-$(VERSION)-ohp.ps
#	cd $(LATEX); kghostview coldformix-$(LANG)-$(CONFIG)-$(VERSION)-ohp.ps



# DIN A5-Datei
dina5: ps
	cd coldformix-scripts; ./coldformix-a5 --l $(LANG) --v $(VERSION) --c $(CONFIG) 
#	cd $(LATEX); kghostview coldformix-$(LANG)-$(CONFIG)-$(VERSION)-a5.ps
	cd $(LATEX); ps2pdf coldformix-$(LANG)-$(CONFIG)-$(VERSION)-a5.ps
	cd $(LATEX); gv --orientation=landscape --scale=2 coldformix-$(LANG)-$(CONFIG)-$(VERSION)-a5.ps

# Loeschen von allem
clean:
	rm -rf coldformix-generated/$(LANG)

ps: dvi 
	cd $(LATEX); dvips coldformix-$(LANG)-$(CONFIG)-$(VERSION).dvi

dvi: tex 
	cd $(LATEX); latex coldformix-$(LANG)-$(CONFIG)-$(VERSION).tex
	cd $(LATEX); latex coldformix-$(LANG)-$(CONFIG)-$(VERSION).tex

tex:logph rtables substances links refrig refsym titlepage delta_t_m latexbase vocabulary
	cd coldformix-scripts; ./coldformix --lang $(LANG) --config $(CONFIG) --version $(VERSION) 




logph: coldformix-source/data/logph/*.ps
	cd coldformix-scripts; ./ps-diag --lang $(LANG)


rtables: coldformix-source/data/rtables/*.dat
	cd coldformix-scripts; ./latex-rtables --lang $(LANG) 


latexbase: coldformix-source/templates/formula-template.tex
# formula-template.tex when --file is empty
	cd coldformix-scripts; ./latex-formula --lang $(LANG)
	cd coldformix-scripts; ./latex-formula --file formula-et --lang $(LANG)
	cd coldformix-scripts; ./latex-formula --file moist-air --lang $(LANG)
	cd coldformix-scripts; ./latex-formula --file heat-transfer-coeff --lang $(LANG)
	cd coldformix-scripts; ./latex-formula --file pipe --lang $(LANG)
	cd coldformix-scripts; ./latex-formula --file units --lang $(LANG)
	cd coldformix-scripts; ./latex-symlist --lang $(LANG)

vocabulary: 
	cd coldformix-scripts; ./latex-vocabulary --lang $(LANG)

substances: 
	cd coldformix-scripts; ./latex-substances --lang $(LANG)

refrig: 
	cd coldformix-scripts; ./latex-rlist --lang $(LANG)

refsym:
	cd coldformix-scripts; ./latex-refsym --lang $(LANG) --config $(CONFIG)

links: 
	cd coldformix-scripts; ./latex-links --lang $(LANG)

titlepage: 
	cd coldformix-scripts; ./latex-titlepage --lang $(LANG)
delta_t_m: 
	cd coldformix-scripts; ./delta_t_m




############################################################
# Installation into the system
############################################################

# shared data
SHAREDIR=$(DESTDIR)/usr/share/coldformix

# tex config
TEXCNFDIR=$(DESTDIR)/etc/texmf/texmf.d

# root scripts
SBIN=$(DESTDIR)/usr/sbin

# Perl modules
PERLMOD=$(DESTDIR)/usr/share/perl5


install-mysql-build:
	install -d -m755 -oroot -groot $(SHAREDIR)/database
# The database
	install -oroot -groot --mode=0644 coldformix-source/data/database/coldformix.sql $(SHAREDIR)/database 
# Scripts to create and fill the database when installing the package
	install -d -m755 -oroot -groot $(SHAREDIR)/database-scripts
	install -oroot -groot --mode=0755 coldformix-scripts/coldformix-sqlroot $(SHAREDIR)/database-scripts 
# Scripts to be run as root to dump and load the database
	install -d -m755 -oroot -groot $(SBIN)
	install -oroot -groot --mode=0755 coldformix-scripts/coldformix-database-dump $(SBIN)
	install -oroot -groot --mode=0755 coldformix-scripts/coldformix-database-load $(SBIN)
# Module coldformix.pm
	@install -d -m755 -oroot -groot $(PERLMOD)
	@install -oroot -groot --mode=0644 coldformix-scripts/coldformix.pm $(PERLMOD)




install-mysql-devel:

install-source-build:
# Tex main_memory size 
	@install -d -m755 -oroot -groot $(TEXCNFDIR)
	@install -oroot -groot --mode=0644 conf/00coldformix.cnf $(TEXCNFDIR)

install-source-devel:




# Data
#PARTDIR=$(DESTDIR)/usr/share/qcad/libraries
PARTDIRQCAD=$(DESTDIR)/usr/share/qcad/libraries
PARTDIRLIBRECAD=$(DESTDIR)/usr/share/librecad/library
TMPDIR=$(DESTDIR)../../coldformix-generated/temp

# install EN_1861 in a Debian system
# qcad and librecad
install-refsym-cad:
	# remove old stuff
	@ rm -rf coldformix-generated/temp
	@ mkdir -p coldformix-generated/temp
	# make a copy
	@ cp -a coldformix-source/refsym/EN_1861 coldformix-generated/temp
	# delete unwanted files
	@ rm -rf coldformix-generated/temp/CVS
	@ rm -rf coldformix-generated/temp/EN_1861/CVS 
	@ rm -rf coldformix-generated/temp/EN_1861/*/CVS
	@ rm -rf coldformix-generated/temp/EN_1861/*/*.ps
	@ rm -rf coldformix-generated/temp/EN_1861/*/*/CVS
	@ rm -rf coldformix-generated/temp/EN_1861/*/*/*.ps
	@ rm -rf coldformix-generated/temp/EN_1861/*/*/*/CVS
	# rename the directory
	@ mv coldformix-generated/temp/EN_1861 coldformix-generated/temp/refrigeration
	# install it qcad
	@ install -d $(PARTDIRQCAD)
	@ cp -r coldformix-generated/temp/refrigeration $(PARTDIRQCAD)
	# install it librecad
	@ install -d $(PARTDIRLIBRECAD)
	@ cp -r coldformix-generated/temp/refrigeration $(PARTDIRLIBRECAD)
	# clean up
	@ rm -rf coldformix-generated/temp





# install real_components in a Debian system
# qcad and librecad
install-rc-cad:
	# remove old stuff
	@ rm -rf coldformix-generated/temp
	@ mkdir -p coldformix-generated/temp
	# make a copy
	@ cp -a coldformix-source/refsym/real_components coldformix-generated/temp
	# delete unwanted files
	@ rm -rf coldformix-generated/temp/CVS
	@ rm -rf coldformix-generated/temp/real_components/CVS 
	@ rm -rf coldformix-generated/temp/real_components/*/CVS
	@ rm -rf coldformix-generated/temp/real_components/*/*.ps
	@ rm -rf coldformix-generated/temp/real_components/*/*/CVS
	@ rm -rf coldformix-generated/temp/real_components/*/*/*.ps
	@ rm -rf coldformix-generated/temp/real_components/*/*/*/CVS
	@ rm -rf coldformix-generated/temp/real_components/calculations
	# rename the directory
	@ mv coldformix-generated/temp/real_components coldformix-generated/temp/real-components
	# install it qcad
	@ install -d $(PARTDIRQCAD)
	@ cp -r coldformix-generated/temp/real-components $(PARTDIRQCAD)
	# install it librecad
	@ install -d $(PARTDIRLIBRECAD)
	@ cp -r coldformix-generated/temp/real-components $(PARTDIRLIBRECAD)
	# clean up
	@ rm -rf coldformix-generated/temp


# install rlt symbols DIN 1946 T1 in a Debian system
# qcad and librecad
install-rltsym-cad:
	# remove old stuff
	@ rm -rf coldformix-generated/temp
	@ mkdir -p coldformix-generated/temp
	# make a copy
	@ cp -a coldformix-source/rltsym coldformix-generated/temp
	# delete unwanted files
	@ rm -rf coldformix-generated/temp/CVS
	@ rm -rf coldformix-generated/temp/rltsym/CVS 
	@ rm -rf coldformix-generated/temp/rltsym/*/CVS
	@ rm -rf coldformix-generated/temp/rltsym/*/*.ps
	@ rm -rf coldformix-generated/temp/rltsym/*/*/CVS
	@ rm -rf coldformix-generated/temp/rltsym/*/*/*.ps
	@ rm -rf coldformix-generated/temp/rltsym/*/*/*/CVS
	# rename the directory
	@ mv coldformix-generated/temp/rltsym coldformix-generated/temp/rlt
	# install it qcad
	@ install -d $(PARTDIRQCAD)
	@ cp -r coldformix-generated/temp/rlt $(PARTDIRQCAD)
	# install it librecad
	@ install -d $(PARTDIRLIBRECAD)
	@ cp -r coldformix-generated/temp/rlt $(PARTDIRLIBRECAD)
	# clean up
	@ rm -rf coldformix-generated/temp




# delete EN_1861 from a Debian system
clean-refsym-cad-debian:
	rm -rf $(PARTDIRQCAD)/refrigeration
	rm -rf $(PARTDIRLIBRECAD)/refrigeration

# delete real_components from a Debian system
clean-rc-cad-debian:
	rm -rf $(PARTDIRQCAD)/real-components
	rm -rf $(PARTDIRLIBRECAD)/real-components

# delete rlt symbols from a Debian system
clean-rlt-cad-debian:
	rm -rf $(PARTDIRQCAD)/rlt
	rm -rf $(PARTDIRLIBRECAD)/rlt



ZIPDIR=$(DESTDIR)../../coldformix-generated/refsym

WWW=/var/www/coldformixhtdoc/download/refsym


install-refsym-server:



deb:
	### deb
	### Prepare to build an debian
	@echo 'Did you do a dch -i ?'
	@sleep 8
	dpkg-buildpackage -tc -uc -us -sa -rfakeroot
	@echo ''
	@echo 'Do not forget to tag this version in cvs'
	@echo ''



