Project

General

Profile

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
and = $(if $(1),$(2))
14
or = $(1)$(2)
15
not = $(if $(1),,1)
16
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
# Formatting
24
sed = sed -$(if $(filter Darwin,$(os)),E,r)
25
_2Space = $(subst _,$(space),$(1))
26
*2Space = $(call _2Space,$*)
27

    
28
# Filesystem
29
wildcard/ = $(shell bash -c 'shopt -s nullglob; echo $(1)')
30
    # needed because builtin $(wildcard) doesn't do / suffix correctly
31
no/ = $(1:/=)# remove trailing /
32
+w = $(wildcard $+)# existing items in $+
33
CP := cp -p
34
cp = $(CP) $< $@
35

    
36
# File editing
37
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
38

    
39
# System
40
os := $(shell uname)
41
isMac := $(filter Darwin,$(os))
42
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
43
dateFmt := %-Y-%-m-%-d %-H:%M:%S %Z
44
date = $(shell date +"$(dateFmt)")
45
mtime = $(shell $(if $(isMac),stat -f %Sm -t "$(dateFmt)" $(1),date\
46
--reference=$(1) +"$(dateFmt)"))
47

    
48
# 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
# Requires `SHELL := /bin/bash`
61
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
## SVN
66

    
67
addFile = $(if $(wildcard $(1)),,touch $(1) && )svn add $(1)
68
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
69
add* = $(if $(1),svn add --depth=empty $(1))
70

    
71
# Revisions
72
revision = $(shell svn info $(1)|$(sed) -n 's/^Last Changed Rev: (.*)$$/\1/p')
73
rootRevision = $(call revision,$(root))
74
version ?= r$(rootRevision)
75

    
76
# rsync
77
rsync* := "time" rsync$(if $(test), --dry-run) --archive --update --verbose\
78
--itemize-changes --progress
79
rsync := $(rsync*) --exclude=".svn/" --exclude="*\#" --exclude=".DS_Store"
80
local := ./
81
localDirName := $(notdir $(realpath $(local)))
82
remote := $(src_user)@$(src_server):/home/bien/svn/$(localDirName)/
83

    
84
# DB
85
mkSchemaCmd = 'CREATE SCHEMA $(1);'
86
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
87

    
88
##### General targets
89

    
90
all: # must be first target in Makefile, so add an empty version here
91

    
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

    
99
clean: # make sure `make clean` always works
100

    
101
# Usage: `make {--silent|-s} version` (don't echo make commands)
102
version: _always
103
	echo $(version)
(9-9/47)