strip address suffixes for better census coding, RT#86245
[freeside.git] / debian / rules
1 #!/usr/bin/make -f
2 # -*- makefile -*-
3
4 # Uncomment this to turn on verbose mode.
5 #export DH_VERBOSE=1
6
7 # If set to a true value then MakeMaker's prompt function will
8 # always return the default without waiting for user input.
9 #export PERL_MM_USE_DEFAULT=1
10
11 PERL   ?= /usr/bin/perl
12 #PACKAGE = $(shell dh_listpackages)
13 PACKAGE = freeside
14 TMP     = $(CURDIR)/debian/$(PACKAGE)
15 #DBC_SCRIPTS = $(TMP)/usr/share/dbconfig-common/scripts/freeside
16
17 ##this is gotten from dbconfig-common
18 DB_TYPE = Pg
19
20 #Data source
21 DATASOURCE = DBI:${DB_TYPE}:dbname=freeside
22
23 #no chance, it doesn't get backslash-interpolted now...
24 ##DEBVERSION                    = `head -1 debian/changelog | cut -d')' -f1 | cut -c11-`
25 #DEBVERSION                    = 1.7.3~rc2-1
26 #export VERSION                = $(DEBVERSION) (Debian)
27
28 #export FREESIDE_CONF          = /etc/freeside
29 #export FREESIDE_LOG           = /var/log/freeside
30 #export FREESIDE_LOCK          = /var/lock/freeside
31 #export FREESIDE_CACHE         = $(TMP)/var/cache/freeside
32 #FREESIDE_CACHE         = $(TMP)/var/cache/freeside
33
34 #XXX huh?
35 #export FREESIDE_EXPORT        = /var/spool/freeside
36
37 export FREESIDE_CONF = $(TMP)/usr/local/etc/freeside
38 export FREESIDE_LOG = $(TMP)/usr/local/etc/freeside
39 export FREESIDE_LOCK = $(TMP)/usr/local/etc/freeside
40 export FREESIDE_CACHE = $(TMP)/usr/local/etc/freeside
41 export FREESIDE_EXPORT = $(TMP)/usr/local/etc/freeside
42
43 export DIST_CONF = ${FREESIDE_CONF}/default_conf
44
45 #XXX own subdir?
46 #export MASON_HANDLER          = /usr/share/freeside/handler.pl
47 export MASON_HANDLER=$(TMP)-webui/usr/local/etc/freeside/handler.pl
48
49 export APACHE_VERSION        := $(shell /usr/sbin/apache2 -v | grep -q '\/2\.4\.' && echo '2.4' || echo '2')
50 export APACHE_DOCUMENT_ROOT  := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo '/var/www/html' || echo '/var/www')
51 export FREESIDE_DOCUMENT_ROOT = $(TMP)-webui$(APACHE_DOCUMENT_ROOT)/freeside
52 export POD2HTML_DOCUMENT_ROOT = $(FREESIDE_DOCUMENT_ROOT)/docs/library
53 export INIT_FILE              = $(TMP).init
54 export INIT_INSTALL           = /bin/true
55 export HTTPD_RESTART          = /bin/true
56 export APACHE_CONF           := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo "$(TMP)-webui/etc/apache2/conf-available" || echo "$(TMP)-webui/etc/apache2/conf.d")
57 export TORRUS_CONF           := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo "$(TMP)-torrus/etc/apache2/conf-available" || echo "$(TMP)-torrus/etc/apache2/conf.d")
58 export FREESIDE_RESTART       = /bin/true
59
60 #XXX root?
61 export INSTALLGROUP           = adm
62
63 export SELFSERVICE_MACHINES   = 
64
65 #prompt ?   XXX these are runtime, not buildtime :/
66 export RT_DOMAIN              =  freeside.biz
67 export RT_TIMEZONE            = US/Eastern
68 export HOSTNAME               = localhost
69 export FREESIDE_URL           = http://$(HOSTNAME)/freeside/
70
71 #specific to deb pkg, for purposes of saving off a permanent copy of default
72 #config for postinst and that sort of thing
73 #export DIST_CONF           = /usr/share/freeside/default_conf
74
75 #XXX yuck.  proper RT layout is entirely necessary
76 #this seems to infect way to much of RT with the build location, requiring
77 # a kludge to hack it out afterwords.  look into using fakeroot (didn't
78 # realize it would need to be explicit argh)
79 # (but leaving it for now, otherwise can't get RT to put files where we need em)
80 export RT_PATH                = $(TMP)-lib/opt/rt3
81
82 export TEXMF_PATH             = $(TMP)-lib/usr/local/share/texmf/tex/latex
83
84 # This has to be exported to make some magic below work.
85 export DH_OPTIONS
86
87 configure: configure-stamp
88 configure-stamp:
89         dh_testdir
90         # Add here commands to configure the package.
91         
92         touch configure-stamp
93
94
95 build: build-stamp
96 build-stamp: 
97         dh_testdir
98         # Add commands to compile the package here
99         
100         ( cd FS/ && $(PERL) Makefile.PL INSTALLDIRS=vendor && $(MAKE) )
101         $(MAKE) perl-modules
102         
103         ( cd fs_selfservice/FS-SelfService/ && $(PERL) Makefile.PL && $(MAKE) )
104         
105         #install this for freeside-setup
106         install -d $(DIST_CONF)
107         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
108
109         #TEST#
110
111         touch $@
112
113 clean:
114         dh_testdir
115         dh_testroot
116         dh_clean build-stamp install-stamp
117
118         # Add here commands to clean up after the build process.
119         $(MAKE) -e clean
120         #|| true #XXX freeside clean target fucked
121
122         dh_clean 
123
124 install: install-stamp
125 install-stamp: build-stamp
126         dh_testdir
127         dh_testroot
128         dh_clean -k
129         dh_installdirs
130
131         # Add here commands to install package into
132         # debian/<package>-whatever.
133
134         install -d $(FREESIDE_DOCUMENT_ROOT)
135         install -d $(TMP)-webui/usr/local/etc/freeside/
136         install -d $(TMP)-webui/etc/insserv/overrides/
137         install -d $(TMP)/usr/local/etc/freeside/
138 #       install -d $(TMP)-lib/usr/bin
139
140         ( cd FS/ && $(MAKE) -e DESTDIR=${TMP}-lib install)
141
142         # Install configuration files
143         install -d -o freeside ${FREESIDE_CONF}
144
145         touch ${FREESIDE_CONF}/secrets
146         chown freeside ${FREESIDE_CONF}/secrets
147         chmod 600 ${FREESIDE_CONF}/secrets
148
149         /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
150         chmod 600 ${FREESIDE_CONF}/secrets
151         chown freeside ${FREESIDE_CONF}/secrets
152
153         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
154         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
155
156         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
157         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
158
159         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
160         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
161
162         #install this for freeside-setup
163         install -d $(DIST_CONF)
164         #install conf/[a-z]* $(DEFAULT_CONF)
165         #CVS is not [a-z]
166         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
167
168         # Install interfaces
169         $(MAKE) -e DESTDIR=$(TMP)-webui install-docs
170         
171         # Install tex
172         install -d ${TEXMF_PATH}
173         install -o freeside -m 444 etc/*.sty ${TEXMF_PATH}
174         install -o root -m 444 -D etc/GnuMICR.otf $(TMP)-lib/usr/local/etc/freeside/GnuMICR.otf
175
176 # Create Apache configurations
177         install -d $(APACHE_CONF)
178         $(MAKE) -e DESTDIR=$(APACHE_CONF) install-apache
179         install -o root -m 755 init.d/insserv-override-apache2 $(TMP)-webui/etc/insserv/overrides/apache2
180
181         #Hack the build dir out of apache config
182
183         perl -p -i -e "\
184          s'${TMP}(-webui)?''g;\
185         " $(APACHE_CONF)/*
186
187         # Install init
188         $(MAKE) -e DESTDIR=$(TMP) install-init
189
190         #hack the build dir out of Freeside too.  oh yeah, sucky.
191         perl -p -i -e "\
192           s'${TMP}(-webui)?''g;\
193         " ${TMP}/usr/local/etc/freeside/handler.pl \
194           ${TMP}/usr/share/perl5/FS/* \
195           ${TMP}/usr/share/perl5/FS/*/* \
196           ${TMP}/usr/bin/*
197
198         #hack the build dur out of lib
199         perl -p -i -e "\
200           s'${TMP}-lib?''g;\
201           s'${TMP}(-webui)?''g;\
202         " ${TMP}/usr/local/etc/freeside/handler.pl \
203           ${TMP}-lib/usr/share/perl5/FS/*.pm \
204           ${TMP}-lib/usr/share/perl5/FS/*/*.pm 
205         
206         #hack the build dir out of Freeside binaries
207
208         perl -p -i -e "\
209           s'${TMP}?''g;\
210         " ${TMP}-lib/usr/bin/* \
211           ${TMP}-webui/usr/local/etc/freeside/handler.pl
212
213         # Self-service
214         
215         ( cd fs_selfservice/FS-SelfService/; $(MAKE) -e DESTDIR=${TMP}-selfservice-lib install ) 
216         install -d -o freeside -g freeside ${TMP}-selfservice-lib/usr/local/freeside
217         touch ${TMP}-selfservice-lib/usr/local/freeside/selfservice_socket 
218         chown -R freeside ${TMP}-selfservice-lib/usr/local/freeside
219         chmod 600 ${TMP}-selfservice-lib/usr/local/freeside/selfservice_socket
220         
221         install -d -o freeside -g freeside ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/
222         cp -R fs_selfservice/FS-SelfService/cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST
223         chown freeside.freeside ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*.cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*/*.cgi;
224         chmod 755 ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*.cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*/*.cgi
225
226         # NG-selfservice
227
228         install -d ${TMP}-ng-selfservice$(APACHE_DOCUMENT_ROOT)/
229         cp -R ng_selfservice ${TMP}-ng-selfservice$(APACHE_DOCUMENT_ROOT)/ng_selfservice-DIST/
230
231         # Torrus 
232         
233         #in freeside-webui package
234         #install -d ${TORRUS_CONF}
235         #install -o root -m 755 htetc/freeside-torrus.conf $(TORRUS_CONF)/
236
237         ( cd torrus; \
238         torrus_user=freeside var_user=freeside var_group=freeside ./configure; \
239         $(MAKE) -e DESTDIR=${TMP}-torrus/; \
240         $(MAKE) -e DESTDIR=${TMP}-torrus/ install; \
241         perl -p -i -e "\
242             s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
243         " ${TMP}-torrus/usr/local/etc/torrus/conf/torrus-siteconfig.pl )
244
245         #RT Config
246
247         ( cd rt; \
248           cp config.layout.in config.layout; \
249           perl -p -i -e "\
250             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
251             s'%%%MASONDATA%%%'${FREESIDE_CACHE}/masondata'g;\
252           " config.layout; \
253           ./configure --prefix=${RT_PATH} \
254                 --enable-layout=Freeside \
255                 --with-db-type=Pg \
256                 --with-db-dba=freeside \
257                 --with-db-database=freeside \
258                 --with-db-rt-user=freeside \
259                 --with-db-rt-pass="" \
260                 --with-web-user=freeside \
261                 --with-web-group=freeside \
262                 --with-rt-group=freeside \
263                 --with-web-handler=modperl2 )
264
265         ##(create-rt)
266         #$(MAKE) -e DESTDIR=${TMP}-lib create-rt
267         install -d $(RT_PATH)
268         install -d $(RT_PATH)/share
269
270         ( cd rt; $(MAKE) config-install dirs files-install fixperms instruct )
271         cp -r rt/share/static/images ${FREESIDE_DOCUMENT_ROOT}/rt/NoAuth/
272         
273         ##hack the build dir out of RT.  yeah, sucky.
274
275         perl -p -i -e "\
276         s'${TMP}(-webui|-lib)''g;\
277         s'${TMP}''g;\
278         " ${TMP}-lib/opt/rt3/etc/*.pm \
279                 ${TMP}-lib/opt/rt3/lib/*.pm \
280                 ${TMP}-lib/opt/rt3/lib/RT/*.pm \
281                 ${TMP}-lib/opt/rt3/etc/upgrade/* \
282                 ${TMP}-lib/opt/rt3/sbin/* \
283                 ${TMP}-lib/opt/rt3/bin/* \
284
285         # Default RT Settings
286         perl -p -i -e "\
287                 s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
288                 s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
289                 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
290                 " ${RT_PATH}/etc/RT_SiteConfig.pm
291
292         # Build pod2html documentation
293         install -d ${POD2HTML_DOCUMENT_ROOT}
294         perl -IFS -MFS::Misc::Pod2Html -e "FS::Misc::Pod2Html::fs_pod2html_from_src('${POD2HTML_DOCUMENT_ROOT}');"
295
296         dh_install
297
298         #touch $@
299
300 binary-arch:
301 # We have nothing to do here for an architecture-independent package
302
303 binary-indep: build install
304         dh_testdir
305         dh_testroot
306         dh_installdeb install
307         dh_installdocs #freeside.docs README AGPL
308         dh_installexamples eg bin
309 #       dh_installmenu
310         dh_installdebconf       
311 #       dh_installlogrotate     
312         dh_installinit --no-start 
313         dh_installcron
314 #       dh_installinfo
315         dh_installman
316         dh_perl
317         dh_link
318         dh_compress 
319         dh_fixperms -X/var/www/selfservice-DIST -X/usr/local/freeside
320         dh_gencontrol
321         dh_md5sums
322         dh_builddeb
323
324 binary: binary-indep binary-arch
325 .PHONY: build clean binary-indep binary-arch binary install