Makefile 13.7 KB
Newer Older
1 2
#!/usr/bin/make

3 4 5 6 7 8 9 10 11 12 13 14
# Prefix for packaging
DESTDIR=

# Perl options
#PERLOPTIONS="INSTALLDIRS=vendor"
PERLOPTIONS=

# Default directories install
PREFIX=/usr/local/
LMPREFIX=$(PREFIX)lemonldap-ng/
RLMPREFIX=$(DESTDIR)$(LMPREFIX)
# BIN dirs
15 16
BINDIR=$(LMPREFIX)bin/
RBINDIR=$(DESTDIR)$(BINDIR)
17 18 19 20
DATADIR=$(LMPREFIX)data/
RDATADIR=$(DESTDIR)$(DATADIR)


21
EXAMPLEROOT=`pwd`/example/
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

# Document roots for Apache VirtualHosts
DOCUMENTROOT=$(LMPREFIX)htdocs/
PORTALDIR=$(DOCUMENTROOT)portal/
RPORTALDIR=$(DESTDIR)$(PORTALDIR)
PORTALSKINSDIR=$(PORTALDIR)skins/
RPORTALSKINSDIR=$(DESTDIR)$(PORTALSKINSDIR)
LASPPORTALDIR=$(DOCUMENTROOT)liberty-alliance-sp-portal/
RLASPPORTALDIR=$(DESTDIR)$(LASPPORTALDIR)
MANAGERDIR=$(DOCUMENTROOT)manager/
RMANAGERDIR=$(DESTDIR)$(MANAGERDIR)
MANAGERDATADIR=$(MANAGERDIR)imgs/
RMANAGERDATADIR=$(DESTDIR)$(MANAGERDATADIR)
SESSIONSEXPLORERDIR=$(MANAGERDIR)
RSESSIONSEXPLORERDIR=$(DESTDIR)$(SESSIONSEXPLORERDIR)
SESSIONSEXPLORERDATADIR=$(SESSIONSEXPLORERDIR)images/
RSESSIONSEXPLORERDATADIR=$(DESTDIR)$(SESSIONSEXPLORERDATADIR)
DOCDIR=$(DOCUMENTROOT)doc/
RDOCDIR=$(DESTDIR)$(DOCDIR)
TESTDIR=$(DOCUMENTROOT)test/
RTESTDIR=$(DESTDIR)$(TESTDIR)
EXAMPLESDIR=$(LMPREFIX)examples/
REXAMPLESDIR=$(DESTDIR)$(EXAMPLESDIR)
TOOLSDIR=$(LMPREFIX)tools/
RTOOLSDIR=$(DESTDIR)$(TOOLSDIR)

DOCDIR=$(DOCUMENTROOT)doc/
RDOCDIR=$(DESTDIR)$(DOCDIR)

# Handler dir
HANDLERDIR=$(LMPREFIX)handler/
RHANDLERDIR=$(DESTDIR)$(HANDLERDIR)

# Configuration dir
CONFDIR=$(LMPREFIX)etc/
RCONFDIR=$(DESTDIR)$(CONFDIR)
CRONDIR=$(LMPREFIX)etc/cron.d/
RCRONDIR=$(DESTDIR)$(CRONDIR)
STORAGECONFFILE=$(CONFDIR)storage.conf

# Lemonldap-ng configuration storage dir
FILECONFIGDIR=$(DATADIR)conf/
RFILECONFIGDIR=$(DESTDIR)$(FILECONFIGDIR)

# Apache::Session::File storage dir
APACHESESSIONFILEDIR=$(DATADIR)sessions/
RAPACHESESSIONFILEDIR=$(DESTDIR)$(APACHESESSIONFILEDIR)
APACHESESSIONFILELOCKDIR=$(APACHESESSIONFILEDIR)lock/
RAPACHESESSIONFILELOCKDIR=$(DESTDIR)$(APACHESESSIONFILELOCKDIR)
APACHEUSER=
APACHEGROUP=

74
# DNS Domain for cookie and virtual hosts
75 76
DNSDOMAIN=example.com

77
# LDAP parameters
78 79 80 81
LDAPHOST=localhost
LDAPPORT=389
LDAPSUFFIX=dc=example,dc=net

82
# Other
83
VERSION=`head -n1 changelog |sed -e 's/lemonldap-ng (//' -e 's/).*$$//'`
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
SRCCOMMONDIR=lemonldap-ng-common/
SRCHANDLERDIR=lemonldap-ng-handler/
SRCPORTALDIR=lemonldap-ng-portal/
SRCMANAGERDIR=lemonldap-ng-manager/
EXAMPLELANG=en # For static Manager example only

#
# Perl libraries configuration
#
configure:	common_conf handler_conf portal_conf manager_conf

common_conf:
	@cd ${SRCCOMMONDIR}; LMNGCONFFILE=$(STORAGECONFFILE) perl Makefile.PL $(PERLOPTIONS)
	@touch common_conf

handler_conf:
	@cd ${SRCHANDLERDIR}; perl Makefile.PL $(PERLOPTIONS)
	@touch handler_conf

portal_conf:
	@cd ${SRCPORTALDIR}; perl Makefile.PL $(PERLOPTIONS)
	@touch portal_conf

manager_conf:
	@cd ${SRCMANAGERDIR}; perl Makefile.PL $(PERLOPTIONS)
	@touch manager_conf
110

111 112 113
#
# Perl libraries make
#
114 115 116 117 118
all:	common handler manager portal

common:		common_conf
	@$(MAKE) -C ${SRCCOMMONDIR}
	@touch common
119 120

handler:	handler_conf
121
	@$(MAKE) -C ${SRCHANDLERDIR}
122
	@touch handler
123 124

portal:		portal_conf
125
	@$(MAKE) -C ${SRCPORTALDIR}
126
	@touch portal
127 128

manager:	manager_conf
129
	@$(MAKE) -C ${SRCMANAGERDIR}
130
	@touch manager
131

132 133 134 135 136 137 138
test:		common handler portal manager common_test handler_test portal_test manager_test

common_test:	common
	@$(MAKE) -C ${SRCCOMMONDIR} test

handler_test:	handler common_test
	@$(MAKE) -C ${SRCHANDLERDIR} test INST_ARCHLIB=../${SRCCOMMONDIR}/blib/lib/
139

140 141
portal_test:	portal handler_test common_test
	@$(MAKE) -C ${SRCPORTALDIR} test INST_ARCHLIB=../${SRCCOMMONDIR}/blib/lib/
142

143 144
manager_test:	manager handler_test common_test
	@$(MAKE) -C ${SRCMANAGERDIR} test INST_ARCHLIB=../${SRCCOMMONDIR}/blib/lib/
145

146 147 148 149
#
# INSTALL
#
install:	install_libs install_bin install_site
150

151 152 153 154 155 156
#
# Perl libraires install
#
install_libs:	common_install_libs handler_install_libs portal_install_libs manager_install_libs

common_install_libs:		common
157
	@$(MAKE) -C ${SRCCOMMONDIR} install
158

159
handler_install_libs:	handler
160
	@$(MAKE) -C ${SRCHANDLERDIR} install
161

162
portal_install_libs:		portal
163
	@$(MAKE) -C ${SRCPORTALDIR} install
164

165
manager_install_libs:	manager
166
	@$(MAKE) -C ${SRCMANAGERDIR} install
167

168 169 170 171
example:
	@$(MAKE) -f $(MAKEFILE) install_site LMPREFIX=$(EXAMPLEROOT)

install_bin:	install_libs install_conf_dir
172 173 174 175
	# Binary install
	@install -v -d $(RBINDIR)
	cp --preserve=mode --remove-destination ${SRCPORTALDIR}/example/scripts/purgeCentralCache $(RBINDIR)
	cp --preserve=mode --remove-destination ${SRCMANAGERDIR}/example/scripts/lmConfigEditor $(RBINDIR)
176 177 178 179 180

#
# SITE INSTALL
#
install_site:	install_manager_site install_portal_site install_handler_site install_test_site install_examples_site
181
	# Site install
182 183 184 185 186 187 188 189 190 191 192 193
	@install -v -d $(RCONFDIR)
	# Apache configuration files
	@cp --remove-destination _example/etc/apache* $(RCONFDIR)
	@perl -i -pe 's#__HANDLER__#${HANDLERDIR}MyHandler.pm#; \
		s/__DNSDOMAIN__/$(DNSDOMAIN)/g; \
		s#__PORTALDIR__#$(PORTALDIR)#g; \
		s#__MANAGERDIR__#$(MANAGERDIR)#g; \
		s#__TESTDIR__#$(TESTDIR)#g; \
		s#__DOCDIR__#$(DOCDIR)#g;' $(RCONFDIR)/apache*
	# File for /etc/hosts inclusion
	@cp --remove-destination _example/etc/for_etc_hosts $(RCONFDIR)
	@perl -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)for_etc_hosts
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	#
	@echo
	@echo "LemonLDAP::NG example v${VERSION} is installed with these parameters:"
	@echo "  - System configuration: ${CONFDIR}"
	@echo "  - DNS domain (for cookies and virtual hosts): ${DNSDOMAIN}"
	@echo "  - LDAP parameters:"
	@echo "    - Host: ${LDAPHOST}"
	@echo "    - Port: ${LDAPPORT}"
	@echo "    - Suffix: ${LDAPSUFFIX}"
	@echo
	@echo "To finish configuration:"
	@echo
	@echo "1 - Add this in your Apache configuration file:"
	@echo "    with Apache-1.3.x"
	@echo "      include ${CONFDIR}apache.conf"
	@echo "    or with Apache-2.x:"
	@echo "      include ${CONFDIR}apache2.conf"
	@echo
	@echo "2 - Restart Apache (or Apache2)"
	@echo
	@echo "3 - Run 'make postconf' as root to update /etc/hosts" if your DNS service does not known auth.$(DNSDOMAIN) and manager.$(DNSDOMAIN)
	@echo
	@echo "4 - Use the manager at http://manager.${DNSDOMAIN}/ (after Apache restart) to modify LemonLDAP::NG configuration."
	@echo "    Edit ${DESTPORTALDIR}apps/apps-list.xml to modify the menu."
	@echo
	@echo "5 - Try to connect to http://test1.${DNSDOMAIN}/ or http://test2.${DNSDOMAIN}/"
	@if [ "$(APACHEUSER)" == "" ]; then \
		echo;echo "    Warning, since APACHEUSER was not set, $(APACHESESSIONFILEDIR) and $(CONFDIR) have permissive permissions."; \
		echo "    Fix them by yourself to restrict their view to apache process only"; \
	fi
	@echo
225 226 227 228 229 230 231 232 233

install_manager_site:	install_conf_dir
	# Manager install
	@install -v -d ${RMANAGERDIR} ${RMANAGERDATADIR} \
		${RSESSIONSEXPLORERDIR} $(RSESSIONSEXPLORERDATADIR) \
		$(RCONFDIR)
	@find ${RMANAGERDIR} -type l -name imgs -delete
	@find ${RMANAGERDIR} -type l -name images -delete
	@cp -pR --remove-destination ${SRCMANAGERDIR}example/* ${RMANAGERDIR}
234
	@rm -rf $$(find ${RMANAGERDIR} -type d -name .svn) ${RMANAGERDIR}scripts ${RMANAGERDIR}mrtg
235 236 237
	@if [ "${RMANAGERDIR}imgs/" != "${RMANAGERDATADIR}" ]; then \
		mv -f ${RMANAGERDIR}imgs/* ${RMANAGERDATADIR}; \
		rm -rf ${RMANAGERDIR}imgs; \
238
		ln -s $$(echo ${MANAGERDATADIR} | sed -e 's/\/$$//') ${RMANAGERDIR}imgs; \
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	fi
	# apply.conf install
	@mv ${RMANAGERDIR}apply.conf $(RCONFDIR)
	@perl -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)apply.conf
	@perl -i -pe 's#__APPLYCONFFILE__#$(CONFDIR)apply.conf#' ${RMANAGERDIR}index.pl
	# Sessions explorer install
	@if [ "${MANAGERDIR}" != "$(SESSIONSEXPLORERDIR)" ]; then mv -f ${RMANAGERDIR}sessions.pl $(RSESSIONSEXPLORERDIR); fi
	@if [ "${MANAGERDIR}images/" != "${SESSIONSEXPLORERDATADIR}" ]; then \
		mv -f ${RMANAGERDIR}images/* ${RSESSIONSEXPLORERDATADIR}; \
		rm -rf ${RMANAGERDIR}images; \
		ln -s $$(echo ${SESSIONSEXPLORERDATADIR} | sed -e 's/\/$$//') ${RMANAGERDIR}images; \
	fi

install_portal_site:	install_conf_dir
	# Portal install
	@install -v -d $(RPORTALDIR) $(RPORTALSKINSDIR) \
		$(RPORTALDIR)skins/ $(RLASPPORTALDIR) \
		$(RCRONDIR) $(RCONFDIR)
	@for skin in $$(ls lemonldap-ng-portal/example/skins/); do \
		[ -h $(RPORTALDIR)skins/$$skin ] && rm -f $(RPORTALDIR)skins/$$skin; \
		install -v -d $(RPORTALSKINSDIR)$$skin; \
	done
	@cp -pR --remove-destination ${SRCPORTALDIR}example/index_skin.pl ${RPORTALDIR}index.pl
	@cp -pR --remove-destination ${SRCPORTALDIR}example/error.pl ${RPORTALDIR}
	@perl -i -pe 's#__SKINDIR__#$(PORTALDIR)skins#; \
		s#__APPSXMLFILE__#$(CONFDIR)apps-list.xml#;' ${RPORTALDIR}index.pl ${RPORTALDIR}error.pl
	@cp -pR --remove-destination ${SRCPORTALDIR}example/skins/* $(RPORTALSKINSDIR)
	@if [ "$(PORTALDIR)skins/" != "$(PORTALSKINSDIR)" ]; then \
		for skin in $$(ls lemonldap-ng-portal/example/skins/); do \
			rm -rf $(RPORTALDIR)skins/$$skin/; \
			ln -s $(PORTALSKINSDIR)$$skin $(RPORTALDIR)skins/$$skin; \
		done; \
	fi
	@cp --remove-destination _example/etc/apps-list* $(RCONFDIR)
	@perl -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)apps-list.xml
	# L-A portal install
	@cp -pR --remove-destination ${SRCPORTALDIR}example/AuthLA/* $(RLASPPORTALDIR)
	@perl -i -pe 's#__DIR__#$(LASPPORTALDIR)#g' $(RLASPPORTALDIR)index.pl
	# Cron files
	@cp --remove-destination lemonldap-ng-portal/example/scripts/purgeCentralCache.cron.d $(RCRONDIR)
	# Clean SVN files
	@rm -rf $$(find ${RPORTALDIR} $(RPORTALSKINSDIR) $(RLASPPORTALDIR) -type d -name .svn)

install_handler_site:	install_conf_dir
283
	# Handler install
284 285 286 287
	@install -v -d ${RHANDLERDIR}
	@cp --remove-destination ${SRCHANDLERDIR}/example/MyHandler.pm ${RHANDLERDIR}

install_test_site:
288
	# Test site install
289 290 291 292 293
	@install -v -d $(RTESTDIR)
	@cp -pR --remove-destination _example/test/* $(RTESTDIR)
	@perl -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RTESTDIR)index.pl

install_examples_site:
294
	# Examples install
295
	@install -v -d $(REXAMPLESDIR)
296
	@for i in manager portal handler; do \
297 298
		cp -dpR --remove-destination lemonldap-ng-$$i/example $(REXAMPLESDIR)/$$i; \
	done
299 300 301
	@rm -rf $(REXAMPLESDIR)portal/skins \
		$(REXAMPLESDIR)manager/imgs \
		$(REXAMPLESDIR)manager/images \
302 303

install_conf_dir:	install_sessions_dir
304
	# Configuration files install
305 306 307
	@install -v -d $(RCONFDIR) $(RFILECONFIGDIR) $(RTOOLSDIR)
	@cp --remove-destination $(SRCCOMMONDIR)storage.conf $(RCONFDIR)
	@cp _example/conf/lmConf-1 $(RFILECONFIGDIR)
308
	perl -000 -i -pe "s#^(globalStorageOptions\\n\\s+)'[^\\n]*?'\$$#\$${1}\'\\$$data1 = {&39;Directory&39; => &39;$(APACHESESSIONFILEDIR)&39;,&39;LockDirectory&39; => &39;$(APACHESESSIONFILELOCKDIR)&39;};'#m" $(RFILECONFIGDIR)lmConf-1
309 310 311 312 313
	@perl -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g;\
		s/__LDAPPORT__/$(LDAPPORT)/g;\
		s/__LDAPHOST__/$(LDAPHOST)/g;\
		s/__LDAPSUFFIX__/$(LDAPSUFFIX)/g;\
		s#__SESSIONDIR__#$(APACHESESSIONFILEDIR)#g;' $(RFILECONFIGDIR)lmConf-1
314 315 316 317 318 319 320 321 322
	@if [ "$(APACHEUSER)" != "" ]; then \
		chown $(APACHEUSER) $(RFILECONFIGDIR) || exit 1; \
		if [ "$(APACHEGROUP)" != "" ]; then \
			chgrp $(APACHEGROUP) $(RFILECONFIGDIR) || exit 1; \
		fi; \
		chmod 770 $(RFILECONFIGDIR); \
	else \
		chmod 777 $(RFILECONFIGDIR); \
	fi
323 324 325 326 327 328
	@cp lemonldap-ng-common/tools/lmConfig.mysql lemonldap-ng-common/tools/apache-session-mysql.sql $(RTOOLSDIR)

install_sessions_dir:
	@install -m 777 -v -d $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR)
	# Fix Apache::Session directories permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
329
		chown $(APACHEUSER) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) || exit 1; \
330
		if [ "$(APACHEGROUP)" != "" ]; then \
331
			chgrp $(APACHEGROUP) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) || exit 1; \
332 333 334 335 336 337 338
		fi; \
		chmod 770 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR); \
	else \
		chmod 777 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR); \
	fi

TODO:
339 340 341 342 343

postconf_hosts:
	@cat ${SYSTEMCONFDIR}for_etc_hosts >> /etc/hosts
	@echo "/etc/hosts was updated"

344
postconf: postconf_hosts
345 346
	@echo "Post configuration done"

347 348
uninstall:	configure handler_uninstall portal_uninstall manager_uninstall

349 350 351 352
common_uninstall:	common
	@$(MAKE) -C ${SRCCOMMONDIR} uninstall
	@rm -vf common_uninstall

353
handler_uninstall:	handler
354
	@$(MAKE) -C ${SRCHANDLERDIR} uninstall
355
	@rm -vf handler_uninstall
356 357

portal_uninstall:		portal
358
	@$(MAKE) -C ${SRCPORTALDIR} uninstall
359
	@rm -vf portal_uninstall
360 361

manager_uninstall:	manager
362
	@$(MAKE) -C ${SRCMANAGERDIR} uninstall
363
	@rm -vf manager_uninstall
364

365
dist:	clean
366 367
	@- $(MAKE) clean
	@mkdir -p lemonldap-ng-$(VERSION)
368
	@- cp -pR lemonldap-ng-common/ lemonldap-ng-manager/ lemonldap-ng-portal/ lemonldap-ng-handler/ * lemonldap-ng-$(VERSION)
369 370 371 372
	@- dir=lemonldap-ng-$(VERSION); find $$dir -name .svn -exec rm -rf {} \; 2>/dev/null
	@rm -rf lemonldap-ng-$(VERSION)/lemonldap-ng-$(VERSION)
	@tar czf lemonldap-ng-$(VERSION).tar.gz lemonldap-ng-$(VERSION)
	@rm -rf lemonldap-ng-$(VERSION)
373

374
debian-dist:	dist
375
	@mv lemonldap-ng-$(VERSION).tar.gz lemonldap-ng_$(VERSION).orig.tar.gz
376

377 378 379 380 381
cpan:	clean configure common_cpan handler_cpan portal_cpan manager_cpan

common_cpan:	common_conf
	@$(MAKE) -C ${SRCCOMMONDIR} dist
	@mv ${SRCCOMMONDIR}/Lemonldap*.gz .
382 383

handler_cpan:	handler_conf
384 385
	@$(MAKE) -C ${SRCHANDLERDIR} dist
	@mv ${SRCHANDLERDIR}/Lemonldap*.gz .
386 387

portal_cpan:		portal_conf
388 389
	@$(MAKE) -C ${SRCPORTALDIR} dist
	@mv ${SRCPORTALDIR}/Lemonldap*.gz .
390 391

manager_cpan:	manager_conf
392 393
	@$(MAKE) -C ${SRCMANAGERDIR} dist
	@mv ${SRCMANAGERDIR}/Lemonldap*.gz .
394 395

static_example:	example
396 397 398
	@mkdir -p ${SCRIPTSDIR}static/
	@cd ${SCRIPTSDIR}static/;cp -a ../manager/{imgs,theme} .;cd -
	@../scripts/make_static_example.pl ${DESTMANAGERDIR}index.pl ${SCRIPTSDIR}static/index.html $(EXAMPLELANG)
399

400
documentation:
401
	@cd doc/ && ../scripts/doc.pl
402

403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
distclean:	clean

clean:		common_clean handler_clean portal_clean manager_clean
	@rm -rf $(EXAMPLEROOT)
	@rm -vf *gz

common_clean:
	- $(MAKE) -C ${SRCCOMMONDIR} distclean
	@rm -vf common*

handler_clean:
	- $(MAKE) -C ${SRCHANDLERDIR} distclean
	@rm -vf handler*

portal_clean:
	- $(MAKE) -C ${SRCPORTALDIR} distclean
	@rm -vf portal*

manager_clean:
	- $(MAKE) -C ${SRCMANAGERDIR} distclean
	@rm -vf manager*