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
# input.Makefile path is relative to subdir
21

    
22
# Formatting
23
sed = sed -$(if $(filter Darwin,$(os)),E,r)
24
_2Space = $(subst _,$(space),$(1))
25
*2Space = $(call _2Space,$*)
26
ucase = $(shell echo "$(1)"|tr "[a-z]" "[A-Z]")
27
ci = $(1) $(ucase)
28

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

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

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

    
50
# Terminal
51
esc := '['
52
reset := $(esc)'0m'
53
emph := $(esc)'7m '
54
endEmph := ' '$(reset)
55

    
56
# User interaction
57

    
58
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
59

    
60
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
61

    
62
# Requires `SHELL := /bin/bash`
63
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
64
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
65
$(error Aborting))
66

    
67
## SVN
68

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

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

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

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

    
90
##### General targets
91

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

    
94
.SUFFIXES: # turn off built-in suffix rules
95
.SECONDARY: # don't automatically delete intermediate files
96
.DELETE_ON_ERROR: # delete target if recipe fails
97

    
98
_always:
99
.PHONY: _always
100

    
101
clean: # make sure `make clean` always works
102

    
103
# Run with `make -s` to avoid echoing make commands
104
version: _always
105
	echo $(version)
(9-9/47)