Ticket #2916 Debian Packages
[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 = db_type_is_configured_during_pkg_install_by_dbconfig-common_not_at_build_time
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 export FREESIDE_SS = $(TMP)/usr/share/docs/freeside
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 FREESIDE_DOCUMENT_ROOT = /usr/share/freeside/www
50 export FREESIDE_DOCUMENT_ROOT = $(TMP)-webui/var/www/freeside
51 export INIT_FILE              = $(TMP).init
52 export INIT_INSTALL           = /bin/true
53 export HTTPD_RESTART          = /bin/true
54 #export APACHE_CONF           = /etc/apache2/conf.d
55 export APACHE_CONF            = $(TMP)-webui/etc/freeside/apache2
56 export FREESIDE_RESTART       = /bin/true
57
58 #XXX root?
59 export INSTALLGROUP           = adm
60
61 export SELFSERVICE_MACHINES   = 
62
63 #prompt ?   XXX these are runtime, not buildtime :/
64 export RT_DOMAIN              =  freeside.biz
65 export RT_TIMEZONE            = US/Eastern
66 export HOSTNAME               = localhost
67 export FREESIDE_URL           = http://$(HOSTNAME)/freeside/
68
69 #specific to deb pkg, for purposes of saving off a permanent copy of default
70 #config for postinst and that sort of thing
71 #export DIST_CONF           = /usr/share/freeside/default_conf
72
73 #XXX yuck.  proper RT layout is entirely necessary
74 #this seems to infect way to much of RT with the build location, requiring
75 # a kludge to hack it out afterwords.  look into using fakeroot (didn't
76 # realize it would need to be explicit argh)
77 # (but leaving it for now, otherwise can't get RT to put files where we need em)
78 export RT_PATH                = $(TMP)/opt/rt3
79
80 # This has to be exported to make some magic below work.
81 export DH_OPTIONS
82
83 configure: configure-stamp
84 configure-stamp:
85         dh_testdir
86         # Add here commands to configure the package.
87         
88         touch configure-stamp
89
90
91 build: build-stamp
92 build-stamp: 
93         dh_testdir
94         # Add commands to compile the package here
95         
96         ( cd FS/ && $(PERL) Makefile.PL INSTALLDIRS=vendor )
97
98         $(MAKE) -e DESTDIR=${TMP}-lib perl-modules
99
100         #TEST#
101
102         touch $@
103
104 clean:
105         dh_testdir
106         dh_testroot
107         dh_clean build-stamp install-stamp
108
109         # Add here commands to clean up after the build process.
110         $(MAKE) -e clean
111         #|| true #XXX freeside clean target fucked
112
113         dh_clean 
114
115 install: install-stamp
116 install-stamp: build-stamp
117         dh_testdir
118         dh_testroot
119         dh_clean -k
120         dh_installdirs
121
122         # Add here commands to install package into
123         # debian/<package>-whatever.
124
125         install -d $(FREESIDE_DOCUMENT_ROOT)
126         install -d $(TMP)-webui/usr/local/etc/freeside/
127         install -d $(TMP)/usr/local/etc/freeside/
128         install -d $(FREESIDE_CACHE)/masondata #MASONDATA
129
130         # Install configuration files
131         install -d -o freeside ${FREESIDE_CONF}
132
133         touch ${FREESIDE_CONF}/secrets
134         chown freeside ${FREESIDE_CONF}/secrets
135         chmod 600 ${FREESIDE_CONF}/secrets
136
137         /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
138         chmod 600 ${FREESIDE_CONF}/secrets
139         chown freeside ${FREESIDE_CONF}/secrets
140
141         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
142         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
143
144         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
145         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
146
147         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
148         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
149
150         #install this for freeside-setup
151         install -d $(DIST_CONF)
152         #install conf/[a-z]* $(DEFAULT_CONF)
153         #CVS is not [a-z]
154         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
155
156         # Install interfaces
157         $(MAKE) -e DESTDIR=$(TMP)-webui install-docs
158
159         # Create Apache configurations
160         install -d $(APACHE_CONF)
161         $(MAKE) -e DESTDIR=$(APACHE_CONF) install-apache
162
163         #Hack the build dir out of apache config
164
165         perl -p -i -e "\
166          s'${TMP}(-webui)?''g;\
167         "  $(TMP)-webui/etc/freeside/apache2/*
168
169         # Install init
170         $(MAKE) -e DESTDIR=$(TMP) install-init
171
172         #hack the build dir out of Freeside too.  oh yeah, sucky.
173         perl -p -i -e "\
174           s'${TMP}(-webui)?''g;\
175         " ${TMP}/usr/local/etc/freeside/handler.pl \
176           ${TMP}/usr/share/perl5/FS/* \
177           ${TMP}/usr/share/perl5/FS/*/* \
178           ${TMP}/usr/bin/*
179
180         #hack the build dur out of lib
181         perl -p -i -e "\
182           s'${TMP}-lib?''g;\
183           s'${TMP}(-webui)?''g;\
184         " ${TMP}/usr/local/etc/freeside/handler.pl \
185           ${TMP}-lib/usr/share/perl5/FS/*.pm \
186           ${TMP}-lib/usr/share/perl5/FS/*/*.pm 
187         
188         #hack the build dir out of Freeside binaries
189
190         perl -p -i -e "\
191           s'${TMP}?''g;\
192         " ${TMP}-lib/usr/bin/* \
193
194         #RT Config
195
196         ( cd rt; \
197           cp config.layout.in config.layout; \
198           perl -p -i -e "\
199             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
200             s'%%%MASONDATA%%%'${FREESIDE_CACHE}/masondata'g;\
201           " config.layout; \
202           ./configure --prefix=${RT_PATH} \
203                 --enable-layout=Freeside \
204                 --with-db-type=Pg \
205                 --with-db-dba=freeside \
206                 --with-db-database=freeside \
207                 --with-db-rt-user=freeside \
208                 --with-db-rt-pass="" \
209                 --with-web-user=freeside \
210                 --with-web-group=freeside \
211                 --with-rt-group=freeside \
212                 --with-web-handler=modperl2 )
213
214         ##(create-rt)
215         #$(MAKE) -e DESTDIR=${TMP}-lib create-rt
216         install -d $(RT_PATH)
217         install -d $(RT_PATH)/share
218
219         ( cd rt; $(MAKE) install )
220         
221         ##hack the build dir out of RT.  yeah, sucky.
222
223         perl -p -i -e "\
224         s'${TMP}(-webui)''g;\
225         s'${TMP}''g;\
226         " ${TMP}/opt/rt3/etc/*.pm \
227                 ${TMP}/opt/rt3/lib/*.pm \
228                 ${TMP}/opt/rt3/lib/RT/*.pm \
229                 ${TMP}/opt/rt3/etc/upgrade/* \
230                 ${TMP}/opt/rt3/sbin/* \
231                 ${TMP}/opt/rt3/bin/* \
232
233         # Default RT Settings
234         perl -p -i -e "\
235                 s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
236                 s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
237                 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
238                 " ${RT_PATH}/etc/RT_SiteConfig.pm
239
240         dh_install
241
242         #touch $@
243
244 binary-arch:
245 # We have nothing to do here for an architecture-independent package
246
247 binary-indep: build install
248         dh_testdir
249         dh_testroot
250         dh_installdeb install
251         dh_installdocs #freeside.docs README AGPL
252         dh_installexamples eg/*
253 #       dh_installmenu
254         dh_installdebconf       
255 #       dh_installlogrotate     
256         dh_installinit --no-start 
257         dh_installcron
258 #       dh_installinfo
259         dh_installman
260         dh_perl
261         dh_link
262         dh_compress 
263         dh_fixperms
264         dh_gencontrol
265         dh_md5sums
266         dh_builddeb
267
268 binary: binary-indep binary-arch
269 .PHONY: build clean binary-indep binary-arch binary install