1
|
##### Configuration
|
2
|
|
3
|
src_server ?= vegbiendev
|
4
|
src_user ?= $(USER)
|
5
|
test ?=
|
6
|
|
7
|
##### Vars/functions
|
8
|
|
9
|
# Make
|
10
|
null :=
|
11
|
space := $(null) $(null)
|
12
|
comma := ,
|
13
|
pathParts = $(shell path="$(1)"; echo "$${path%%/*}" "$${path\#*/}")
|
14
|
topDir = $(word 1,$(pathParts))
|
15
|
subPath = $(word 2,$(pathParts))
|
16
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@) \
|
17
|
--makefile=../input.Makefile
|
18
|
# input.Makefile path is relative to subdir
|
19
|
|
20
|
# Formatting
|
21
|
sed = sed -$(if $(filter Darwin,$(os)),E,r)
|
22
|
_2Space = $(subst _,$(space),$(1))
|
23
|
*2Space = $(call _2Space,$*)
|
24
|
|
25
|
# Filesystem
|
26
|
wildcard/ = $(shell bash -c 'shopt -s nullglob; echo $(1)')
|
27
|
# needed because builtin $(wildcard) doesn't do / suffix correctly
|
28
|
no/ = $(1:/=)# remove trailing /
|
29
|
+w = $(wildcard $+)# existing items in $+
|
30
|
CP := cp -p
|
31
|
cp = $(CP) $< $@
|
32
|
|
33
|
# File editing
|
34
|
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
|
35
|
|
36
|
# System
|
37
|
os := $(shell uname)
|
38
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
39
|
date = $(shell date +"%Y-%m-%d-%H-%M-%S")
|
40
|
|
41
|
# Terminal
|
42
|
esc := '['
|
43
|
reset := $(esc)'0m'
|
44
|
emph := $(esc)'7m '
|
45
|
endEmph := ' '$(reset)
|
46
|
|
47
|
# User interaction
|
48
|
|
49
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
50
|
|
51
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
52
|
|
53
|
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
|
54
|
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
|
55
|
$(error Aborting))
|
56
|
|
57
|
## SVN
|
58
|
|
59
|
addFile = $(if $(wildcard $(1)),,touch $(1) && )svn add $(1)
|
60
|
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
|
61
|
add* = $(if $(1),svn add --depth=empty $(1))
|
62
|
|
63
|
# Revisions
|
64
|
revision = $(shell svn info $(1)|$(sed) -n 's/^Last Changed Rev: (.*)$$/\1/p')
|
65
|
rootRevision = $(call revision,$(root))
|
66
|
initRootRevision := $(if $(root),$(rootRevision))
|
67
|
rootRevisionsEqual := $(filter $(rootRevision),$(initRootRevision))
|
68
|
rootRevisions = $(foreach rootRevision,$(rootRevision),$(if\
|
69
|
$(rootRevisionsEqual),$(initRootRevision),$(initRootRevision)-$(rootRevision)))
|
70
|
# only evaluate $(rootRevision) once
|
71
|
version ?= $(date).r$(rootRevisions)
|
72
|
|
73
|
# rsync
|
74
|
rsync* := "time" rsync$(if $(test), --dry-run) --archive --update --verbose\
|
75
|
--itemize-changes --progress
|
76
|
rsync := $(rsync*) --exclude=".svn/" --exclude="*\#" --exclude=".DS_Store"
|
77
|
local := ./
|
78
|
localDirName := $(notdir $(realpath $(local)))
|
79
|
remote := $(src_user)@$(src_server):/home/bien/svn/$(localDirName)/
|
80
|
|
81
|
# DB
|
82
|
mkSchemaCmd = 'CREATE SCHEMA $(1);'
|
83
|
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
|
84
|
|
85
|
##### General targets
|
86
|
|
87
|
all: # must be first target in Makefile, so add an empty version here
|
88
|
|
89
|
.SUFFIXES: # turn off built-in suffix rules
|
90
|
.SECONDARY: # don't automatically delete intermediate files
|
91
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
92
|
|
93
|
_always:
|
94
|
.PHONY: _always
|
95
|
|
96
|
clean: # make sure `make clean` always works
|