1 |
3697
|
aaronmk
|
##### Configuration
|
2 |
|
|
|
3 |
7557
|
aaronmk
|
remote_user ?= $(USER)
|
4 |
7564
|
aaronmk
|
remote_host ?= jupiter
|
5 |
|
|
remote_basepath ?= /data/dev/aaronmk/bien
|
6 |
3697
|
aaronmk
|
test ?=
|
7 |
|
|
|
8 |
|
|
##### Vars/functions
|
9 |
|
|
|
10 |
|
|
# Make
|
11 |
3763
|
aaronmk
|
null :=
|
12 |
|
|
space := $(null) $(null)
|
13 |
5483
|
aaronmk
|
comma := ,
|
14 |
7046
|
aaronmk
|
and = $(if $(1),$(2))
|
15 |
|
|
or = $(1)$(2)
|
16 |
|
|
not = $(if $(1),,1)
|
17 |
3697
|
aaronmk
|
pathParts = $(shell path="$(1)"; echo "$${path%%/*}" "$${path\#*/}")
|
18 |
|
|
topDir = $(word 1,$(pathParts))
|
19 |
|
|
subPath = $(word 2,$(pathParts))
|
20 |
7081
|
aaronmk
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
|
21 |
3697
|
aaronmk
|
# input.Makefile path is relative to subdir
|
22 |
|
|
|
23 |
3763
|
aaronmk
|
# Formatting
|
24 |
5452
|
aaronmk
|
sed = sed -$(if $(filter Darwin,$(os)),E,r)
|
25 |
3763
|
aaronmk
|
_2Space = $(subst _,$(space),$(1))
|
26 |
|
|
*2Space = $(call _2Space,$*)
|
27 |
7385
|
aaronmk
|
ucase = $(shell echo "$(1)"|tr "[a-z]" "[A-Z]")
|
28 |
|
|
ci = $(1) $(ucase)
|
29 |
3763
|
aaronmk
|
|
30 |
3792
|
aaronmk
|
# Filesystem
|
31 |
5913
|
aaronmk
|
wildcard/ = $(shell bash -c 'shopt -s nullglob; echo $(1)')
|
32 |
4136
|
aaronmk
|
# needed because builtin $(wildcard) doesn't do / suffix correctly
|
33 |
4602
|
aaronmk
|
no/ = $(1:/=)# remove trailing /
|
34 |
4603
|
aaronmk
|
+w = $(wildcard $+)# existing items in $+
|
35 |
3794
|
aaronmk
|
CP := cp -p
|
36 |
|
|
cp = $(CP) $< $@
|
37 |
7381
|
aaronmk
|
mkdir = $(if $(wildcard $(1)),,mkdir -p $(1))
|
38 |
3792
|
aaronmk
|
|
39 |
6915
|
aaronmk
|
# File editing
|
40 |
|
|
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
|
41 |
|
|
|
42 |
5451
|
aaronmk
|
# System
|
43 |
5458
|
aaronmk
|
os := $(shell uname)
|
44 |
6965
|
aaronmk
|
isMac := $(filter Darwin,$(os))
|
45 |
5458
|
aaronmk
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
46 |
6966
|
aaronmk
|
dateFmt := %-Y-%-m-%-d %-H:%M:%S %Z
|
47 |
|
|
date = $(shell date +"$(dateFmt)")
|
48 |
6967
|
aaronmk
|
mtime = $(shell $(if $(isMac),stat -f %Sm -t "$(dateFmt)" $(1),date\
|
49 |
|
|
--reference=$(1) +"$(dateFmt)"))
|
50 |
5451
|
aaronmk
|
|
51 |
6915
|
aaronmk
|
# Terminal
|
52 |
|
|
esc := '['
|
53 |
|
|
reset := $(esc)'0m'
|
54 |
|
|
emph := $(esc)'7m '
|
55 |
|
|
endEmph := ' '$(reset)
|
56 |
|
|
|
57 |
|
|
# User interaction
|
58 |
|
|
|
59 |
|
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
60 |
|
|
|
61 |
|
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
62 |
|
|
|
63 |
6978
|
aaronmk
|
# Requires `SHELL := /bin/bash`
|
64 |
6915
|
aaronmk
|
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
|
65 |
|
|
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
|
66 |
|
|
$(error Aborting))
|
67 |
|
|
|
68 |
5460
|
aaronmk
|
## SVN
|
69 |
|
|
|
70 |
4222
|
aaronmk
|
addFile = $(if $(wildcard $(1)),,touch $(1) && )svn add $(1)
|
71 |
3697
|
aaronmk
|
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
|
72 |
5939
|
aaronmk
|
add* = $(if $(1),svn add --depth=empty $(1))
|
73 |
5460
|
aaronmk
|
|
74 |
|
|
# Revisions
|
75 |
5454
|
aaronmk
|
revision = $(shell svn info $(1)|$(sed) -n 's/^Last Changed Rev: (.*)$$/\1/p')
|
76 |
5455
|
aaronmk
|
rootRevision = $(call revision,$(root))
|
77 |
6927
|
aaronmk
|
version ?= r$(rootRevision)
|
78 |
3697
|
aaronmk
|
|
79 |
|
|
# rsync
|
80 |
7569
|
aaronmk
|
rsync* := "time" rsync$(if $(test), --dry-run) --archive --no-group --update \
|
81 |
|
|
--verbose --itemize-changes --progress
|
82 |
5808
|
aaronmk
|
rsync := $(rsync*) --exclude=".svn/" --exclude="*\#" --exclude=".DS_Store"
|
83 |
3697
|
aaronmk
|
local := ./
|
84 |
3700
|
aaronmk
|
localDirName := $(notdir $(realpath $(local)))
|
85 |
7558
|
aaronmk
|
remote := $(remote_user)@$(remote_host):$(remote_basepath)/$(localDirName)/
|
86 |
3697
|
aaronmk
|
|
87 |
6915
|
aaronmk
|
# DB
|
88 |
|
|
mkSchemaCmd = 'CREATE SCHEMA $(1);'
|
89 |
|
|
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
|
90 |
|
|
|
91 |
3697
|
aaronmk
|
##### General targets
|
92 |
|
|
|
93 |
3765
|
aaronmk
|
all: # must be first target in Makefile, so add an empty version here
|
94 |
3697
|
aaronmk
|
|
95 |
|
|
.SUFFIXES: # turn off built-in suffix rules
|
96 |
|
|
.SECONDARY: # don't automatically delete intermediate files
|
97 |
|
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
98 |
|
|
|
99 |
|
|
_always:
|
100 |
|
|
.PHONY: _always
|
101 |
3765
|
aaronmk
|
|
102 |
|
|
clean: # make sure `make clean` always works
|
103 |
6929
|
aaronmk
|
|
104 |
7076
|
aaronmk
|
# Run with `make -s` to avoid echoing make commands
|
105 |
6929
|
aaronmk
|
version: _always
|
106 |
|
|
echo $(version)
|
107 |
7559
|
aaronmk
|
|
108 |
|
|
##### Checksums
|
109 |
|
|
|
110 |
|
|
%.md5: %
|
111 |
|
|
nice -n +5 md5sum $<|cut -d ' ' -f 1 >$@
|
112 |
|
|
|
113 |
|
|
# Run with `make -s` to avoid echoing make commands
|
114 |
|
|
%.md5/test: %.md5 % _always
|
115 |
|
|
echo '$(shell cat $<) $*'|nice -n +5 md5sum -$(if $(isMac),v)c /dev/stdin
|