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

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

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

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

    
47
# 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
# Requires `SHELL := /bin/bash`
60
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
## SVN
65

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

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

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

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

    
87
##### General targets
88

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

    
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

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

    
100
# Run with `make -s` to avoid echoing make commands
101
version: _always
102
	echo $(version)
(9-9/47)