summaryrefslogtreecommitdiffstats
path: root/init.mk
blob: 1c3035c71206a522e4f963329b38789bd1e2d096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# ver R1.00/2017-03-16 Creation of this file
# ver R2.00/2017-04-05 Updated the docbuild.git clone command.

ifeq ($(VERBOSE),yes)
VERB :=
else
VERB := @
endif

#Git repositories to be cloned
REPO_DOCBUILD      := build/docbuild.git
NAME_DOCBUILD      := docbuild

GLOBALTMPCLONEROOT = ../../tmpcommon
ifeq ($(BOOK_GLOBALCLONEROOT),)
  TMPCLONEROOT := tmpcommon
else
  ifeq ($(BOOK_GLOBALCLONEROOT),yes)
    TMPCLONEROOT := $(GLOBALTMPCLONEROOT)
  else
    TMPCLONEROOT := $(BOOK_GLOBALCLONEROOT)/tmpcommon
  endif
endif
DIR_TMPCLONEROOT := $(dir $(TMPCLONEROOT))
ifeq ($(wildcard $(DIR_TMPCLONEROOT)),)
$(error Parent of selected clone root does not exist ($(DIR_TMPCLONEROOT)))
endif

.PHONY:  initbuild usageinit cleaninit
# Keep usageinit as default target here to avoid init by mistake

usageinit: docusage
	@echo 'make initbuild  Create s_docbuild and if it does not exist, clone docbuild.git'
	@echo '  Default clone in tmpcommon'
	@echo '  BOOK_GLOBALCLONEROOT=yes  Clone in $(GLOBALTMPCLONEROOT)'
	@echo '  BOOK_GLOBALCLONEROOT=parentdir  Clone in parentdir/tmpcommon'

	@echo 'make pullbuild   git pull in s_docbuild'
	@echo 'make cleaninit   Delete all s_* symlinks and local tmpcommon/'


initbuild:    s_docbuild
pullbuild:
	$(VERB)if [ ! -d s_docbuild ]; then echo "ERROR: No s_docbuild exists?" ; exit 10 ; fi
	$(VERB)cd s_docbuild ; git pull
s_docbuild: $(TMPCLONEROOT)/$(NAME_DOCBUILD)
	$(VERB)rm s_docbuild 2>/dev/null; ln -s $(TMPCLONEROOT)/$(NAME_DOCBUILD) s_docbuild

$(TMPCLONEROOT)/$(NAME_DOCBUILD):
	$(VERB)if [ ! -d "$(TMPCLONEROOT)" ] ; then mkdir -p "$(TMPCLONEROOT)" ; fi
	$(VERB)if [ -d "$(TMPCLONEROOT)/$(NAME_DOCBUILD)" ] ; then \
	     echo "Already exists $(TMPCLONEROOT)/$(NAME_DOCBUILD)" ; \
	     echo "Doing git pull instead"; cd $(TMPCLONEROOT)/$(NAME_DOCBUILD) ; git pull ; \
	   else \
	     echo "Cloning $(REPO_DOCBUILD) in $(TMPCLONEROOT)" ; \
	     cd "$(TMPCLONEROOT)" ; \
	     git clone -b master git@git.enea.se:$(REPO_DOCBUILD) $(NAME_DOCBUILD) ; \
	   fi

cleaninit:
	@echo "Clean only local tmpcommon/ and all local temporary symlinks s_docbuild etc."
	$(VERB)rm -rf tmpcommon 2>/dev/null ; true
	$(VERB)rm s_* 2>/dev/null ; true