summaryrefslogtreecommitdiffstats
path: root/doc/init.mk
blob: 252409c237fea4a3e6da7a15cbae175f36e16624 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Makefile including this should first set nondefault BRANCH_DOCENEACOMMON before including it
#   and should have targets init: s_docbuild and optional initcommon: s_doceneacommon
#   Typically let doc: depend on init and initcommon inside Makefile
#   Manually optionally set GLOBALTMPCLONEROOT to yes  or  to a parent dir for tmpcommon
# This init.mk file ver R1.00/2016-04-29

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

#Git repositories to be cloned
REPO_DOCBUILD      := build/docbuild.git
NAME_DOCBUILD      := docbuild
REPO_DOCENEACOMMON := linux/documentation.git
NAME_DOCENEACOMMON := doceneacommon

# Set nondefault BRANCH_DOCENEACOMMON in Makefile
BRANCH_DOCENEACOMMON ?= master-enea
# Separate clones of documentation.git with different branches, needed if cloned globally with risk that different distros can be at same place
ifneq ($(BRANCH_DOCENEACOMMON),master-enea)
NAME_DOCENEACOMMON := doceneacommon_$(BRANCH_DOCENEACOMMON)
endif

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 initcommon usageinit cleaninit
# Keep usageinit as default target here to avoid init by mistake

usageinit: docusage
	@echo 'make initbuild  Create s_docbuild and if not exists, clone docbuild.git'
	@echo 'make initcommon Create s_doceneacommon and if not exists, clone documentation.git'
	@echo '  Default clone in tmpcommon'
	@echo '  BOOK_GLOBALCLONEROOT=yes  Clone in $(GLOBALTMPCLONEROOT)'
	@echo '  BOOK_GLOBALCLONEROOT=parentdir  Clone in parentdir/tmpcommon'
	@echo '  Default branch for documentation.git is master-enea'
	@echo '  BRANCH_DOCENEACOMMON=... If another branch, Makefile should set this'
	@echo 'make pullbuild   git pull in s_docbuild'
	@echo 'make pullcommon  git pull in s_doceneacommon'
	@echo 'make cleaninit   Delete all s_* symlinks and local tmpcommon/'


# MOVE these to Makefile and set also non-default BRANCH_DOCENEACOMMON in Makefile
initbuild:    s_docbuild
initcommon:   s_doceneacommon
pullbuild:
	$(VERB)if [ ! -d s_docbuild ]; then echo "ERROR: No s_docbuild exists?" ; exit 10 ; fi
	$(VERB)cd s_docbuild ; git pull
pullcommon:
	$(VERB)if [ ! -d s_doceneacommon ]; then echo "ERROR: No s_doceneacommon exists?" ; exit 10 ; fi
	$(VERB)cd s_doceneacommon ; git pull

s_docbuild: $(TMPCLONEROOT)/$(NAME_DOCBUILD)
	$(VERB)rm s_docbuild 2>/dev/null; ln -s $(TMPCLONEROOT)/$(NAME_DOCBUILD) s_docbuild

s_doceneacommon: $(TMPCLONEROOT)/$(NAME_DOCENEACOMMON)
	$(VERB)rm s_doceneacommon 2>/dev/null; ln -s $(TMPCLONEROOT)/$(NAME_DOCENEACOMMON) s_doceneacommon

$(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-enea git@git.enea.se:$(REPO_DOCBUILD) $(NAME_DOCBUILD) ; \
	   fi

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

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