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