Project

General

Profile

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