Makefile 41.8 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'`
30
export PERL5LIB=$(shell echo `pwd`/${SRCCOMMONDIR}/blib/lib:`pwd`/${SRCHANDLERDIR}/blib/lib:`pwd`/${SRCMANAGERDIR}/blib/lib/:`pwd`/${SRCPORTALDIR}/blib/lib/)
Xavier Guimard's avatar
Xavier Guimard committed
31 32 33
SU=su -c
COMPRESS=tar czf
UNCOMPRESS=tar xzf
Clément OUDOT's avatar
Clément OUDOT committed
34
LISTCOMPRESSED=tar tzf
Xavier Guimard's avatar
Xavier Guimard committed
35
COMPRESSSUFFIX=tar.gz
Xavier Guimard's avatar
Xavier Guimard committed
36
NGINX=/usr/sbin/nginx
37 38

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

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

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

59
MANAGERDIR=$(DOCUMENTROOT)/manager
60 61
MANAGERSITEDIR=$(MANAGERDIR)/htdocs
MANAGERSTATICDIR=$(MANAGERSITEDIR)/static
62
MANAGERRELATIVESTATICDIR=/static
63
MANAGERTEMPLATESDIR=$(MANAGERSITEDIR)/templates
64 65
DOCDIR=$(DOCUMENTROOT)
DEFDOCDIR=$(DOCUMENTROOT)/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

Xavier Guimard's avatar
Xavier Guimard committed
105 106 107 108 109 110
# uWSGI
UWSGIYAMLDIR=$(LMPREFIX)/uwsgi
LLNGAPPDIR=$(LMPREFIX)/llng-server
UWSGIUSER=$(APACHEUSER)
UWSGIGROUP=$(APACHEGROUP)

111
# Apache version
112
APACHEVERSION=2.X
113

114
# DNS Domain for cookie and virtual hosts
115 116
DNSDOMAIN=example.com

117
# Virtual Host Listen IP and Port (*, *:80, ...)
Xavier Guimard's avatar
Xavier Guimard committed
118 119
PORT=80
VHOSTLISTEN="*:$(PORT)"
120
TESTWEBSERVER=apache
Xavier Guimard's avatar
Xavier Guimard committed
121
TESTWEBSERVERPORT=19876
122
TESTUSESSL=0
123

124
# LDAP backend test
125 126 127
LLNGTESTLDAP_SLAPD_BIN=/usr/sbin/slapd
LLNGTESTLDAP_SLAPADD_BIN=/usr/sbin/slapdadd
LLNGTESTLDAP_SCHEMA_DIR=/etc/slapd/schema
128

129
# Other
130 131 132 133
SRCCOMMONDIR=lemonldap-ng-common
SRCHANDLERDIR=lemonldap-ng-handler
SRCPORTALDIR=lemonldap-ng-portal
SRCMANAGERDIR=lemonldap-ng-manager
Xavier Guimard's avatar
Xavier Guimard committed
134 135 136 137 138 139 140 141
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)
Xavier Guimard's avatar
Xavier Guimard committed
142 143
RUWSGIYAMLDIR=$(DESTDIR)/$(UWSGIYAMLDIR)
RLLNGAPPDIR=$(DESTDIR)/$(LLNGAPPDIR)
Xavier Guimard's avatar
Xavier Guimard committed
144 145 146 147
RINITDIR=$(DESTDIR)/$(INITDIR)
RETCDEFAULTDIR=$(DESTDIR)/$(ETCDEFAULTDIR)
RDATADIR=$(DESTDIR)/$(DATADIR)
RPORTALDIR=$(DESTDIR)/$(PORTALDIR)
148 149 150
RPORTALSITEDIR=$(DESTDIR)/$(PORTALSITEDIR)
RPORTALSTATICDIR=$(DESTDIR)/$(PORTALSTATICDIR)
RPORTALTEMPLATESDIR=$(DESTDIR)/$(PORTALTEMPLATESDIR)
Xavier Guimard's avatar
Xavier Guimard committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
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)
171 172

VERSION=`head -n1 changelog |sed -e 's/lemonldap-ng (//' -e 's/).*$$//'`
173
PORTALSKINS=`ls $(SRCPORTALDIR)/site/templates/`
174
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.*'
175 176
DIFFPREFIX=

177

178 179
MANAGERLIBSTOREMOVEFORDEBIAN=$(RMANAGERSTATICDIR)/bwr/jquery/ \
			$(RMANAGERSTATICDIR)/bwr/angular/ \
180
			$(RMANAGERSTATICDIR)/bwr/angular-animate/ \
181 182 183
			$(RMANAGERSTATICDIR)/bwr/angular-cookie/ \
			$(RMANAGERSTATICDIR)/bwr/bootstrap/ \
			$(RMANAGERSTATICDIR)/bwr/es5-shim/
184
PORTALLIBSTOREMOVEFORDEBIAN=$(RPORTALSTATICDIR)/bwr/bootstrap/ \
185
			$(RPORTALSTATICDIR)/bwr/font-awesome \
186 187 188
			$(RPORTALSTATICDIR)/bwr/jquery-ui \
			$(RPORTALSTATICDIR)/bwr/jquery.cookie \
			$(RPORTALSTATICDIR)/bwr/jquery
Xavier Guimard's avatar
Xavier Guimard committed
189 190 191
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
192
DOCEXTERNALLIBS=$(DOCLIBSTOREMOVEFORDEBIAN)
193
MANAGEREXTERNALLIBS=$(RMANAGERSTATICDIR)/bwr/
194
PORTALEXTERNALLIBS=$(PORTALLIBSTOREMOVEFORDEBIAN)
195

Xavier Guimard's avatar
Xavier Guimard committed
196
# GENERATED SRC FILES
197
MANAGERJSONSRC= scripts/jsongenerator.pl \
Xavier Guimard's avatar
Xavier Guimard committed
198
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build.pm \
199
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/Attributes.pm \
200
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/Tree.pm \
201
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Build/CTrees.pm \
202
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Conf/Zero.pm
203 204
MANAGERJSONDST=$(SRCMANAGERDIR)/site/htdocs/static/struct.json \
		$(SRCMANAGERDIR)/site/htdocs/static/js/conftree.js \
Xavier Guimard's avatar
Xavier Guimard committed
205
		$(SRCMANAGERDIR)/lib/Lemonldap/NG/Manager/Attributes.pm \
206
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/ReConstants.pm \
207
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/DefaultValues.pm \
208
		$(SRCCOMMONDIR)/lib/Lemonldap/NG/Common/Conf/Constants.pm \
209
		_example/conf/lmConf-1.json
210 211

# Javascript and CSS to minify
212 213
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
214
CSSSRCFILES:=$(shell find $(SRCMANAGERDIR)/site/htdocs/static  $(SRCPORTALDIR)/site/htdocs/static -type f -name '*.css' ! -name '*.min.css')
215

216
# Coffee files
217 218 219
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)
220
MANAGERCOFFEEDSTFILES:=$(subst coffee/,htdocs/static/js/,$(MANAGERCOFFEESRCFILES:.coffee=.js))
221 222
PORTALCOFFEEDSTFILES:=$(subst coffee/,htdocs/static/common/js/,$(PORTALCOFFEESRCFILES:.coffee=.js))
COFFEEDSTFILES:=$(MANAGERCOFFEEDSTFILES) $(PORTALCOFFEEDSTFILES)
223

224 225 226
# Minified files
JSDSTFILES=$(JSSRCFILES:.js=.min.js)
CSSDSTFILES=$(CSSSRCFILES:.css=.min.css)
Xavier Guimard's avatar
Xavier Guimard committed
227

Xavier Guimard's avatar
Xavier Guimard committed
228 229 230 231 232
# -------
# TARGETS
# -------

# Targets section contains the following subsections:
233
#  - 'all' that must be defined at first
Xavier Guimard's avatar
Xavier Guimard committed
234 235 236 237 238 239 240 241 242 243
#  - configure targets
#  - make targets
#  - test targets
#  - end-to-end tests
#  - install targets
#  - cleaning targets
#  - Perl libraries uninstall targets
#  - packaging targets
#  - developper corner

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
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))"
Xavier Guimard's avatar
Xavier Guimard committed
267
	@echo " * FastCGI (or uWSGI) server install (required for Nginx)"
268
	@echo "   - install_fastcgi_server ($(SBINDIR))"
Xavier Guimard's avatar
Xavier Guimard committed
269
	@echo "   - install_uwsgi_server   ($(UWSGIYAMLDIR))"
270 271 272 273 274 275 276 277 278 279
	@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

Xavier Guimard's avatar
Xavier Guimard committed
280 281 282
# Configure targets
# -----------------

283
configure:	common_conf handler_conf portal_conf manager_conf
Xavier Guimard's avatar
Xavier Guimard committed
284

285 286 287
js: $(COFFEEDSTFILES)

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

289
$(SRCPORTALDIR)/site/htdocs/static/common/js/%.js: $(SRCPORTALDIR)/site/coffee/%.coffee
290 291
	@if which coffee >/dev/null; then \
		echo "Compiling $(SRCPORTALDIR)/site/coffee/$*.coffee"; \
292
		coffee -c -o $(SRCPORTALDIR)/site/htdocs/static/common/js/ $(SRCPORTALDIR)/site/coffee/$*.coffee; \
293 294
	fi

Xavier Guimard's avatar
Xavier Guimard committed
295
$(SRCMANAGERDIR)/site/htdocs/static/js/%.js: $(SRCMANAGERDIR)/site/coffee/%.coffee
296 297
	@if which coffee >/dev/null; then \
		echo "Compiling $(SRCMANAGERDIR)/site/coffee/$*.coffee"; \
298
		coffee -c -o $(SRCMANAGERDIR)/site/htdocs/static/js/ $(SRCMANAGERDIR)/site/coffee/$*.coffee; \
299 300
	fi

Xavier Guimard's avatar
Xavier Guimard committed
301 302 303 304 305 306
%.min.css: %.css
	@echo "Compressing $*.css"
	@yui-compressor $*.css > $*.min.css

%.min.js: %.js
	@echo "Compressing $*.js"
307
	@uglifyjs --comments='/Copyr/i' $*.js > $*.min.js
Xavier Guimard's avatar
Xavier Guimard committed
308 309

fastcgi-server/man/llng-fastcgi-server.1p: fastcgi-server/sbin/llng-fastcgi-server
Xavier Guimard's avatar
Xavier Guimard committed
310
	@echo Update FastCGI server man page
Xavier Guimard's avatar
Xavier Guimard committed
311 312 313 314 315
	@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
316
	@if which yui-compressor >/dev/null; then $(MAKE) minify; fi
Xavier Guimard's avatar
Xavier Guimard committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

$(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
# ------------

344
common:		common_conf
345
	@$(MAKE) -C ${SRCCOMMONDIR}
346

Xavier Guimard's avatar
Xavier Guimard committed
347
handler:	handler_conf common
348
	@$(MAKE) -C ${SRCHANDLERDIR}
349

350
portal:		portal_conf handler
351
	@$(MAKE) -C ${SRCPORTALDIR}
352

Xavier Guimard's avatar
Xavier Guimard committed
353
manager:	manager_conf handler
354
	$(MAKE) -C ${SRCMANAGERDIR}
355

Xavier Guimard's avatar
Xavier Guimard committed
356 357
# Test targets
# ------------
358
test:		all common_test handler_test portal_test manager_test
359 360 361 362

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

Xavier Guimard's avatar
Xavier Guimard committed
363
handler_test:	handler
364
	@$(MAKE) -C ${SRCHANDLERDIR} test
365

Xavier Guimard's avatar
Xavier Guimard committed
366
portal_test:	portal
367
	@$(MAKE) -C ${SRCPORTALDIR} test
368

Xavier Guimard's avatar
Xavier Guimard committed
369
manager_test:	manager
370
	@$(MAKE) -C ${SRCMANAGERDIR} test
371

372 373 374 375 376
autopkgtest:    all
	./debian/tests/runner build-deps
	./debian/tests/runner runtime-deps
	#/usr/share/pkg-perl-autopkgtest/runner runtime-deps-and-recommends

377
# End-to-end tests
Xavier Guimard's avatar
Xavier Guimard committed
378 379
# ----------------

380 381
e2e_test:	all prepare_test_server start_web_server launch_protractor stop_web_server

382 383 384 385 386 387
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
388

389
prepare_test_server:
390 391
	-@mkdir -p e2e-tests/conf/sessions/lock e2e-tests/conf/persistents/lock
	-@mkdir e2e-tests/conf/manager e2e-tests/conf/portal
392 393
	$(MAKE) install_webserver_conf install_test_site install_fastcgi_server \
		CONFDIR=`pwd`/e2e-tests/conf \
394 395
		RCONFDIR=e2e-tests/conf \
		ERASECONFIG=1 \
Xavier Guimard's avatar
Xavier Guimard committed
396 397
		VHOSTLISTEN='*:$(TESTWEBSERVERPORT)' \
		PORT=$(TESTWEBSERVERPORT) \
Xavier Guimard's avatar
Xavier Guimard committed
398
		FASTCGISOCKDIR=`pwd`/e2e-tests/conf \
Xavier Guimard's avatar
Xavier Guimard committed
399 400 401 402
		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
403
		TESTDIR=`pwd`/e2e-tests/conf/site \
404
		DEFDOCDIR=`pwd`/doc \
405 406 407
		SBINDIR=`pwd`/e2e-tests/conf/sbin \
		INITDIR=`pwd`/e2e-tests/conf/init \
		ETCDEFAULTDIR=`pwd`/e2e-tests/conf/def
408 409 410
	#@cp -f e2e-tests/index.* e2e-tests/conf/
	@cp -f $(SRCMANAGERDIR)/site/htdocs/manager* e2e-tests/conf/manager
	@cp -f $(SRCPORTALDIR)/site/htdocs/index* e2e-tests/conf/portal
411
	@cp e2e-tests/saml-sp.xml e2e-tests/conf/site/saml-sp.xml
412
	@cp e2e-tests/rules.json e2e-tests/conf/site/test.json
413 414 415
	@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
416
	@cp e2e-tests/lmConf-1.json e2e-tests/lemonldap-ng*.ini e2e-tests/env.conf e2e-tests/test-nginx.conf e2e-tests/conf/
417
	@cp e2e-tests/form.html e2e-tests/conf/site
Xavier Guimard's avatar
Xavier Guimard committed
418
	@perl -i -pe 'BEGIN{$$p=`pwd`;chomp $$p}s#__pwd__#$$p#;s#__port__#$(TESTWEBSERVERPORT)#;s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#;' \
Xavier Guimard's avatar
Xavier Guimard committed
419
		e2e-tests/conf/lemonldap-ng*.ini \
420
		e2e-tests/conf/lmConf-1.json \
421 422
		e2e-tests/conf/env.conf \
		e2e-tests/conf/test-nginx.conf
423
	@perl -i -pe 's/#CustomLog.*$$/CustomLog conf\/apache2.log llng/' e2e-tests/conf/portal-apache2.X.conf e2e-tests/conf/manager-apache2.X.conf
424 425 426 427
	@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
428

Xavier Guimard's avatar
Xavier Guimard committed
429 430 431
e2e-tests/conf/apache2.pid: start_web_server

start_web_server:	all prepare_test_server
Xavier Guimard's avatar
Xavier Guimard committed
432
	# Clean old server if launched
Xavier Guimard's avatar
Xavier Guimard committed
433
	@if test "$(TESTBACKEND)" = "DBI"; then \
Xavier Guimard's avatar
Xavier Guimard committed
434 435
		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; \
436
		perl --current=e2e-tests/conf/lemonldap-ng.ini \
Xavier Guimard's avatar
Xavier Guimard committed
437 438
			--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
439
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
440
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
Xavier Guimard's avatar
Xavier Guimard committed
441 442
				set globalStorage Apache::Session::SQLite3; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
443
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
Xavier Guimard's avatar
Xavier Guimard committed
444
				addKey globalStorageOptions DataSource 'dbi:SQLite:dbname='`pwd`'/e2e-tests/conf/sessions.db'; \
Xavier Guimard's avatar
Xavier Guimard committed
445
	fi
Xavier Guimard's avatar
Xavier Guimard committed
446
	@# 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
447
	@if test "$(TESTBACKEND)" = "LDAP"; then \
Xavier Guimard's avatar
Xavier Guimard committed
448 449 450 451 452 453 454
		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; \
455
		${LLNGTESTLDAP_SLAPADD_BIN} -F e2e-tests/conf/slapd.d -n 1 -l lemonldap-ng-portal/t/testslapd/users.ldif; \
Xavier Guimard's avatar
Xavier Guimard committed
456 457
		${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; \
458
		perl ./lemonldap-ng-common/scripts/convertConfig \
459 460 461
			--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; \
462
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
463
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
464 465
				set globalStorage Apache::Session::LDAP; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
466
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
467 468
				addKey globalStorageOptions ldapServer 'ldap://localhost:20389'; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
469
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
470 471
				addKey globalStorageOptions ldapConfBase 'ou=configurations,dc=example,dc=com'; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
472
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
473 474
				addKey globalStorageOptions ldapBindDN 'cn=admin,dc=example,dc=com'; \
		LLNG_DEFAULTCONFFILE=e2e-tests/conf/lemonldap-ng.ini \
475
			perl lemonldap-ng-common/scripts/lemonldap-ng-cli --yes 1 \
476
				addKey globalStorageOptions ldapBindPassword admin; \
Xavier Guimard's avatar
Xavier Guimard committed
477
	fi
478 479
	-@[ -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
480
	-@[ -e e2e-tests/conf/llng-fastcgi.pid ] && kill `cat e2e-tests/conf/llng-fastcgi.pid` && rm -f e2e-tests/conf/llng-fastcgi.pid || true
481
	# Start web server (designed for Debian, path may be broken else)
Xavier Guimard's avatar
Xavier Guimard committed
482
	@if test "$(TESTWEBSERVER)" = "apache"; then \
483 484 485 486 487 488
		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; \
489
	elif test "$(TESTWEBSERVER)" = "nginx"; then \
Xavier Guimard's avatar
Xavier Guimard committed
490 491 492 493 494
		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; \
495 496
		echo "Launching nginx"; \
		$(NGINX) -p `pwd`/e2e-tests \
497
			-g 'error_log '`pwd`'/e2e-tests/conf/nginx.log;' \
498 499
			-c `pwd`/e2e-tests/nginx.conf \
			2>&1 | grep -v 'Permission denied' || true; \
500
		echo "Launching plackup"; \
501
		$(MAKE) plackup; \
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
	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; \
521 522 523 524
	else \
		echo "!!!!! Unknown test server: $(TESTWEBSERVER) !!!!!" >&2; \
		exit 1; \
	fi
525

526
reload_web_server:
527
	@if [ -e e2e-tests/conf/apache2.pid ]; then \
Xavier Guimard's avatar
Xavier Guimard committed
528 529
		LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini \
		/usr/sbin/apache2 -d `pwd`/e2e-tests -f apache2.conf -k graceful; \
530
	elif [ -e e2e-tests/conf/nginx.pid ]; then \
Xavier Guimard's avatar
Xavier Guimard committed
531 532 533 534 535
		$(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; \
536
		kill `cat e2e-tests/conf/llng-fastcgi.pid` || true; \
537
		$(MAKE) plackup; \
538 539 540 541 542
	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; \
543 544 545 546
	else \
		$(MAKE) start_web_server; \
	fi

547
launch_protractor:
548
	# Start e2e tests
Xavier Guimard's avatar
Xavier Guimard committed
549
	# NB: you must have protractor installed (using npm install -g protractor)
Xavier Guimard's avatar
Xavier Guimard committed
550
	# and have run update-webdriver at least once and have a node.js > 4.0
Xavier Guimard's avatar
Xavier Guimard committed
551
	@TESTWEBSERVERPORT=$(TESTWEBSERVERPORT) protractor e2e-tests/protractor-conf.js
552 553 554

stop_web_server:
	# Stop web server
555 556
	-@[ -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
557
	-@[ -e e2e-tests/conf/llng-fastcgi.pid ] && kill `cat e2e-tests/conf/llng-fastcgi.pid` && rm -f e2e-tests/conf/llng-fastcgi.pid || true
558
	-@[ -e e2e-tests/conf/slapd.pid ] && kill `cat e2e-tests/conf/slapd.pid` || true
559
	-@[ -e e2e-tests/conf/server.pid ] && kill `cat e2e-tests/conf/server.pid` || true
560
	# Clean
561
	@rm -rf e2e-tests/conf
562

563 564
restart_web_server: start_web_server

565
plackup:
Xavier Guimard's avatar
Xavier Guimard committed
566
	@LLNG_DEFAULTCONFFILE=`pwd`/e2e-tests/conf/lemonldap-ng.ini \
567 568
	perl -I . e2e-tests/conf/sbin/llng-fastcgi-server \
		-F >e2e-tests/conf/fastcgi.log 2>&1 &
569

Xavier Guimard's avatar
Xavier Guimard committed
570 571 572
install_test:
	@TESTWEBSERVERPORT=$(PORT) protractor e2e-tests/protractor-conf.js

Xavier Guimard's avatar
Xavier Guimard committed
573 574
# Install targets
# ---------------
Xavier Guimard's avatar
Xavier Guimard committed
575
install:	install_libs install_bin install_fastcgi_server install_uwsgi_server install_site
576

577
# Perl libraires install
Xavier Guimard's avatar
Xavier Guimard committed
578

Xavier Guimard's avatar
Xavier Guimard committed
579
install_libs:	common_install_libs install_handler_libs install_portal_libs install_manager_libs
580 581

common_install_libs:		common
582
	@$(MAKE) -C ${SRCCOMMONDIR} install
583

584
install_handler_libs:	handler
585
	@$(MAKE) -C ${SRCHANDLERDIR} install
586

587
install_portal_libs:		portal
588
	@$(MAKE) -C ${SRCPORTALDIR} install
589

590
install_manager_libs:	manager
591
	@$(MAKE) -C ${SRCMANAGERDIR} install
592

Xavier Guimard's avatar
Xavier Guimard committed
593
install_bin:	install_conf_dir
594 595
	# Binary install
	@install -v -d $(RBINDIR)
596
	@cp -f\
Xavier Guimard's avatar
Xavier Guimard committed
597
		${SRCHANDLERDIR}/eg/scripts/purgeLocalCache \
598
		${SRCPORTALDIR}/site/cron/purgeCentralCache \
599
		${SRCCOMMONDIR}/scripts/convertConfig \
Xavier Guimard's avatar
Xavier Guimard committed
600
		${SRCCOMMONDIR}/scripts/lmMigrateConfFiles2ini \
601
		${SRCCOMMONDIR}/scripts/rotateOidcKeys \
Xavier Guimard's avatar
Xavier Guimard committed
602
		${SRCMANAGERDIR}/scripts/lmConfigEditor \
603
		${SRCCOMMONDIR}/scripts/lemonldap-ng-cli \
604
		${SRCCOMMONDIR}/scripts/importMetadata \
605
			$(RBINDIR)
606
	@if [ ! "$(APACHEUSER)" ]; then \
607
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
608
	else \
609
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
610 611
	fi
	@if [ ! "$(APACHEGROUP)" ]; then \
612
		$(PERL) -i -pe 's#__APACHEGROUP__#nobody#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
613
	else \
614
		$(PERL) -i -pe 's#__APACHEGROUP__#$(APACHEGROUP)#g;' $(RBINDIR)/lmConfigEditor $(RBINDIR)/lemonldap-ng-cli; \
615
	fi
616
	@chmod +x $(RBINDIR)/*
617

618
install_fastcgi_server:
619
	@install -v -d $(RSBINDIR) $(RINITDIR) $(RETCDEFAULTDIR) $(RFASTCGISOCKDIR)
620
	@cp -f fastcgi-server/sbin/llng-fastcgi-server $(RSBINDIR)
621
	@chmod +x $(RSBINDIR)/llng-fastcgi-server
622 623
	@cp -f fastcgi-server/rc/llng-fastcgi-server $(RINITDIR)
	@cp -f fastcgi-server/default/llng-fastcgi-server $(RETCDEFAULTDIR)
624
	@$(PERL) -pi -e 's#__SBINDIR__#$(SBINDIR)#;s#__DEFAULTDIR__#$(ETCDEFAULTDIR)#;s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#g;' \
625 626
		$(RETCDEFAULTDIR)/llng-fastcgi-server \
		$(RSBINDIR)/llng-fastcgi-server \
627
		$(RINITDIR)/llng-fastcgi-server
628 629 630 631 632 633
	@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 \
634
		$(PERL) -pi -e 's#__GROUP__#nobody#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
635
	else \
636
		$(PERL) -pi -e 's#__GROUP__#$(FASTCGIGROUP)#' $(RETCDEFAULTDIR)/llng-fastcgi-server; \
637
	fi
638
	@if [ "$(FASTCGIUSER)" != "" ]; then \
639 640 641 642 643 644 645 646
		chown $(FASTCGIUSER) $(RFASTCGISOCKDIR) || exit 1; \
		if [ "$(FASTCGIGROUP)" != "" ]; then \
			chgrp $(FASTCGIGROUP) $(RFASTCGISOCKDIR) || exit 1; \
		fi; \
		chmod 770 $(RFASTCGISOCKDIR); \
	else \
		chmod 777 $(RFASTCGISOCKDIR); \
	fi
647

Xavier Guimard's avatar
Xavier Guimard committed
648 649 650
install_uwsgi_server:
	@install -v -d $(RUWSGIYAMLDIR) $(RLLNGAPPDIR)
	@install -m 644 -v fastcgi-server/uwsgi/llng-server.yaml $(RUWSGIYAMLDIR)/llng-server.yaml
Xavier Guimard's avatar
Xavier Guimard committed
651
	@install -m 644 -v $(SRCHANDLERDIR)/eg/llng-server.psgi $(RLLNGAPPDIR)/llng-server.psgi
652
	$(PERL) -pi -e 's#__APPDIR__#$(LLNGAPPDIR)#;s#__UID__#$(UWSGIUSER)#;s#__GID__#$(UWSGIGROUP)#;' $(RUWSGIYAMLDIR)/llng-server.yaml
Xavier Guimard's avatar
Xavier Guimard committed
653

Xavier Guimard's avatar
Xavier Guimard committed
654 655
# Site install

656
install_site:	install_manager_site install_portal_site install_handler_site install_test_site install_examples_site install_doc_site install_webserver_conf
657
	# Site install
658
	@install -v -d $(RCONFDIR)
659 660
	# Check if erase is wanted
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
661
		cp -f _example/etc/for_etc_hosts $(RCONFDIR); \
662
	fi
Xavier Guimard's avatar
Xavier Guimard committed
663
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)/for_etc_hosts
664
	# Fix a lost of rights on the main directory
665
	@chmod 755 $(RBINDIR) $(RDOCUMENTROOT) $(REXAMPLESDIR) $(RHANDLERDIR) $(RPORTALSTATICDIR) $(RMANAGERSITEDIR) $(RTOOLSDIR) $(RCONFDIR) $(RDATADIR)
666
	@echo
667
	@echo "LemonLDAP::NG v${VERSION} is installed with these parameters:"
668 669 670 671 672
	@echo "  - System configuration: ${CONFDIR}"
	@echo "  - DNS domain (for cookies and virtual hosts): ${DNSDOMAIN}"
	@echo
	@echo "To finish configuration:"
	@echo
673 674 675 676
	@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"
677
	@echo "      include ${CONFDIR}/test-apache$(APACHEVERSION).conf"
678
	@echo
679 680
	@echo "2 - Restart Apache:"
	@echo "      apache$(APACHEVERSION)ctl restart"
681
	@echo
682
	@echo "3 - Run 'make postconf' as root to update /etc/hosts if your DNS service does not known auth.$(DNSDOMAIN) and manager.$(DNSDOMAIN)"
683
	@echo
684 685 686 687 688 689
	@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"
690
	@echo
691
	@if [ ! "$(APACHEUSER)" ]; then \
692
		echo;echo "    Warning, since APACHEUSER was not set, $(APACHESESSIONFILEDIR), $(APACHEPSESSIONFILEDIR), $(CAPTCHADIR) and $(CONFDIR) have permissive permissions."; \
693 694 695
		echo "    Fix them by yourself to restrict their view to apache process only"; \
	fi
	@echo
696

697 698 699
install_webserver_conf:
	@install -m 755 -v -d $(RCONFDIR)
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
700 701 702 703 704
		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); \
705 706 707
	fi
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g; \
			s#__PORTALDIR__#$(PORTALDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
708
			s#__PORTALSITEDIR__#$(PORTALSITEDIR)/#g; \
709
			s#__PORTALSTATICDIR__#$(PORTALSTATICDIR)/#g; \
710
			s#__MANAGERDIR__#$(MANAGERDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
711
			s#__MANAGERSITEDIR__#$(MANAGERSITEDIR)/#g; \
712 713
			s#__MANAGERSTATICDIR__#$(MANAGERSTATICDIR)/#g; \
			s#__TESTDIR__#$(TESTDIR)/#g; \
Xavier Guimard's avatar
Xavier Guimard committed
714
			s#__PORT__#$(PORT)#g; \
715
			s#__CONFDIR__#$(CONFDIR)#g; \
Xavier Guimard's avatar
Xavier Guimard committed
716
			s#__FASTCGISOCKDIR__#$(FASTCGISOCKDIR)#g; \
717
			s#__VHOSTLISTEN__#$(VHOSTLISTEN)#g; \
Xavier Guimard's avatar
Xavier Guimard committed
718
			s#__DEFDOCDIR__#$(DEFDOCDIR)/#g;' $(RCONFDIR)/*apache*.conf $(RCONFDIR)/*nginx*.conf
719

720 721
install_manager_site:	install_conf_dir
	# Manager install
722
	@install -v -d $(RMANAGERDIR) $(RMANAGERSTATICDIR) \
723
		$(RMANAGERTEMPLATESDIR)
724
	@cp -pR -f $(SRCMANAGERDIR)/site/htdocs/manager.* $(RMANAGERSITEDIR)
725
	@cp -pR $(SRCMANAGERDIR)/site/htdocs/static/* $(RMANAGERSTATICDIR)
726
	@for f in $(SRCMANAGERDIR)/site/templates/*.tpl; do \
727 728 729 730 731
		./scripts/transform-templates \
			usedebianlibs $(USEDEBIANLIBS) \
			useexternallibs $(USEEXTERNALLIBS) \
			jsminified $(JSCOMPRESS) \
			cssminified $(CSSCOMPRESS) <$$f \
732 733
			> $(RMANAGERTEMPLATESDIR)/`basename $$f`; \
	done
734
	@if test "$(USEEXTERNALLIBS)" = "yes"; then \
735
		rm -rvf $(MANAGEREXTERNALLIBS); \
736
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
737 738
		rm -rvf $(MANAGERLIBSTOREMOVEFORDEBIAN); \
	fi
739
	# Clean svn files
740
	@rm -rf $$(find ${RMANAGERSTATICDIR} \
741
		$(RMANAGERTEMPLATESDIR) $(RCONFDIR) -type d -name .svn)
742 743
	@$(PERL) -i -pe 's#__MANAGERSTATICDIR__#$(MANAGERRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
	@$(PERL) -i -pe 's#__MANAGERTEMPLATESDIR__#$(MANAGERTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
744 745 746

install_portal_site:	install_conf_dir
	# Portal install
747
	@install -v -d $(RPORTALDIR) $(RPORTALSTATICDIR) \
748
		$(RPORTALTEMPLATESDIR) \
749
		$(RCRONDIR) $(RCONFDIR)
750
	@cp -pR -f $(SRCPORTALDIR)/site/htdocs/index.* $(RPORTALSITEDIR)
751
	@cp -pR -f $(SRCPORTALDIR)/site/htdocs/static/* $(RPORTALSTATICDIR)
752
	@cd $(SRCPORTALDIR)/site/templates; for f in `find * -type f -name '*.tpl'`; do \
753 754
		echo "$$f => $(RPORTALTEMPLATESDIR)/$$f"; \
		mkdir -p $(RPORTALTEMPLATESDIR)/`dirname $$f`; \
Xavier Guimard's avatar
Xavier Guimard committed
755
		../../../scripts/transform-templates \
756 757 758 759
			usedebianlibs $(USEDEBIANLIBS) \
			useexternallibs $(USEEXTERNALLIBS) \
			jsminified $(JSCOMPRESS) \
			cssminified $(CSSCOMPRESS) <$$f \
760 761
			>$(RPORTALTEMPLATESDIR)/$$f; \
	done; cd -
762 763
	@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
764
		install -m 644 -v $$f $(RPORTALTEMPLATESDIR)/$$f; \
765 766
	done; cd -
	@cd $(SRCPORTALDIR)/site/templates; for l in `find * -type l`; do \
Xavier Guimard's avatar
Xavier Guimard committed
767
		echo link to do $$l `readlink $$l`; \
768 769 770 771
		target=`readlink $$l`; \
		cd $(RPORTALTEMPLATESDIR); \
		ln -s $$target $$l; \
		cd -; \
772
	done
Xavier Guimard's avatar
Xavier Guimard committed
773
	@if test "$(USEEXTERNALLIBS)" = "yes"; then \
774
		rm -rvf $(PORTALEXTERNALLIBS); \
775
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
776 777
		rm -rvf $(PORTALLIBSTOREMOVEFORDEBIAN); \
	fi
778
	# Cron files
779
	@cp -f $(SRCPORTALDIR)/site/cron/purgeCentralCache.cron.d $(RCRONDIR)/lemonldap-ng-portal
780
	@if [ ! "$(APACHEUSER)" ]; then \
781
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RCRONDIR)/lemonldap-ng-portal; \
782
	else \
783
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RCRONDIR)/lemonldap-ng-portal; \
784
	fi
785
	@$(PERL) -i -pe 's#__BINDIR__#$(BINDIR)#g;' $(RCRONDIR)/lemonldap-ng-portal
786
	# Clean SVN files
787
	@rm -rf $$(find ${RPORTALDIR} $(RPORTALSKINSDIR) $(RCRONDIR) $(RCONFDIR) -type d -name .svn)
Xavier Guimard's avatar
Xavier Guimard committed
788 789
	@$(PERL) -i -pe 's#__PORTALSTATICDIR__#$(PORTALRELATIVESTATICDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
	@$(PERL) -i -pe 's#__PORTALTEMPLATESDIR__#$(PORTALTEMPLATESDIR)#g' $(RCONFDIR)/$(CONFFILENAME)
790 791

install_handler_site:	install_conf_dir
792
	# Handler install
793
	@install -v -d ${RHANDLERDIR}
Xavier Guimard's avatar
Xavier Guimard committed
794
	@cp -f $(SRCHANDLERDIR)/eg/scripts/purgeLocalCache.cron.d $(RCRONDIR)/lemonldap-ng-handler
795
	@if [ ! "$(APACHEUSER)" ]; then \
796
		$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RCRONDIR)/lemonldap-ng-handler; \
797 798 799 800
	else \
		$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RCRONDIR)/lemonldap-ng-handler; \
	fi
	@$(PERL) -i -pe 's#__BINDIR__#$(BINDIR)#g;' $(RCRONDIR)/lemonldap-ng-handler
801
	@rm -rf $$(find $(RHANDLERDIR) -type d -name .svn)
802 803

install_test_site:
804
	# Test site install
805
	@install -v -d $(RTESTDIR)
806
	@cp -pR -f _example/test/* $(RTESTDIR)
807
	@rm -rf $$(find $(RTESTDIR) -type d -name .svn)
Xavier Guimard's avatar
Xavier Guimard committed
808
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RTESTDIR)/index.pl
809
	@rm -rf $$(find $(RTESTDIR) -type d -name .svn)
810 811

install_examples_site:
812
	# Examples install
813
	@install -v -d $(REXAMPLESDIR)
Xavier Guimard's avatar
Xavier Guimard committed
814
	@for i in portal manager handler; do \
815
		cp -a -f lemonldap-ng-$$i/eg $(REXAMPLESDIR)/$$i; \
816
	done
817
	@cp -a -f fastcgi-server/psgi/llngapp.psgi $(REXAMPLESDIR)/$$i
818
	@rm -rf $(REXAMPLESDIR)/portal/skins \
Xavier Guimard's avatar
Xavier Guimard committed
819
		$(REXAMPLESDIR)/manager/skins \
820
	@rm -rf $$(find $(REXAMPLESDIR) -type d -name .svn)
821

822
install_doc_site:
823
	# Offline documentation install
824
	@rm -rf $(RDEFDOCDIR)
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
	# 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
844
	# Remove js
845
	@cd $(RDEFDOCDIR) && if test "$(USEEXTERNALLIBS)" = "yes"; then \
Xavier Guimard's avatar
Xavier Guimard committed
846 847 848
		rm -rvf $(DOCEXTERNALLIBS); \
	elif test "$(USEDEBIANLIBS)" = "yes"; then \
		rm -rvf $(DOCLIBSTOREMOVEFORDEBIAN); \
849
	fi && cd -
850

851
install_conf_dir:	install_sessions_dir install_notif_dir install_captcha_dir
852
	# Configuration files install
853
	@install -v -d $(RCONFDIR) $(RFILECONFIGDIR) $(RTOOLSDIR)
854
	@if [ "$(ERASECONFIG)" -eq "1" ]; then \
855
		cp -f $(SRCCOMMONDIR)/$(CONFFILENAME) $(RCONFDIR); \
Xavier Guimard's avatar
Xavier Guimard committed
856
		$(PERL) -i -pe 's#^dirName\s*=\s*.*#dirName = $(FILECONFIGDIR)#g' $(RCONFDIR)/$(CONFFILENAME); \
857
	fi
858
	@cp _example/conf/lmConf-1.json $(RFILECONFIGDIR)
Xavier Guimard's avatar
Xavier Guimard committed
859
	@$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g;\
860
		s#__SESSIONDIR__#$(APACHESESSIONFILEDIR)#g;\
861
		s#__PSESSIONDIR__#$(APACHEPSESSIONFILEDIR)#g;\
862
		s#__NOTIFICATIONDIR__#$(APACHEFILENOTIFDIR)#g;' $(RFILECONFIGDIR)/lmConf-1.json
863 864 865 866 867 868 869 870 871
	@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
872 873
	@cp $(SRCCOMMONDIR)/tools/lmConfig.* $(SRCCOMMONDIR)/tools/apache-session-mysql.sql $(RTOOLSDIR)
	@cp $(SRCCOMMONDIR)/tools/sso.schema $(RTOOLSDIR)
874
	$(PERL) -i -pe 's/__DNSDOMAIN__/$(DNSDOMAIN)/g' $(RCONFDIR)/$(CONFFILENAME)
875
	@rm -rf $$(find $(RCONFDIR) $(RFILECONFIGDIR) $(RTOOLSDIR) -type d -name .svn)
876 877

install_sessions_dir:
878
	@install -m 777 -v -d $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR)
879 880
	# Fix Apache::Session directories permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
881
		chown $(APACHEUSER) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR) || exit 1; \
882
		if [ "$(APACHEGROUP)" != "" ]; then \
883
			chgrp $(APACHEGROUP) $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR) || exit 1; \
884
		fi; \
885
		chmod 770 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR); \
886
	else \
887
		chmod 777 $(RAPACHESESSIONFILEDIR) $(RAPACHESESSIONFILELOCKDIR) $(RAPACHEPSESSIONFILEDIR) $(RAPACHEPSESSIONFILELOCKDIR); \
888 889
	fi

890 891 892 893 894 895 896 897 898 899 900 901 902
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

903
install_captcha_dir:
904
	@install -m 777 -v -d $(RCAPTCHADIR)
905 906
	# Fix captcha directory permissions
	@if [ "$(APACHEUSER)" != "" ]; then \
907
		chown $(APACHEUSER) $(RCAPTCHADIR) || exit 1; \
908
		if [ "$(APACHEGROUP)" != "" ]; then \
909
			chgrp $(APACHEGROUP) $(RCAPTCHADIR) || exit 1; \
910
		fi; \
911
		chmod 770 $(RCAPTCHADIR); \
912
	else \
913
		chmod 777 $(RCAPTCHADIR); \
914 915
	fi

916
postconf_hosts:
917
	@cat ${CONFDIR}/for_etc_hosts >> /etc/hosts
918 919
	@echo "/etc/hosts was updated"

920
postconf: postconf_hosts
921 922
	@echo "Post configuration done"

Xavier Guimard's avatar
Xavier Guimard committed
923 924 925 926 927 928 929 930 931 932 933 934
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
935
	perl -i -ne 'next if/(?:fastcgi|uwsgi).*deb$$/;s/lemonldap-ng-(?:fastcgi-server|uwsgi-app)//;print' /tmp/lemonldap-ng_$(VERSION)*.changes
Xavier Guimard's avatar
Xavier Guimard committed
936 937 938 939
	cd /tmp/lemonldap-ng-$(VERSION) && \
	$(SU) debi

debian-install-for-nginx: debian-packages
940 941 942 943 944 945
	perl -i -ne 'next if/(?:uwsgi).*deb$$/;s/lemonldap-ng-(?:uwsgi-app)//;print' /tmp/lemonldap-ng_$(VERSION)*.changes
	cd /tmp/lemonldap-ng-$(VERSION) && \
	$(SU) debi

debian-install-for-nginx-uwsgi: debian-packages
	perl -i -ne 'next if/(?:fastcgi).*deb$$/;s/lemonldap-ng-(?:fastcgi-server)//;print' /tmp/lemonldap-ng_$(VERSION)*.changes
Xavier Guimard's avatar
Xavier Guimard committed
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
	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

962
clean:		common_clean handler_clean portal_clean manager_clean stop_web_server
Xavier Guimard's avatar
Xavier Guimard committed
963 964 965 966 967 968 969
	@rm -f $$(find */ -name '*bak' -delete)
	@rm -rf doc/devel
	@rm -vf *gz *zip
	@rm -rf lemonldap-ng-$(VERSION)
	@echo "Cleaned"

common_clean:
970
	-@if test -e ${SRCCOMMONDIR}/Makefile;then $(MAKE) -C ${SRCCOMMONDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
971 972 973
	@rm -vf common*

handler_clean:
974
	-@if test -e ${SRCHANDLERDIR}/Makefile;then $(MAKE) -C ${SRCHANDLERDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
975 976 977
	@rm -vf handler*

portal_clean:
978
	-@if test -e ${SRCPORTALDIR}/Makefile;then $(MAKE) -C ${SRCPORTALDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
979 980 981
	@rm -vf portal*

manager_clean:
982
	-@if test -e ${SRCMANAGERDIR}/Makefile;then $(MAKE) -C ${SRCMANAGERDIR} distclean;fi
Xavier Guimard's avatar
Xavier Guimard committed
983 984 985 986 987
	@rm -vf manager*

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

988 989
uninstall:	configure handler_uninstall portal_uninstall manager_uninstall

990 991 992 993
common_uninstall:	common
	@$(MAKE) -C ${SRCCOMMONDIR} uninstall
	@rm -vf common_uninstall

994
handler_uninstall:	handler
995
	@$(MAKE) -C ${SRCHANDLERDIR} uninstall
996
	@rm -vf handler_uninstall
997 998

portal_uninstall:		portal
999
	@$(MAKE) -C ${SRCPORTALDIR} uninstall
1000
	@rm -vf portal_uninstall
1001 1002

manager_uninstall:	manager
1003
	@$(MAKE) -C ${SRCMANAGERDIR} uninstall
1004
	@rm -vf manager_uninstall
1005

Xavier Guimard's avatar
Xavier Guimard committed
1006 1007 1008
# Packaging target
# ----------------

1009
dist:	clean
1010 1011 1012 1013 1014 1015 1016 1017
	@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)

1018
rpm-dist:	clean
1019
	@mkdir -p lemonldap-ng-$(VERSION)
1020
	@cp -pRH $$(find * -maxdepth 0|grep -v -e "\(lemonldap-ng-$(VERSION)\|debian\)") lemonldap-ng-$(VERSION)
1021 1022
	@rm -rf $$(find lemonldap-ng-$(VERSION) -name .svn -print)
	@find $$dir -name '*.bak' -delete
1023
	@rm -rf lemonldap-ng-$(VERSION)/lemonldap-ng-$(VERSION)
Xavier Guimard's avatar
Xavier Guimard committed
1024
	@$(COMPRESS) lemonldap-ng-$(VERSION).$(COMPRESSSUFFIX) lemonldap-ng-$(VERSION)
1025
	@rm -rf lemonldap-ng-$(VERSION)
1026

1027

1028 1029
debian-dist:	clean
	@mkdir -p lemonldap-ng-$(VERSION)
1030
	@cp -pRH $$(find * -maxdepth 0|grep -v -e "\(lemonldap-ng-$(VERSION)\|rpm\)") lemonldap-ng-$(VERSION)
1031 1032
	@rm -rf $$(find lemonldap-ng-$(VERSION) -name .svn -print)
	@find $$dir -name '*.bak' -delete