################################################################################
#	Master Makefile for TMS Sources
#				T.Barnaby,	BEAM Ltd,	2006-12-07
#				updated by	D.Korchagin,	CERN AB-BI-SW,	2007-08-31
################################################################################
#
TOP	= .
include ${TOP}/Makefile.config
LDIRS	= beam libTms
SDIRS	= tmsExamples tmsControl
DDIRS	= 
ADIRS	= $(LDIRS) $(SDIRS) $(DDIRS)
# Build System Settings
ifeq ("$(BUILD)", "CLIENT")
SDIRS	+= config tmsSigGen tmsStateGen tmsControlGui tmsDevTest tmsTestData
DDIRS	+= datasrc
endif
ifeq ("$(BUILD)", "FULL")
SDIRS	+= config tmsSigGen tmsStateGen tmsControlGui tmsDevTest tmsTestData
SDIRS	+= tmsPuServer tmsServer tmsWeb
DDIRS	+= datasrc
endif
SRC_LIB 	= tms/Readme tms/Makefile tms/Makefile.config tms/include tms/lib/$(CPU)
SRC_LIB 	+= tms/beam tms/libTms
SRC_LIB 	+= tms/tmsExamples tms/tmsControl
SRC_CLIENT	= $(SRC_LIB) tms/config tms/tmsSigGen tms/tmsStateGen
SRC_CLIENT	+= tms/tmsControlGui tms/tmsDevTest tms/datasrc tms/tmsTestData
SRC_MAIN	= $(SRC_CLIENT) tms/tmsPuServer tms/tmsServer tms/tmsWeb
SVNDIRS	= build $(LDIRS) $(SDIRS) $(DDIRS)
SVNROOT	= file:///src/cern/SVN/tms
.PHONY: all install clean includes #depend
.PHONY: fresh checkout commit svnrelease svntag svnimport
all:	info
	@(for f in $(ADIRS); do if !(make -C $$f all); then break; fi; done)
install:
	@for f in $(ADIRS); do if ! (make -C $$f install); then break; fi; done
	cp Makefile Makefile.config $(DEST_DIR)/$(PREFIX)
	cp $(CPFLAGS) tmsExamples $(DEST_DIR)/$(PREFIX)
	 
clean:
	@(for f in $(ADIRS); do (make -C $$f clean); done)
	rm -f tms-*.tar.gz
includes:
	@(for f in $(ADIRS); do (make -C $$f includes); done)
depend:
	@(for f in $(ADIRS); do (make -C $$f depend); done)
fresh:
	make clean includes all #depend all
buildFiles:
	cp $(CPFLAGS) Makefile Makefile.config tms.spec tms-client.spec Readme build
info:
	echo "Build: ${BUILD}"
	echo "Target: ${TARGET}"
	
################################################################################
#	RPM package builds
################################################################################
#
rpms:	clean tms.spec
#rpms:	tms.spec
	tar -czC .. -f ${RPM_DIR}/SOURCES/tms.tar.gz --exclude .svn tms
	rpmbuild -ba -D "version $(VERSION)" -D "release $(RELEASE)" tms.spec 
rpmsInstall:
	-mkdir -p ../packages
	cp ${RPM_DIR}/RPMS/i386/tms-*$(VERSION)-$(RELEASE)*.rpm ../packages
rpms-rh7:	clean tms-client.spec
	tar -czC .. -f ${RPM_DIR}/SOURCES/tms.tar.gz --exclude .svn tms
	rpmbuild -ba tms-client.spec 
################################################################################
#	Source package builds
################################################################################
#
tms-main-src:
	tar -czf tms-main-src-$(VERSION).tar.gz --exclude .svn  -C .. ${SRC_MAIN}
tms-client-src:
	tar -czf tms-client-$(VERSION).tar.gz --exclude .svn -C .. ${SRC_CLIENT}
tms-lib-src:
	tar -czf tms-lib-src-$(VERSION).tar.gz --exclude .svn -C .. ${SRC_LIB}
svnSetup:
#	svnadmin create --fs-type fsfs /src/cern/SVN
#	svn mkdir -m "First import." $(SVNROOT) $(SVNROOT)/design $(SVNROOT)/releases
svnImportAll:
#	for f in $(SVNDIRS); do\
#		(echo Dir: $$f;\
#		svn mkdir -m "First import." $(SVNROOT)/$$f $(SVNROOT)/$$f/trunk $(SVNROOT)/$$f/tags $(SVNROOT)/$$f/branches;\
#		svn import -m "First import." $$f $(SVNROOT)/$$f/trunk); done;
		
svnCheckoutAll:
	for f in $(SVNDIRS); do (svn checkout $(SVNROOT)/$$f/trunk $$f); done;
svnList:
	svn list $(SVNROOT)
svnListReleases:
	svn list $(SVNROOT)/releases
svnCommit:
	for f in $(SVNDIRS); do (echo Dir: $$f; cd $$f; svn commit); done;
svnRelease:
	svn mkdir $(SVNROOT)/releases/release-$(VERSION) -m "Release"
	for f in $(SVNDIRS); do (svn copy  -m "Release" $(SVNROOT)/$$f $(SVNROOT)/releases/release-${VERSION}); done;
svnDiff:
	for f in $(SVNDIRS); do (echo Dir: $$f; cd $$f; svn diff); done;