#
# Makefile.in
#
# This file is part of webCDwriter - Network CD/DVD Writing.
#
# Copyright (C) 1999-2005 J�rg P. M. Haeger
#
# webCDwriter is free software. See CDWserver.cpp for details.
#

goal: CDWserver

include ../config

HTTPServer.o: Config.h HTTPServer.h Log.h Server.h HTTPServer.cpp
	$(CXX) $(CXXFLAGS) -c HTTPServer.cpp

Log.o: Version.h Config.h Log.h Log.cpp
	$(CXX) $(CXXFLAGS) -c Log.cpp

Server.o: Support.h Version.h Config.h Log.h \
	PAM.h Session.h Status.h Server.h Server.cpp
	$(CXX) $(CXXFLAGS) -c Server.cpp

CDWserver.o: Config.h Log.h Server.h CDWserver.cpp
	$(CXX) $(CXXFLAGS) -c CDWserver.cpp

%.o: %.cpp %.h
	$(CXX) $(CXXFLAGS) -c $<

CDWrootGate: PAM.h CDWrootGate.cpp
	$(CXX) $(CXXFLAGS) CDWrootGate.cpp -o CDWrootGate $(LFLAGS2)

CDWserver: \
	BufferedReader.o StreamTokenizer.o Socket.o \
	ServerSocket.o String.o StringBuffer.o Thread.o \
	PrintWriter.o Version.o \
	HTTPRequest.o HTTPResponse.o HTTPServer.o \
	Support.o LineReader.o Process.o Cdrecord.o Log.o \
	Accounts.o AudioToWAV.o Session.o Status.o Store.o \
	Config.o Server.o CDWserver.o \
	$(PROMODULES) \
	CDWrootGate CDWverify
	$(CXX) $(CXXFLAGS) -o CDWserver *.o $(LFLAGS)

CDWverify: CDWverify.cpp
	$(CXX) $(CXXFLAGS) CDWverify.cpp -o CDWverify

install: CDWserver
	groupadd $(GROUP) 2> /dev/null \
		|| pw addgroup $(GROUP) 2> /dev/null \
		|| :
	useradd -c "System User for webCDwriter" \
			-g $(GROUP) $(USER) -r 2> /dev/null \
		|| useradd -c "System User for webCDwriter" \
			-g $(GROUP) $(USER) 2> /dev/null \
		|| pw adduser $(USER) -c "System User for webCDwriter" \
			-g $(GROUP) 2> /dev/null \
		|| :
	install -d -m 755 $(CONFIGDIR)/
	install -d -m 755 $(EXPORTDIR)/
	install -d -m 755 $(EXPORTDIR)/Server/
	install -d -m 755 $(EXPORTDIR)/Server/doc/
	$(INSTALL_644) ../COPYING ../ChangeLog ../README ../*.html \
		$(EXPORTDIR)/Server/doc/
	install -d $(INITDIR)/
	install -d $(SBINDIR)/
	rm -f $(SBINDIR)/CDWserver-GPL
	$(INSTALL) -m 755 CDWserver $(SBINDIR)/
	ln -sf CDWserver $(SBINDIR)/CDWpasswd
	ln -sf CDWserver $(SBINDIR)/CDWuseradd
	install -d $(BINDIR)/
	$(INSTALL) -g $(GROUP) -m 4710 -o root CDWrootGate \
		$(BINDIR)/ 2> /dev/null \
		|| $(INSTALL) CDWrootGate $(BINDIR)/
	$(INSTALL) -g $(GROUP) -m 4710 -o root CDWverify \
		$(BINDIR) 2> /dev/null \
		|| $(INSTALL) CDWverify $(BINDIR)/
	install -d -g $(GROUP) -m 755 -o $(USER) \
		$(TOOLSDIR) 2> /dev/null \
		|| install -d -m 755 $(TOOLSDIR)
	install -d -g $(GROUP) -m 700 -o $(USER) \
		$(PROJECTSDIR)/ 2> /dev/null \
		|| install -d -m 700 $(PROJECTSDIR)/
	install -d -g $(GROUP) -m 700 -o $(USER) \
		$(LOGDIR)/ 2> /dev/null \
		|| install -d -m 700 $(LOGDIR)/
	/bin/chown $(USER) $(LOGDIR)/log 2> /dev/null || :
	/bin/chown $(USER) $(LOGDIR)/sessions 2> /dev/null || :
	install -d -g $(GROUP) -m 755 -o $(USER) \
		$(MNTDIR) 2> /dev/null \
		|| install -d -m 755 $(MNTDIR)
	install -d -g $(GROUP) -m 700 -o $(USER) \
		$(SPOOLDIR)/ 2> /dev/null \
		|| install -d -m 700 $(SPOOLDIR)/
	$(INSTALL_DIR) $(PAMDIR)/ 2> /dev/null || :
	$(INSTALL_644) PAM-cdwserver $(PAMDIR)/cdwserver \
		2> /dev/null || :
	$(MAKE) install -C config
	$(MAKE) install -C http
	$(MAKE) install -C init.d
	$(MAKE) install -C test

clean:
	rm -f *~ .nfs* *.o core
	$(MAKE) -C test clean

maintainer-clean:
	rm -f *~ .nfs* *.o core
	rm -f a.out config.h CDWrootGate CDWserver CDWverify
	rm -f Makefile
	$(MAKE) -C config clean
	$(MAKE) -C http clean
	$(MAKE) -C init.d clean
	$(MAKE) -C test maintainer-clean
