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
pathParts = $(shell path="$(1)"; echo "$${path%%/*}" "$${path\#*/}")
14
topDir = $(word 1,$(pathParts))
15
subPath = $(word 2,$(pathParts))
16
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@) \
17
--makefile=../input.Makefile
18
# input.Makefile path is relative to subdir
19

    
20
# Formatting
21
sed = sed -$(if $(filter Darwin,$(os)),E,r)
22
_2Space = $(subst _,$(space),$(1))
23
*2Space = $(call _2Space,$*)
24

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

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

    
36
# System
37
os := $(shell uname)
38
isMac := $(filter Darwin,$(os))
39
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
40
date = $(shell date +"%-Y-%-m-%-d %-H:%M:%S %Z")
41

    
42
# Terminal
43
esc := '['
44
reset := $(esc)'0m'
45
emph := $(esc)'7m '
46
endEmph := ' '$(reset)
47

    
48
# User interaction
49

    
50
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
51

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

    
54
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
55
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
56
$(error Aborting))
57

    
58
## SVN
59

    
60
addFile = $(if $(wildcard $(1)),,touch $(1) && )svn add $(1)
61
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
62
add* = $(if $(1),svn add --depth=empty $(1))
63

    
64
# Revisions
65
revision = $(shell svn info $(1)|$(sed) -n 's/^Last Changed Rev: (.*)$$/\1/p')
66
rootRevision = $(call revision,$(root))
67
version ?= r$(rootRevision)
68

    
69
# rsync
70
rsync* := "time" rsync$(if $(test), --dry-run) --archive --update --verbose\
71
--itemize-changes --progress
72
rsync := $(rsync*) --exclude=".svn/" --exclude="*\#" --exclude=".DS_Store"
73
local := ./
74
localDirName := $(notdir $(realpath $(local)))
75
remote := $(src_user)@$(src_server):/home/bien/svn/$(localDirName)/
76

    
77
# DB
78
mkSchemaCmd = 'CREATE SCHEMA $(1);'
79
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
80

    
81
##### General targets
82

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

    
85
.SUFFIXES: # turn off built-in suffix rules
86
.SECONDARY: # don't automatically delete intermediate files
87
.DELETE_ON_ERROR: # delete target if recipe fails
88

    
89
_always:
90
.PHONY: _always
91

    
92
clean: # make sure `make clean` always works
93

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