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

Xavier Guimard's avatar
Xavier Guimard committed
3 4 5 6 7 8 9 10
# This Makefile contains 2 main sections
#  - Variables
#  - targets

# ---------
# VARIABLES
# ---------

11 12 13
# Prefix for packaging
DESTDIR=

14
# Flag for optimizations
15 16
USEDEBIANLIBS=no
PROD=$(USEDEBIANLIBS)
17
USEEXTERNALLIBS=no
18

Xavier Guimard's avatar
Xavier Guimard committed
19 20 21 22
# Perl options
#PERLOPTIONS="INSTALLDIRS=vendor"
PERLOPTIONS=

23 24 25 26
# Compression
JSCOMPRESS=$(PROD)
CSSCOMPRESS=$(PROD)

Xavier Guimard's avatar
Xavier Guimard committed
27
# External commands
28
PERL=$$(which perl)
29
PERLVERSION=`perl -e '$$version = $$^V; $$version =~ s/v//; print $$version'`
Xavier Guimard's avatar
Xavier Guimard committed
30 31 32
SU=su -c
COMPRESS=tar czf
UNCOMPRESS=tar xzf
Clément OUDOT's avatar
Clément OUDOT committed
33
LISTCOMPRESSED=tar tzf
Xavier Guimard's avatar
Xavier Guimard committed
34
COMPRESSSUFFIX=tar.gz
Xavier Guimard's avatar
Xavier Guimard committed
35
NGINX=/usr/sbin/nginx
36 37

# Default directories install
Xavier Guimard's avatar
Xavier Guimard committed
38 39 40
# ---------------------------

# Common dirs
41 42
PREFIX=/usr/local
LMPREFIX=$(PREFIX)/lemonldap-ng
43
# BIN dirs
44
BINDIR=$(LMPREFIX)/bin
45 46 47
SBINDIR=$(LMPREFIX)/sbin
INITDIR=$(LMPREFIX)/etc/init.d
ETCDEFAULTDIR=$(LMPREFIX)/etc/default
48
DATADIR=$(LMPREFIX)/data
49 50

# Document roots for Apache VirtualHosts
51 52
DOCUMENTROOT=$(LMPREFIX)/htdocs
PORTALDIR=$(DOCUMENTROOT)/portal
53 54
PORTALSITEDIR=$(PORTALDIR)/htdocs
PORTALSTATICDIR=$(PORTALSITEDIR)/static
55
PORTALRELATIVESTATICDIR=/static
56
PORTALTEMPLATESDIR=$(PORTALDIR)/templates
57

58
MANAGERDIR=$(DOCUMENTROOT)/manager
59 60
MANAGERSITEDIR=$(MANAGERDIR)/htdocs
MANAGERSTATICDIR=$(MANAGERSITEDIR)/static
Xavier Guimard's avatar
Xavier Guimard committed
61
MANAGERRELATIVESTATICDIR=/static
62
MANAGERTEMPLATESDIR=$(MANAGERSITEDIR)/templates
63 64 65
DOCDIR=$(DOCUMENTROOT)
DEFDOCDIR=$(DOCUMENTROOT)/doc
FRDOCDIR=$(DOCUMENTROOT)/fr-doc
66 67 68
TESTDIR=$(DOCUMENTROOT)/test
EXAMPLESDIR=$(LMPREFIX)/examples
TOOLSDIR=$(LMPREFIX)/tools
69 70

# Handler dir
71
HANDLERDIR=$(LMPREFIX)/handler
72 73

# Configuration dir
74 75
CONFDIR=$(LMPREFIX)/etc
CRONDIR=$(LMPREFIX)/etc/cron.d
76 77
CONFFILENAME=lemonldap-ng.ini
STORAGECONFFILE=$(CONFDIR)/$(CONFFILENAME)
78

79
# LL::NG configuration storage dir
80
FILECONFIGDIR=$(DATADIR)/conf
81

82
# LL::NG sessions storage dir
83 84
APACHESESSIONFILEDIR=$(DATADIR)/sessions
APACHESESSIONFILELOCKDIR=$(APACHESESSIONFILEDIR)/lock
85

86 87 88 89 90
# LL::NG persistent sessions storage dir
APACHEPSESSIONFILEDIR=$(DATADIR)/psessions
APACHEPSESSIONFILELOCKDIR=$(APACHEPSESSIONFILEDIR)/lock

# LL::NG notifications storage dir
91
APACHEFILENOTIFDIR=$(DATADIR)/notifications
92

93 94
# LL::NG captcha dir
CAPTCHADIR=$(DATADIR)/captcha
95

96
# Apache user/group
97 98
APACHEUSER=
APACHEGROUP=
99 100 101

# FastCGI
FASTCGISOCKDIR=$(PREFIX)/run
102 103
FASTCGIUSER=$(APACHEUSER)
FASTCGIGROUP=$(APACHEGROUP)
104

105
# Apache version
106
APACHEVERSION=2.X
107

108
# DNS Domain for cookie and virtual hosts
109 110
DNSDOMAIN=example.com

111
# Virtual Host Listen IP and Port (*, *:80, ...)
Xavier Guimard's avatar
Xavier Guimard committed
112 113
PORT=80
VHOSTLISTEN="*:$(PORT)"
114
TESTWEBSERVER=apache
Xavier Guimard's avatar
Xavier Guimard committed
115
TESTWEBSERVERPORT=19876
116
TESTUSESSL=0
117

118
# LDAP backend test
119 120 121
LLNGTESTLDAP_SLAPD_BIN=/usr/sbin/slapd
LLNGTESTLDAP_SLAPADD_BIN=/usr/sbin/slapdadd
LLNGTESTLDAP_SCHEMA_DIR=/etc/slapd/schema
122

123
# Other
124 125 126 127
SRCCOMMONDIR=lemonldap-ng-common
SRCHANDLERDIR=lemonldap-ng-handler
SRCPORTALDIR=lemonldap-ng-portal
SRCMANAGERDIR=lemonldap-ng-manager
Xavier Guimard's avatar
Xavier Guimard committed
128 129 130 131 132 133 134 135 136 137 138 139
ERASECONFIG=1 # Set to 0 if you do not want to replace your configuration

# INTERNAL VARIABLES

# Internal variables used to install in $(DESTDIR)
RLMPREFIX=$(DESTDIR)/$(LMPREFIX)
RBINDIR=$(DESTDIR)/$(BINDIR)
RSBINDIR=$(DESTDIR)/$(SBINDIR)
RINITDIR=$(DESTDIR)/$(INITDIR)
RETCDEFAULTDIR=$(DESTDIR)/$(ETCDEFAULTDIR)
RDATADIR=$(DESTDIR)/$(DATADIR)
RPORTALDIR=$(DESTDIR)/$(PORTALDIR)
140 141 142
RPORTALSITEDIR=$(DESTDIR)/$(PORTALSITEDIR)
RPORTALSTATICDIR=$(DESTDIR)/$(PORTALSTATICDIR)
RPORTALTEMPLATESDIR=$(DESTDIR)/$(PORTALTEMPLATESDIR)
Xavier Guimard's avatar
Xavier Guimard committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
RMANAGERDIR=$(DESTDIR)/$(MANAGERDIR)
RMANAGERSITEDIR=$(DESTDIR)/$(MANAGERSITEDIR)
RMANAGERSTATICDIR=$(DESTDIR)/$(MANAGERSTATICDIR)
RMANAGERTEMPLATESDIR=$(DESTDIR)/$(MANAGERTEMPLATESDIR)
RDOCDIR=$(DESTDIR)/$(DOCDIR)
RDEFDOCDIR=$(DESTDIR)/$(DEFDOCDIR)
RTESTDIR=$(DESTDIR)/$(TESTDIR)
REXAMPLESDIR=$(DESTDIR)/$(EXAMPLESDIR)
RTOOLSDIR=$(DESTDIR)/$(TOOLSDIR)
RHANDLERDIR=$(DESTDIR)/$(HANDLERDIR)
RCONFDIR=$(DESTDIR)/$(CONFDIR)
RCRONDIR=$(DESTDIR)/$(CRONDIR)
RFILECONFIGDIR=$(DESTDIR)/$(FILECONFIGDIR)
RAPACHESESSIONFILEDIR=$(DESTDIR)/$(APACHESESSIONFILEDIR)
RAPACHESESSIONFILELOCKDIR=$(DESTDIR)/$(APACHESESSIONFILELOCKDIR)
RAPACHEPSESSIONFILEDIR=$(DESTDIR)/$(APACHEPSESSIONFILEDIR)
RAPACHEPSESSIONFILELOCKDIR=$(DESTDIR)/$(APACHEPSESSIONFILELOCKDIR)
RFILENOTIFDIR=$(DESTDIR)/$(APACHEFILENOTIFDIR)
RCAPTCHADIR=$(DESTDIR)/$(CAPTCHADIR)
RFASTCGISOCKDIR=$(DESTDIR)/$(FASTCGISOCKDIR)
163 164

VERSION=`head -n1 changelog |sed -e 's/lemonldap-ng (//' -e 's/).*$$//'`
165
PORTALSKINS=`ls $(SRCPORTALDIR)/site/templates/`
166
DIFF=diff -aurN -x '*.tpl' -x '*.bak' -x .svn -x '*.map' -x '*.min.js' -x '*.min.css' -x '*.swp' --ignore-matching-lines='.*jquery.*' --ignore-matching-lines='.*lemonldap-ng\.ini.*'
167 168
DIFFPREFIX=

169

170 171
MANAGERLIBSTOREMOVEFORDEBIAN=$(RMANAGERSTATICDIR)/bwr/jquery/ \
			$(RMANAGERSTATICDIR)/bwr/angular/ \
172
			$(RMANAGERSTATICDIR)/bwr/angular-animate/ \
173 174 175
			$(RMANAGERSTATICDIR)/bwr/angular-cookie/ \
			$(RMANAGERSTATICDIR)/bwr/bootstrap/ \
			$(RMANAGERSTATICDIR)/bwr/es5-shim/
176 177 178 179
PORTALLIBSTOREMOVEFORDEBIAN=$(RPORTALSTATICDIR)/bwr/bootstrap/ \
			$(RPORTALSTATICDIR)/bwr/jquery-ui \
			$(RPORTALSTATICDIR)/bwr/jquery.cookie \
			$(RPORTALSTATICDIR)/bwr/jquery
Xavier Guimard's avatar
Xavier Guimard committed
180 181 182
DOCLIBSTOREMOVEFORDEBIAN=pages/documentation/current/lib/tpl/bootstrap3 \
			pages/documentation/current/lib/scripts/jquery-ui*.js \
			pages/documentation/current/bootswatch/3.3.4/flatly/bootstrap.min.css
Xavier Guimard's avatar
Xavier Guimard committed
183
DOCEXTERNALLIBS=$(DOCLIBSTOREMOVEFORDEBIAN)
184
MANAGEREXTERNALLIBS=$(RMANAGERSTATICDIR)/bwr/
185
PORTALEXTERNALLIBS=$(PORTALLIBSTOREMOVEFORDEBIAN)
186

Xavier Guimard's avatar
Xavier Guimard committed
187
# GENERATED SRC FILES
188
MANAGERJSONSRC= scripts/jsongenerator.pl \
Xavier Guimard's avatar
Xavier Guimard committed
189
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build.pm \
190
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/Attributes.pm \
191
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/Tree.pm \
192
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/CTrees.pm \
193
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Conf/Zero.pm
194 195
MANAGERJSONDST=$(SRCMANAGERDIR)/site/htdocs/static/struct.json \
		$(SRCMANAGERDIR)/site/htdocs/static/js/conftree.js \
Xavier Guimard's avatar
Xavier Guimard committed
196
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Attributes.pm \
197
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/ReConstants.pm \
198
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/DefaultValues.pm \
199
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/Constants.pm \
200
		_example/conf/lmConf-1.json
201 202

# Javascript and CSS to minify
203 204
JSSRCFILES:=$(shell find */site/htdocs/static/js $(SRCPORTALDIR)/site/htdocs/static -type f -name '*.js' ! -name '*.min.js') \
		$(SRCMANAGERDIR)/site/htdocs/static/bwr/file-saver.js/FileSaver.js
Xavier Guimard's avatar
Xavier Guimard committed
205
CSSSRCFILES:=$(shell find $(SRCMANAGERDIR)/site/htdocs/static  $(SRCPORTALDIR)/site/htdocs/static -type f -name '*.css' ! -name '*.min.css')
206

207
# Coffee files
208 209 210
MANAGERCOFFEESRCFILES:=$(shell find lemonldap-ng-manager/site/coffee -type f -name '*.coffee')
PORTALCOFFEESRCFILES:=$(shell find lemonldap-ng-portal/site/coffee -type f -name '*.coffee')
COFFEESRCFILES=$(MANAGERCOFFEESRCFILES) $(PORTALCOFFEESRCFILES)
211
MANAGERCOFFEEDSTFILES:=$(subst coffee/,htdocs/static/js/,$(MANAGERCOFFEESRCFILES:.coffee=.js))
212 213
PORTALCOFFEEDSTFILES:=$(subst coffee/,htdocs/static/common/js/,$(PORTALCOFFEESRCFILES:.coffee=.js))
COFFEEDSTFILES:=$(MANAGERCOFFEEDSTFILES) $(PORTALCOFFEEDSTFILES)
214

215 216 217
# Minified files
JSDSTFILES=$(JSSRCFILES:.js=.min.js)
CSSDSTFILES=$(CSSSRCFILES:.css=.min.css)
Xavier Guimard's avatar
Xavier Guimard committed
218

Xavier Guimard's avatar
Xavier Guimard committed
219 220 221 222 223
# -------
# TARGETS
# -------

# Targets section contains the following subsections:
224
#  - 'all' that must be defined at first
Xavier Guimard's avatar
Xavier Guimard committed
225 226 227 228 229 230 231 232 233 234
#  - configure targets
#  - make targets
#  - test targets
#  - end-to-end tests
#  - install targets
#  - cleaning targets
#  - Perl libraries uninstall targets
#  - packaging targets
#  - developper corner

235 236 237 238 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
all:	configure common handler manager portal
	@echo
	@echo "Building succeed. Now run :"
	@echo " - 'make test' to verify your installation"
	@echo " - 'make install PROD=yes' to install all"
	@echo
	@echo "    MAKE INSTALL OPTIONS:"
	@echo "    - PROD=yes            : use js/css minified files"
	@echo "    - USEDEBIANLIBS=yes   : use some Debian shared js/css files"
	@echo "    - USEEXTERNALLIBS=yes : use external links for some js/css files"
	@echo
	@echo 'Other targets :'
	@echo " * Partial build :"
	@echo "   - portal, manager, handler"
	@echo
	@echo 'Other targets launched by "make install" :'
	@echo " * Perl libraries install :"
	@echo "   - install_libs           (all Perl libraries)"
	@echo "   - install_portal_libs"
	@echo "   - install_manager_libs"
	@echo "   - install_handler_libs"
	@echo " * Binaries install :"
	@echo "   - install_bin            ($(BINDIR))"
	@echo " * FastCGI server install   (required for Nginx)"
	@echo "   - install_fastcgi_server ($(SBINDIR))"
	@echo " * Web sites install :"
	@echo "   - install_site           (all sites including install_doc_site)"
	@echo "   - install_portal_site    ($(PORTALDIR))"
	@echo "   - install_manager_site   ($(MANAGERDIR))"
	@echo "   - install_handler_site   ($(HANDLERDIR))"
	@echo " * Documentation install :"
	@echo "   - install_doc_site       ($(DEFDOCDIR))"
	@echo "   - install_examples_site  ($(EXAMPLESDIR))"
	@echo
	@echo "Other languages documentation (fr only for now)"
	@echo " - fr-doc                  (needs OmegaT)"
	@echo " - install_fr_doc_site"
	@echo

Xavier Guimard's avatar
Xavier Guimard committed
274 275 276
# Configure targets
# -----------------

277
configure:	common_conf handler_conf portal_conf manager_conf
Xavier Guimard's avatar
Xavier Guimard committed
278

Xavier Guimard's avatar
Xavier Guimard committed
279 280 281
js: $(COFFEEDSTFILES)

minify: js $(JSDSTFILES) $(CSSDSTFILES)
Xavier Guimard's avatar
Xavier Guimard committed
282

283
$(SRCPORTALDIR)/site/htdocs/static/common/js/%.js: $(SRCPORTALDIR)/site/coffee/%.coffee
Xavier Guimard's avatar
Xavier Guimard committed
284 285
	@if which coffee >/dev/null; then \
		echo "Compiling $(SRCPORTALDIR)/site/coffee/$*.coffee"; \
286
		coffee -c -o $(SRCPORTALDIR)/site/htdocs/static/common/js/ $(SRCPORTALDIR)/site/coffee/$*.coffee; \
Xavier Guimard's avatar
Xavier Guimard committed
287 288
	fi

Xavier Guimard's avatar
Typo  
Xavier Guimard committed
289
$(SRCMANAGERDIR)/site/htdocs/static/js/%.js: $(SRCMANAGERDIR)/site/coffee/%.coffee
290 291
	@if which coffee >/dev/null; then \
		echo "Compiling $(SRCMANAGERDIR)/site/coffee/$*.coffee"; \
292
		coffee -c -o $(SRCMANAGERDIR)/site/htdocs/static/js/ $(SRCMANAGERDIR)/site/coffee/$*.coffee; \
293 294
	fi

Xavier Guimard's avatar
Xavier Guimard committed
295 296 297 298 299 300 301 302 303
%.min.css: %.css
	@echo "Compressing $*.css"
	@yui-compressor $*.css > $*.min.css

%.min.js: %.js
	@echo "Compressing $*.js"
	@yui-compressor $*.js > $*.min.js

fastcgi-server/man/llng-fastcgi-server.1p: fastcgi-server/sbin/llng-fastcgi-server
Xavier Guimard's avatar
Xavier Guimard committed
304
	@echo Update FastCGI server man page
Xavier Guimard's avatar
Xavier Guimard committed
305 306 307 308 309
	@pod2man -name llng-fastcgi-server fastcgi-server/sbin/llng-fastcgi-server >fastcgi-server/man/llng-fastcgi-server.1p

# Perl libraries configuration

json:	$(MANAGERJSONDST) fastcgi-server/man/llng-fastcgi-server.1p
310
	@if which yui-compressor >/dev/null; then $(MAKE) minify; fi
Xavier Guimard's avatar
Xavier Guimard committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

$(MANAGERJSONDST):	$(MANAGERJSONSRC)
	./scripts/jsongenerator.pl

common_conf:	${SRCCOMMONDIR}/Makefile

handler_conf:	${SRCHANDLERDIR}/Makefile

portal_conf:	${SRCPORTALDIR}/Makefile

manager_conf:	${SRCMANAGERDIR}/Makefile

${SRCCOMMONDIR}/Makefile:
	@cd ${SRCCOMMONDIR}; LMNGCONFFILE=$(STORAGECONFFILE) $(PERL) Makefile.PL $(PERLOPTIONS)

${SRCHANDLERDIR}/Makefile:
	@cd ${SRCHANDLERDIR}; $(PERL) Makefile.PL $(PERLOPTIONS)

${SRCPORTALDIR}/Makefile:
	@cd ${SRCPORTALDIR}; $(PERL) Makefile.PL $(PERLOPTIONS)

${SRCMANAGERDIR}/Makefile:
	@cd ${SRCMANAGERDIR}; $(PERL) Makefile.PL $(PERLOPTIONS)

# Make targets
# ------------

338
common:		common_conf
339
	@$(MAKE) -C ${SRCCOMMONDIR}
340

Xavier Guimard's avatar
Xavier Guimard committed
341
handler:	handler_conf common
342
	@$(MAKE) -C ${SRCHANDLERDIR}
343

344
portal:		portal_conf handler
345
	@$(MAKE) -C ${SRCPORTALDIR}
346

Xavier Guimard's avatar
Xavier Guimard committed
347
manager:	manager_conf handler
348
	$(MAKE) -C ${SRCMANAGERDIR}
349

Xavier Guimard's avatar
Xavier Guimard committed
350 351
# Test targets
# ------------
352
test:		all common_test handler_test portal_test manager_test
353 354 355 356

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

Xavier Guimard's avatar
Xavier Guimard committed
357
handler_test:	handler
358
	@$(MAKE) -C ${SRCHANDLERDIR} test FULLPERL="$(PERL) -I../${SRCCOMMONDIR}/blib/lib/"
359

Xavier Guimard's avatar
Xavier Guimard committed
360
portal_test:	portal
361
	@$(MAKE) -C ${SRCPORTALDIR} test FULLPERL="$(PERL) -I../${SRCCOMMONDIR}/blib/lib/ -I../${SRCHANDLERDIR}/blib/lib/"
362

Xavier Guimard's avatar
Xavier Guimard committed
363
manager_test:	manager
364
	@$(MAKE) -C ${SRCMANAGERDIR} test FULLPERL="$(PERL) -I../${SRCCOMMONDIR}/blib/lib/ -I../${SRCHANDLERDIR}/blib/lib/"
365

366
# End-to-end tests
Xavier Guimard's avatar
Xavier Guimard committed
367 368
# ----------------

369 370
e2e_test:	all prepare_test_server start_web_server launch_protractor stop_web_server

371 372 373 374 375 376
nox_full_test:	test prepare_test_server start_web_server
	X -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./e2e-tests/conf/X.log -config ./e2e-tests/xorg.conf :11 & \
		echo $$! > e2e-tests/conf/X.pid
	-DISPLAY=:11 $(MAKE) launch_protractor
	kill $$(cat e2e-tests/conf/X.pid)
	$(MAKE) stop_web_server
377

378
prepare_test_server:
379 380
	-@mkdir -p e2e-tests/conf/sessions/lock e2e-tests/conf/persistents/lock
	-@mkdir e2e-tests/conf/manager e2e-tests/conf/portal
381 382
	$(MAKE) install_webserver_conf install_test_site install_fastcgi_server \
		CONFDIR=`pwd`/e2e-tests/conf \
383 384
		RCONFDIR=e2e-tests/conf \
		ERASECONFIG=1 \
Xavier Guimard's avatar
Xavier Guimard committed
385 386
		VHOSTLISTEN='*:$(TESTWEBSERVERPORT)' \
		PORT=$(TESTWEBSERVERPORT) \
Xavier Guimard's avatar
Xavier Guimard committed
387
		FASTCGISOCKDIR=`pwd`/e2e-tests/conf \
Xavier Guimard's avatar
Xavier Guimard committed
388 389 390 391
		PORTALSITEDIR=`pwd`/e2e-tests/conf/portal \
		PORTALSTATICDIR=`pwd`/$(SRCPORTALDIR)/site/htdocs/static \
		MANAGERSITEDIR=`pwd`/e2e-tests/conf/manager \
		MANAGERSTATICDIR=`pwd`/$(SRCMANAGERDIR)/site/htdocs/static \
Xavier Guimard's avatar
Xavier Guimard committed
392
		TESTDIR=`pwd`/e2e-tests/conf/site \
393
		DEFDOCDIR=`pwd`/doc \
394 395 396 397
		FRDOCDIR=`pwd`/po-doc/fr \
		SBINDIR=`pwd`/e2e-tests/conf/sbin \
		INITDIR=`pwd`/e2e-tests/conf/init \
		ETCDEFAULTDIR=`pwd`/e2e-tests/conf/def
398
	#@cp -f e2e-tests/index.* e2e-tests/conf/
Xavier Guimard's avatar
Xavier Guimard committed
399
	@perl -i -pe 's/example\.com/example.com:19876/g' e2e-tests/conf/site/index.pl
400 401
	@cp -f $(SRCMANAGERDIR)/site/htdocs/manager* e2e-tests/conf/manager
	@cp -f $(SRCPORTALDIR)/site/htdocs/index* e2e-tests/conf/portal
402
	@cp e2e-tests/saml-sp.xml e2e-tests/conf/site/saml-sp.xml
403 404 405
	@for f in $$(find e2e-tests/conf -name '*.fcgi'); do \
		perl -i -pe 'if($$.==2){print "BEGIN{\n"; print qq(use lib q('`pwd`'/lemonldap-ng-$$_/blib/lib);\n) foreach qw(common handler portal manager); print "}\n"; }' $$f; \
	done
Xavier Guimard's avatar
Xavier Guimard committed
406
	@cp e2e-tests/lmConf-1.json e2e-tests/lemonldap-ng*.ini e2e-tests/env.conf e2e-tests/test-nginx.conf e2e-tests/conf/
Xavier Guimard's avatar
Xavier Guimard committed
407
	@cp e2e-tests/form.html e2e-tests/conf/site
Xavier Guimard's avatar
Xavier Guimard committed
408
	@perl -i -pe 'BEGIN{$$p=`pwd`;chomp $$p}s#__pwd__#$$p#;s#__port__#$(TESTWEBSERVERPORT)#;s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#;' \
Xavier Guimard's avatar
Xavier Guimard committed
409
		e2e-tests/conf/lemonldap-ng*.ini \
410
		e2e-tests/conf/lmConf-1.json \
411 412
		e2e-tests/conf/env.conf \
		e2e-tests/conf/test-nginx.conf
413 414 415 416
	@if test "$(TESTUSESSL)" = "1"; then \
		perl -i -pe 's#http://(test|mana|auth)#https://$$1#' e2e-tests/conf/lmConf-1.json e2e-tests/conf/handler-apache2.X.conf e2e-tests/conf/site/index.pl; \
		perl -i -pe 's#"https": 0#"https": 1#' e2e-tests/conf/lmConf-1.json; \
	fi
417

Xavier Guimard's avatar
Xavier Guimard committed
418 419 420
e2e-tests/conf/apache2.pid: start_web_server

start_web_server:	all prepare_test_server
Xavier Guimard's avatar
Xavier Guimard committed
421
	# Clean old server if launched
Xavier Guimard's avatar
Hide  
Xavier Guimard committed
422
	@if test "$(TESTBACKEND)" = "DBI"; then \
Xavier Guimard's avatar
Xavier Guimard committed
423 424 425 426 427 428
		echo 'create table lmConfig (cfgNum int, data text);'|sqlite3 e2e-tests/conf/config.db; \
		echo 'create table sessions (id text, a_session text, LastUpdated int);'|sqlite3 e2e-tests/conf/sessions.db; \
		perl -Ilemonldap-ng-common/blib/lib ./lemonldap-ng-common/scripts/convertConfig \
			--current=e2e-tests/conf/lemonldap-ng.ini \
			--new=e2e-tests/conf/lemonldap-ng-sql.ini; \
		mv e2e-tests/conf/lemonldap-ng-sql.ini e2e-tests/conf/lemonldap-ng.ini; \
Xavier Guimard's avatar
Xavier Guimard committed
429 430 431 432 433 434 435 436
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
			perl -Ilemonldap-ng-common/blib/lib -Ilemonldap-ng-manager/blib/lib -Ilemonldap-ng-handler/blib/lib \
				lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
				set globalStorage Apache::Session::SQLite3; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
			perl -Ilemonldap-ng-common/blib/lib -Ilemonldap-ng-manager/blib/lib -Ilemonldap-ng-handler/blib/lib \
				lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
				addKey globalStorageOptions DataSource 'dbi:SQLite:dbname='`pwd`'/e2e-tests/conf/sessions.db'; \
Xavier Guimard's avatar
Xavier Guimard committed
437
	fi
Xavier Guimard's avatar
Tidy  
Xavier Guimard committed
438
	@# Debian: make start_web_server TESTBACKEND=LDAP LLNGTESTLDAP_SCHEMA_DIR=/etc/ldap/schema LLNGTESTLDAP_SLAPADD_BIN=/usr/sbin/slapadd
Xavier Guimard's avatar
Xavier Guimard committed
439
	@if test "$(TESTBACKEND)" = "LDAP"; then \
Xavier Guimard's avatar
Tidy  
Xavier Guimard committed
440 441 442 443 444 445 446 447 448
		cp lemonldap-ng-portal/t/testslapd/slapd.ldif e2e-tests/conf/; \
		mkdir e2e-tests/conf/slapd.d; \
		mkdir e2e-tests/conf/data; \
		sed -i 's:__SCHEMA_DIR__:${LLNGTESTLDAP_SCHEMA_DIR}:' e2e-tests/conf/slapd.ldif; \
		sed -i 's|olcDbDirectory.*|olcDbDirectory: e2e-tests/conf/data|' e2e-tests/conf/slapd.ldif; \
		sed -i 's|olcPidFile.*|olcPidFile: e2e-tests/conf/slapd.pid|' e2e-tests/conf/slapd.ldif; \
		${LLNGTESTLDAP_SLAPADD_BIN} -F e2e-tests/conf/slapd.d -n 0 -l e2e-tests/conf/slapd.ldif; \
		${LLNGTESTLDAP_SLAPADD_BIN} -F e2e-tests/conf/slapd.d -n 1 -l lemonldap-ng-portal/t/testslapd/confs-sessions.ldif; \
		${LLNGTESTLDAP_SLAPD_BIN} -s 511 -h "ldap://127.0.0.1:20389/" -F e2e-tests/conf/slapd.d; \
449 450 451 452
		perl -Ilemonldap-ng-common/blib/lib ./lemonldap-ng-common/scripts/convertConfig \
			--current=e2e-tests/conf/lemonldap-ng.ini \
			--new=e2e-tests/conf/lemonldap-ng-ldap.ini; \
		mv e2e-tests/conf/lemonldap-ng-ldap.ini e2e-tests/conf/lemonldap-ng.ini; \
Xavier Guimard's avatar
Tidy  
Xavier Guimard committed
453
	fi
454 455
	-@[ -e e2e-tests/conf/apache2.pid ] && kill `cat e2e-tests/conf/apache2.pid` || true
	-@[ -e e2e-tests/conf/nginx.pid ]   && kill `cat e2e-tests/conf/nginx.pid` || true
456
	-@[ -e e2e-tests/conf/llng-fastcgi.pid ] && kill `cat e2e-tests/conf/llng-fastcgi.pid` && rm -f e2e-tests/conf/llng-fastcgi.pid || true
457
	# Start web server (designed for Debian, path may be broken else)
Xavier Guimard's avatar
Xavier Guimard committed
458
	@if test "$(TESTWEBSERVER)" = "apache"; then \
459 460 461 462 463 464
		if test "$(TESTUSESSL)" = "1"; then \
			APACHEARGS=-DUseSSL; \
		else \
			APACHEARGS=; \
		fi; \
		LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini /usr/sbin/apache2 -d `pwd`/e2e-tests -f apache2.conf $$APACHEARGS -k start; \
465
	elif test "$(TESTWEBSERVER)" = "nginx"; then \
Xavier Guimard's avatar
Xavier Guimard committed
466 467 468 469 470
		echo "Testing nginx conf"; \
		$(NGINX) -t -p `pwd`/e2e-tests \
			-g 'error_log '`pwd`'/e2e-tests/conf/nginx.log;' \
			-c `pwd`/e2e-tests/nginx.conf \
			2>&1 | grep -v 'Permission denied' || true; \
471 472
		echo "Launching nginx"; \
		$(NGINX) -p `pwd`/e2e-tests \
473
			-g 'error_log '`pwd`'/e2e-tests/conf/nginx.log;' \
474 475
			-c `pwd`/e2e-tests/nginx.conf \
			2>&1 | grep -v 'Permission denied' || true; \
476
		echo "Launching plackup"; \
Xavier Guimard's avatar
Xavier Guimard committed
477
		$(MAKE) plackup; \
Xavier Guimard's avatar
Xavier Guimard committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
	elif test "$(TESTWEBSERVER)" = "starman"; then \
		if test "$(TESTUSESSL)" = "1"; then \
			ARGS="--ssl-cert-file e2e-tests/cert.pem --ssl-key-file e2e-tests/key.pem --enable-ssl"; \
		else \
			ARGS=; \
		fi; \
		echo "ARGS=$$ARGS"; \
		LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini \
		PERL5LIB=`pwd`/lemonldap-ng-common/blib/lib/:`pwd`/lemonldap-ng-handler/blib/lib/:`pwd`/lemonldap-ng-portal/blib/lib/:`pwd`/lemonldap-ng-manager/blib/lib/ \
		/usr/bin/start_server \
			--log-file=e2e-tests/conf/starman.log \
			--pid-file=e2e-tests/conf/server.pid \
			--status-file=e2e-tests/conf/server-status.pid \
			--daemonize \
			-- starman \
			--port=$(TESTWEBSERVERPORT) \
			--workers 3 \
			$$ARGS \
			e2e-tests/llng.psgi; \
497 498 499 500
	else \
		echo "!!!!! Unknown test server: $(TESTWEBSERVER) !!!!!" >&2; \
		exit 1; \
	fi
501

Xavier Guimard's avatar
Xavier Guimard committed
502
reload_web_server:
503
	@if [ -e e2e-tests/conf/apache2.pid ]; then \
Xavier Guimard's avatar
Xavier Guimard committed
504 505
		LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini \
		/usr/sbin/apache2 -d `pwd`/e2e-tests -f apache2.conf -k graceful; \
506
	elif [ -e e2e-tests/conf/nginx.pid ]; then \
Xavier Guimard's avatar
Xavier Guimard committed
507 508 509 510 511
		$(NGINX) -p `pwd`/e2e-tests \
			-g 'error_log '`pwd`'/e2e-tests/conf/nginx.log;' \
			-c `pwd`/e2e-tests/nginx.conf \
			-s reload \
			2>&1 | grep -v 'Permission denied' || true; \
512
		kill `cat e2e-tests/conf/llng-fastcgi.pid` || true; \
Xavier Guimard's avatar
Xavier Guimard committed
513
		$(MAKE) plackup; \
Xavier Guimard's avatar
Xavier Guimard committed
514 515 516 517 518
	elif [ -e e2e-tests/conf/server.pid ]; then \
		/usr/bin/start_server\
			--pid-file=e2e-tests/conf/server.pid \
			--status-file=e2e-tests/conf/server-status.pid \
			--restart; \
519 520 521 522
	else \
		$(MAKE) start_web_server; \
	fi

523
launch_protractor:
524
	# Start e2e tests
Xavier Guimard's avatar
Xavier Guimard committed
525
	# NB: you must have protractor installed (using npm install -g protractor)
Xavier Guimard's avatar
Xavier Guimard committed
526
	# and have run update-webdriver at least once and have a node.js > 4.0
Xavier Guimard's avatar
Xavier Guimard committed
527
	@TESTWEBSERVERPORT=$(TESTWEBSERVERPORT) protractor e2e-tests/protractor-conf.js
528 529 530

stop_web_server:
	# Stop web server
531 532
	-@[ -e e2e-tests/conf/apache2.pid ] && kill `cat e2e-tests/conf/apache2.pid` || true
	-@[ -e e2e-tests/conf/nginx.pid ]   && kill `cat e2e-tests/conf/nginx.pid` ||true
533
	-@[ -e e2e-tests/conf/llng-fastcgi.pid ] && kill `cat e2e-tests/conf/llng-fastcgi.pid` && rm -f e2e-tests/conf/llng-fastcgi.pid || true
534
	-@[ -e e2e-tests/conf/slapd.pid ] && kill `cat e2e-tests/conf/slapd.pid` || true
Xavier Guimard's avatar
Xavier Guimard committed
535
	-@[ -e e2e-tests/conf/server.pid ] && kill `cat e2e-tests/conf/server.pid` || true
536
	# Clean
537
	@rm -rf e2e-tests/conf
538

539 540
restart_web_server: start_web_server

Xavier Guimard's avatar
Xavier Guimard committed
541
plackup:
Xavier Guimard's avatar
Xavier Guimard committed
542
	@LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini \
Xavier Guimard's avatar
Xavier Guimard committed
543
	perl -I . -I`pwd`/lemonldap-ng-common/blib/lib/ \
544 545 546 547 548
			-I`pwd`/lemonldap-ng-handler/blib/lib/ \
			-I`pwd`/lemonldap-ng-portal/blib/lib/ \
			-I`pwd`/lemonldap-ng-manager/blib/lib/ \
		e2e-tests/conf/sbin/llng-fastcgi-server \
			-F >e2e-tests/conf/fastcgi.log 2>&1 &
Xavier Guimard's avatar
Xavier Guimard committed
549

Xavier Guimard's avatar
Xavier Guimard committed
550 551 552
install_test:
	@TESTWEBSERVERPORT=$(PORT) protractor e2e-tests/protractor-conf.js

Xavier Guimard's avatar
Xavier Guimard committed
553 554
# Install targets
# ---------------
Xavier Guimard's avatar
Xavier Guimard committed
555
install:	install_libs install_bin install_fastcgi_server install_site
556

557
# Perl libraires install
Xavier Guimard's avatar
Xavier Guimard committed
558

Xavier Guimard's avatar
Xavier Guimard committed
559
install_libs:	common_install_libs install_handler_libs install_portal_libs install_manager_libs
560 561

common_install_libs:		common
562
	@$(MAKE) -C ${SRCCOMMONDIR} install
563

564
install_handler_libs:	handler
565
	@$(MAKE) -C ${SRCHANDLERDIR} install
566

567
install_portal_libs:		portal
568
	@$(MAKE) -C ${SRCPORTALDIR} install
569

570
install_manager_libs:	manager
571
	@$(MAKE) -C ${SRCMANAGERDIR} install
572

Xavier Guimard's avatar
Xavier Guimard committed
573
install_bin:	install_conf_dir
574 575
	# Binary install
	@install -v -d $(RBINDIR)
576
	@cp -f\
577
		${SRCHANDLERDIR}/example/scripts/purgeLocalCache \
578
		${SRCPORTALDIR}/site/cron/purgeCentralCache \
Xavier Guimard's avatar
Xavier Guimard committed
579
		${SRCCOMMONDIR}/scripts/convertConfig \
Xavier Guimard's avatar
Xavier Guimard committed
580
		${SRCCOMMONDIR}/scripts/lmMigrateConfFiles2ini \
581
		${SRCCOMMONDIR}/scripts/rotateOidcKeys \
Xavier Guimard's avatar
Xavier Guimard committed
582
		${SRCMANAGERDIR}/scripts/lmConfigEditor \
Xavier Guimard's avatar
Xavier Guimard committed
583
		${SRCCOMMONDIR}/scripts/lemonldap-ng-cli \
584
			$(RBINDIR)
585
	@if [ ! "$(APACHEUSER)" ]; then \
586
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
587
	else \
588
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
589 590
	fi
	@if [ ! "$(APACHEGROUP)" ]; then \
591
		$(PERL) -i -pe 's#__APACHEGROUP__#nobody#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
592
	else \
593
		$(PERL) -i -pe 's#__APACHEGROUP__#$(APACHEGROUP)#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
594
	fi
595
	@chmod +x $(RBINDIR)/*
596

597
install_fastcgi_server:
598
	@install -v -d $(RSBINDIR) $(RINITDIR) $(RETCDEFAULTDIR) $(RFASTCGISOCKDIR)
599
	@cp -f fastcgi-server/sbin/llng-fastcgi-server $(RSBINDIR)
600
	@chmod +x $(RSBINDIR)/llng-fastcgi-server
601 602
	@cp -f fastcgi-server/rc/llng-fastcgi-server $(RINITDIR)
	@cp -f fastcgi-server/default/llng-fastcgi-server $(RETCDEFAULTDIR)
603
	@$(PERL) -pi -e 's#__SBINDIR__#$(SBINDIR)#;s#__DEFAULTDIR__#$(ETCDEFAULTDIR)#;s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#g;' \
604 605
		$(RETCDEFAULTDIR)/llng-fastcgi-server \
		$(RSBINDIR)/llng-fastcgi-server \
606
		$(RINITDIR)/llng-fastcgi-server
607 608 609 610 611 612
	@if [ ! "$(FASTCGIUSER)" ]; then \
		$(PERL) -pi -e 's#__USER__#nobody#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
	else \
		$(PERL) -pi -e 's#__USER__#$(FASTCGIUSER)#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
	fi
	@if [ ! "$(FASTCGIGROUP)" ]; then \
613
		$(PERL) -pi -e 's#__GROUP__#nobody#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
614
	else \
615
		$(PERL) -pi -e 's#__GROUP__#$(FASTCGIGROUP)#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
616
	fi
617
	@if [ "$(FASTCGIUSER)" != "" ]; then \
618 619 620 621 622 623 624 625
		chown $(FASTCGIUSER) $(RFASTCGISOCKDIR) || exit 1; \
		if [ "$(FASTCGIGROUP)" != "" ]; then \
			chgrp $(FASTCGIGROUP) $(RFASTCGISOCKDIR) || exit 1; \
		fi; \
		chmod 770 $(RFASTCGISOCKDIR); \
	else \
		chmod 777 $(RFASTCGISOCKDIR); \
	fi
626

Xavier Guimard's avatar
Xavier Guimard committed
627 628
# Site install

629
install_site:	install_manager_site install_portal_site install_handler_site install_test_site install_examples_site install_doc_site install_webserver_conf
630
	# Site install
631
	@install -v -d $(RCONFDIR)
Clément OUDOT's avatar
Clément OUDOT committed
632 633
	# Check if erase is wanted
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
634
		cp -f _example/etc/for_etc_hosts $(RCONFDIR); \
635
	fi
Xavier Guimard's avatar
Xavier Guimard committed
636
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)/for_etc_hosts
637
	# Fix a lost of rights on the main directory
638
	@chmod 755 $(RBINDIR) $(RDOCUMENTROOT) $(REXAMPLESDIR) $(RHANDLERDIR) $(RPORTALSTATICDIR) $(RMANAGERSITEDIR) $(RTOOLSDIR) $(RCONFDIR) $(RDATADIR)
639
	@echo
640
	@echo "LemonLDAP::NG v${VERSION} is installed with these parameters:"
641 642 643 644 645
	@echo "  - System configuration: ${CONFDIR}"
	@echo "  - DNS domain (for cookies and virtual hosts): ${DNSDOMAIN}"
	@echo
	@echo "To finish configuration:"
	@echo
646 647 648 649
	@echo "1 - Add this in your Apache $(APACHEVERSION) configuration file:"
	@echo "      include ${CONFDIR}/portal-apache$(APACHEVERSION).conf"
	@echo "      include ${CONFDIR}/handler-apache$(APACHEVERSION).conf"
	@echo "      include ${CONFDIR}/manager-apache$(APACHEVERSION).conf"
650
	@echo "      include ${CONFDIR}/test-apache$(APACHEVERSION).conf"
651
	@echo
652 653
	@echo "2 - Restart Apache:"
	@echo "      apache$(APACHEVERSION)ctl restart"
654
	@echo
655
	@echo "3 - Run 'make postconf' as root to update /etc/hosts if your DNS service does not known auth.$(DNSDOMAIN) and manager.$(DNSDOMAIN)"
656
	@echo
657 658 659 660 661 662
	@echo "4 - Try to connect to http://test1.${DNSDOMAIN}/ or http://test2.${DNSDOMAIN}/ with demonstration accounts:"
	@echo "    - rtyler/rtyler"
	@echo "    - msmith/msmith"
	@echo "    - dwho/dwho"
	@echo
	@echo "5 - Connect to Manager at http://manager.${DNSDOMAIN}/ to edit configuration"
663
	@echo
664
	@if [ ! "$(APACHEUSER)" ]; then \
665
		echo;echo "    Warning, since APACHEUSER was not set, $(APACHESESSIONFILEDIR), $(APACHEPSESSIONFILEDIR), $(CAPTCHADIR) and $(CONFDIR) have permissive permissions."; \
666 667 668
		echo "    Fix them by yourself to restrict their view to apache process only"; \
	fi
	@echo
669

670 671 672
install_webserver_conf:
	@install -m 755 -v -d $(RCONFDIR)
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
673 674 675 676 677
		cp -f _example/etc/portal-apache$(APACHEVERSION).conf $(RCONFDIR); \
		cp -f _example/etc/handler-apache$(APACHEVERSION).conf $(RCONFDIR); \
		cp -f _example/etc/manager-apache$(APACHEVERSION).conf $(RCONFDIR); \
		cp -f _example/etc/test-apache$(APACHEVERSION).conf $(RCONFDIR); \
		cp -f _example/etc/*nginx*.conf $(RCONFDIR); \
678 679 680
	fi
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g; \
			s#__PORTALDIR__#$(PORTALDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
681
			s#__PORTALSITEDIR__#$(PORTALSITEDIR)/#g; \
682
			s#__PORTALSTATICDIR__#$(PORTALSTATICDIR)/#g; \
683
			s#__MANAGERDIR__#$(MANAGERDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
684
			s#__MANAGERSITEDIR__#$(MANAGERSITEDIR)/#g; \
685 686
			s#__MANAGERSTATICDIR__#$(MANAGERSTATICDIR)/#g; \
			s#__TESTDIR__#$(TESTDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
687
			s#__PORT__#$(PORT)#g; \
688
			s#__CONFDIR__#$(CONFDIR)#g; \
Xavier Guimard's avatar
Xavier Guimard committed
689
			s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#g; \
690 691 692 693
			s#__VHOSTLISTEN__#$(VHOSTLISTEN)#g; \
			s#__DEFDOCDIR__#$(DEFDOCDIR)/#g; \
			s#__FRDOCDIR__#$(FRDOCDIR)/#g;' $(RCONFDIR)/*apache*.conf $(RCONFDIR)/*nginx*.conf

694 695
install_manager_site:	install_conf_dir
	# Manager install
696
	@install -v -d $(RMANAGERDIR) $(RMANAGERSTATICDIR) \
697
		$(RMANAGERTEMPLATESDIR)
698
	@cp -pR -f $(SRCMANAGERDIR)/site/htdocs/manager.* $(RMANAGERSITEDIR)
699
	@cp -pR $(SRCMANAGERDIR)/site/htdocs/static/* $(RMANAGERSTATICDIR)
700
	@for f in $(SRCMANAGERDIR)/site/templates/*.tpl; do \
701 702 703 704 705
		./scripts/transform-templates \
			usedebianlibs $(USEDEBIANLIBS) \
			useexternallibs $(USEEXTERNALLIBS) \
			jsminified $(JSCOMPRESS) \
			cssminified $(CSSCOMPRESS) <$$f \
706 707
			> $(RMANAGERTEMPLATESDIR)/`basename $$f`; \
	done
708
	@if test "$(USEEXTERNALLIBS)" = "yes"; then \
709
		rm -rvf $(MANAGEREXTERNALLIBS); \
710
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
711 712
		rm -rvf $(MANAGERLIBSTOREMOVEFORDEBIAN); \
	fi
713
	# Clean svn files
714
	@rm -rf $$(find ${RMANAGERSTATICDIR} \
715
		$(RMANAGERTEMPLATESDIR) $(RCONFDIR) -type d -name .svn)
716 717
	@$(PERL) -i -pe 's#__MANAGERSTATICDIR__#$(MANAGERRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
	@$(PERL) -i -pe 's#__MANAGERTEMPLATESDIR__#$(MANAGERTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
718 719 720

install_portal_site:	install_conf_dir
	# Portal install
721
	@install -v -d $(RPORTALDIR) $(RPORTALSTATICDIR) \
Xavier Guimard's avatar
Xavier Guimard committed
722
		$(RPORTALTEMPLATESDIR) \
723
		$(RCRONDIR) $(RCONFDIR)
724
	@cp -pR -f $(SRCPORTALDIR)/site/htdocs/index.* $(RPORTALSITEDIR)
725
	@cp -pR -f $(SRCPORTALDIR)/site/htdocs/static/* $(RPORTALSTATICDIR)
726
	@cd $(SRCPORTALDIR)/site/templates; for f in `find * -type f -name '*.tpl'`; do \
Xavier Guimard's avatar
Xavier Guimard committed
727 728
		echo "$$f => $(RPORTALTEMPLATESDIR)/$$f"; \
		mkdir -p $(RPORTALTEMPLATESDIR)/`dirname $$f`; \
Xavier Guimard's avatar
Xavier Guimard committed
729
		../../../scripts/transform-templates \
730 731 732 733
			usedebianlibs $(USEDEBIANLIBS) \
			useexternallibs $(USEEXTERNALLIBS) \
			jsminified $(JSCOMPRESS) \
			cssminified $(CSSCOMPRESS) <$$f \
Xavier Guimard's avatar
Xavier Guimard committed
734 735
			>$(RPORTALTEMPLATESDIR)/$$f; \
	done; cd -
736 737
	@cd $(SRCPORTALDIR)/site/templates; for f in `find * -type f ! -name '*.tpl'`; do \
		mkdir -p $(RPORTALTEMPLATESDIR)/`dirname $$f`; \
Xavier Guimard's avatar
Xavier Guimard committed
738
		install -m 644 -v $$f $(RPORTALTEMPLATESDIR)/$$f; \
739 740
	done; cd -
	@cd $(SRCPORTALDIR)/site/templates; for l in `find * -type l`; do \
Xavier Guimard's avatar
Xavier Guimard committed
741
		echo link to do $$l `readlink $$l`; \
Xavier Guimard's avatar
Xavier Guimard committed
742 743 744 745
		target=`readlink $$l`; \
		cd $(RPORTALTEMPLATESDIR); \
		ln -s $$target $$l; \
		cd -; \
746
	done
Xavier Guimard's avatar
Xavier Guimard committed
747
	@if test "$(USEEXTERNALLIBS)" = "yes"; then \
748
		rm -rvf $(PORTALEXTERNALLIBS); \
749
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
750 751
		rm -rvf $(PORTALLIBSTOREMOVEFORDEBIAN); \
	fi
752
	# Cron files
753
	@cp -f $(SRCPORTALDIR)/site/cron/purgeCentralCache.cron.d $(RCRONDIR)/lemonldap-ng-portal
754
	@if [ ! "$(APACHEUSER)" ]; then \
755
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RCRONDIR)/lemonldap-ng-portal; \
756
	else \
757
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RCRONDIR)/lemonldap-ng-portal; \
758
	fi
759
	@$(PERL) -i -pe 's#__BINDIR__#$(BINDIR)#g;' $(RCRONDIR)/lemonldap-ng-portal
760
	# Clean SVN files
761
	@rm -rf $$(find ${RPORTALDIR} $(RPORTALSKINSDIR) $(RCRONDIR) $(RCONFDIR) -type d -name .svn)
Xavier Guimard's avatar
Xavier Guimard committed
762 763
	@$(PERL) -i -pe 's#__PORTALSTATICDIR__#$(PORTALRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
	@$(PERL) -i -pe 's#__PORTALTEMPLATESDIR__#$(PORTALTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
764 765

install_handler_site:	install_conf_dir
766
	# Handler install
767
	@install -v -d ${RHANDLERDIR}
768
	@cp -f $(SRCHANDLERDIR)/example/scripts/purgeLocalCache.cron.d $(RCRONDIR)/lemonldap-ng-handler
769
	@if [ ! "$(APACHEUSER)" ]; then \
770
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RCRONDIR)/lemonldap-ng-handler; \
771 772 773 774
	else \
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RCRONDIR)/lemonldap-ng-handler; \
	fi
	@$(PERL) -i -pe 's#__BINDIR__#$(BINDIR)#g;' $(RCRONDIR)/lemonldap-ng-handler
775
	@rm -rf $$(find $(RHANDLERDIR) -type d -name .svn)
776 777

install_test_site:
778
	# Test site install
779
	@install -v -d $(RTESTDIR)
780
	@cp -pR -f _example/test/* $(RTESTDIR)
781
	@rm -rf $$(find $(RTESTDIR) -type d -name .svn)
Xavier Guimard's avatar
Xavier Guimard committed
782
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RTESTDIR)/index.pl
783
	@rm -rf $$(find $(RTESTDIR) -type d -name .svn)
784 785

install_examples_site:
786
	# Examples install
787
	@install -v -d $(REXAMPLESDIR)
788
	@for i in handler; do \
789
		cp -a -f lemonldap-ng-$$i/example $(REXAMPLESDIR)/$$i; \
790
	done
791
	@for i in portal manager; do \
792
		cp -a -f lemonldap-ng-$$i/eg $(REXAMPLESDIR)/$$i; \
793
	done
794
	@cp -a -f fastcgi-server/psgi/llngapp.psgi $(REXAMPLESDIR)/$$i
795
	@rm -rf $(REXAMPLESDIR)/portal/skins \
Xavier Guimard's avatar
Xavier Guimard committed
796
		$(REXAMPLESDIR)/manager/skins \
797
	@rm -rf $$(find $(REXAMPLESDIR) -type d -name .svn)
798

799
install_doc_site:
800
	# Offline documentation install
801
	@rm -rf $(RDEFDOCDIR)
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
	# Install doc directories
	@install -v -d -m 755 $(RDEFDOCDIR)
	@cd doc && find * -type d |(cd $(RDEFDOCDIR); xargs install -v -d -m 755) && cd -
	# Install HTML files
	@cd doc && for f in `find * -type f -name '*.html'`; do \
		echo "Installing $$f"; \
		../scripts/transform-templates \
			usedebianlibs $(USEDEBIANLIBS) \
			useexternallibs $(USEEXTERNALLIBS) \
			jsminified $(JSCOMPRESS) \
			cssminified $(CSSCOMPRESS) <$$f \
		> $(RDEFDOCDIR)/$$f; \
	done && cd -
	# Install other files
	@cd doc && for f in `find * -type f ! -name '*.html'`; do \
		install -v -m 644 $$f $(RDEFDOCDIR)/$$f; \
	done && cd -
	# Install symlinks
	@cd doc && tar cf - `find * -type l` | tar xvf - -C $(RDEFDOCDIR) && cd -
Xavier Guimard's avatar
Xavier Guimard committed
821
	# Remove js
Xavier Guimard's avatar
Xavier Guimard committed
822
	@cd $(RDEFDOCDIR) && if test "$(USEEXTERNALLIBS)" = "yes"; then \
Xavier Guimard's avatar
Xavier Guimard committed
823 824 825
		rm -rvf $(DOCEXTERNALLIBS); \
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
		rm -rvf $(DOCLIBSTOREMOVEFORDEBIAN); \
Xavier Guimard's avatar
Xavier Guimard committed
826
	fi && cd -
827

828
install_conf_dir:	install_sessions_dir install_notif_dir install_captcha_dir
829
	# Configuration files install
830
	@install -v -d $(RCONFDIR) $(RFILECONFIGDIR) $(RTOOLSDIR)
Clément OUDOT's avatar
Clément OUDOT committed
831
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
832
		cp -f $(SRCCOMMONDIR)/$(CONFFILENAME) $(RCONFDIR); \
Xavier Guimard's avatar
Xavier Guimard committed
833
		$(PERL) -i -pe 's#^dirName\s*=\s*.*#dirName = $(FILECONFIGDIR)#g' $(RCONFDIR)/$(CONFFILENAME); \
Clément OUDOT's avatar
Clément OUDOT committed
834
	fi
835
	@cp _example/conf/lmConf-1.json $(RFILECONFIGDIR)
Xavier Guimard's avatar
Xavier Guimard committed
836
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g;\
837
		s#__SESSIONDIR__#$(APACHESESSIONFILEDIR)#g;\
838
		s#__PSESSIONDIR__#$(APACHEPSESSIONFILEDIR)#g;\
839
		s#__NOTIFICATIONDIR__#$(APACHEFILENOTIFDIR)#g;' $(RFILECONFIGDIR)/lmConf-1.json
840 841 842 843 844 845 846 847 848
	@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
849 850
	@cp $(SRCCOMMONDIR)/tools/lmConfig.* $(SRCCOMMONDIR)/tools/apache-session-mysql.sql $(RTOOLSDIR)
	@cp $(SRCCOMMONDIR)/tools/sso.schema $(RTOOLSDIR)
851
	$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)/$(CONFFILENAME)
852
	@rm -rf $$(find $(RCONFDIR) $(RFILECONFIGDIR) $(RTOOLSDIR) -type d -name .svn)
853 854

install_sessions_dir:
855
	@install -m 777 -v -d $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR)
856 857
	# Fix Apache::Session directories permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
858
		chown $(APACHEUSER) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR) || exit 1; \
859
		if [ "$(APACHEGROUP)" != "" ]; then \
860
			chgrp $(APACHEGROUP) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR) || exit 1; \
861
		fi; \
862
		chmod 770 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR); \
863
	else \
864
		chmod 777 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR); \
865 866
	fi

867 868 869 870 871 872 873 874 875 876 877 878 879
install_notif_dir:
	@install -m 777 -v -d $(RFILENOTIFDIR)
	# Fix notifications directory permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
		chown $(APACHEUSER) $(RFILENOTIFDIR) || exit 1; \
		if [ "$(APACHEGROUP)" != "" ]; then \
			chgrp $(APACHEGROUP) $(RFILENOTIFDIR) || exit 1; \
		fi; \
		chmod 770 $(RFILENOTIFDIR); \
	else \
		chmod 777 $(RFILENOTIFDIR); \
	fi

880
install_captcha_dir:
881
	@install -m 777 -v -d $(RCAPTCHADIR)
882 883
	# Fix captcha directory permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
884
		chown $(APACHEUSER) $(RCAPTCHADIR) || exit 1; \
885
		if [ "$(APACHEGROUP)" != "" ]; then \
886
			chgrp $(APACHEGROUP) $(RCAPTCHADIR) || exit 1; \
887
		fi; \
888
		chmod 770 $(RCAPTCHADIR); \
889
	else \
890
		chmod 777 $(RCAPTCHADIR); \
891 892
	fi

893
postconf_hosts:
Clément OUDOT's avatar
Clément OUDOT committed
894
	@cat ${CONFDIR}/for_etc_hosts >> /etc/hosts
895 896
	@echo "/etc/hosts was updated"

897
postconf: postconf_hosts
898 899
	@echo "Post configuration done"

Xavier Guimard's avatar
Xavier Guimard committed
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
debian-install:
	@echo "You have now to choose between:"
	@echo " - make debian-install-for-apache"
	@echo " - make ubuntu-install-for-apache"
	@echo " - make debian-install-for-nginx"
	@echo " - make ubuntu-install-for-nginx"
	@echo
	@echo "All packages will be built in /tmp/ but only those needed by the"
	@echo "server you will choose will be installed"
	@exit 1

debian-install-for-apache: debian-packages
	perl -i -ne 'next if/fastcgi.*deb$$/;s/lemonldap-ng-fastcgi-server//;print' /tmp/lemonldap-ng_$(VERSION)*.changes
	cd /tmp/lemonldap-ng-$(VERSION) && \
	$(SU) debi

debian-install-for-nginx: debian-packages
	cd /tmp/lemonldap-ng-$(VERSION) && \
	$(SU) debi

ubuntu-install: debian-install

ubuntu-install-for-apache:
	$(MAKE) debian-install-for-apache SU=sudo

ubuntu-install-for-nginx:
	$(MAKE) debian-install-for-nginx SU=sudo

# Cleaning targets
# ----------------

distclean:	clean

clean:		common_clean handler_clean portal_clean manager_clean omegat-clean stop_web_server
	@rm -f $$(find */ -name '*bak' -delete)
	@rm -rf doc/devel
	@rm -vf *gz *zip
	@rm -rf lemonldap-ng-$(VERSION)
	@echo "Cleaned"

common_clean:
941
	-@if test -e ${SRCCOMMONDIR}/Makefile;then $(MAKE) -C ${SRCCOMMONDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
942 943 944
	@rm -vf common*

handler_clean:
945
	-@if test -e ${SRCHANDLERDIR}/Makefile;then $(MAKE) -C ${SRCHANDLERDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
946 947 948
	@rm -vf handler*

portal_clean:
949
	-@if test -e ${SRCPORTALDIR}/Makefile;then $(MAKE) -C ${SRCPORTALDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
950 951 952
	@rm -vf portal*

manager_clean:
953
	-@if test -e ${SRCMANAGERDIR}/Makefile;then $(MAKE) -C ${SRCMANAGERDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
954 955 956 957 958
	@rm -vf manager*

# Perl libraries uninstall targets
# --------------------------------

959 960
uninstall:	configure handler_uninstall portal_uninstall manager_uninstall

961 962 963 964
common_uninstall:	common
	@$(MAKE) -C ${SRCCOMMONDIR} uninstall
	@rm -vf common_uninstall

965
handler_uninstall:	handler
966
	@$(MAKE) -C ${SRCHANDLERDIR} uninstall
967
	@rm -vf handler_uninstall
968 969

portal_uninstall:		portal
970
	@$(MAKE) -C ${SRCPORTALDIR} uninstall
971
	@rm -vf portal_uninstall
972 973

manager_uninstall:	manager
974
	@$(MAKE) -C ${SRCMANAGERDIR} uninstall
975
	@rm -vf manager_uninstall
976

Xavier Guimard's avatar
Xavier Guimard committed
977 978 979
# Packaging target
# ----------------

980
dist:	clean
981 982 983 984 985 986 987 988
	@mkdir -p lemonldap-ng-$(VERSION)
	@cp -pRH $$(find * -maxdepth 0|grep -v -e "\(lemonldap-ng-$(VERSION)\|debian\|rpm\)") lemonldap-ng-$(VERSION)
	@rm -rf $$(find lemonldap-ng-$(VERSION) -name .svn -print)
	@find $$dir -name '*.bak' -delete
	@rm -rf lemonldap-ng-$(VERSION)/lemonldap-ng-$(VERSION)
	@$(COMPRESS) lemonldap-ng-$(VERSION).$(COMPRESSSUFFIX) lemonldap-ng-$(VERSION)
	@rm -rf lemonldap-ng-$(VERSION)

989
rpm-dist:	clean
990
	@mkdir -p lemonldap-ng-$(VERSION)
991
	@cp -pRH $$(find * -maxdepth 0|grep -v -e