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