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 7081 aaronmk
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
20 3697 aaronmk
# input.Makefile path is relative to subdir
21
22 3763 aaronmk
# Formatting
23 5452 aaronmk
sed = sed -$(if $(filter Darwin,$(os)),E,r)
24 3763 aaronmk
_2Space = $(subst _,$(space),$(1))
25
*2Space = $(call _2Space,$*)
26 7385 aaronmk
ucase = $(shell echo "$(1)"|tr "[a-z]" "[A-Z]")
27
ci = $(1) $(ucase)
28 3763 aaronmk
29 3792 aaronmk
# Filesystem
30 5913 aaronmk
wildcard/ = $(shell bash -c 'shopt -s nullglob; echo $(1)')
31 4136 aaronmk
    # needed because builtin $(wildcard) doesn't do / suffix correctly
32 4602 aaronmk
no/ = $(1:/=)# remove trailing /
33 4603 aaronmk
+w = $(wildcard $+)# existing items in $+
34 3794 aaronmk
CP := cp -p
35
cp = $(CP) $< $@
36 7381 aaronmk
mkdir = $(if $(wildcard $(1)),,mkdir -p $(1))
37 3792 aaronmk
38 6915 aaronmk
# File editing
39
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
40
41 5451 aaronmk
# System
42 5458 aaronmk
os := $(shell uname)
43 6965 aaronmk
isMac := $(filter Darwin,$(os))
44 5458 aaronmk
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
45 6966 aaronmk
dateFmt := %-Y-%-m-%-d %-H:%M:%S %Z
46
date = $(shell date +"$(dateFmt)")
47 6967 aaronmk
mtime = $(shell $(if $(isMac),stat -f %Sm -t "$(dateFmt)" $(1),date\
48
--reference=$(1) +"$(dateFmt)"))
49 5451 aaronmk
50 6915 aaronmk
# 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 6978 aaronmk
# Requires `SHELL := /bin/bash`
63 6915 aaronmk
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 5460 aaronmk
## SVN
68
69 4222 aaronmk
addFile = $(if $(wildcard $(1)),,touch $(1) && )svn add $(1)
70 3697 aaronmk
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
71 5939 aaronmk
add* = $(if $(1),svn add --depth=empty $(1))
72 5460 aaronmk
73
# Revisions
74 5454 aaronmk
revision = $(shell svn info $(1)|$(sed) -n 's/^Last Changed Rev: (.*)$$/\1/p')
75 5455 aaronmk
rootRevision = $(call revision,$(root))
76 6927 aaronmk
version ?= r$(rootRevision)
77 3697 aaronmk
78
# rsync
79 5084 aaronmk
rsync* := "time" rsync$(if $(test), --dry-run) --archive --update --verbose\
80
--itemize-changes --progress
81 5808 aaronmk
rsync := $(rsync*) --exclude=".svn/" --exclude="*\#" --exclude=".DS_Store"
82 3697 aaronmk
local := ./
83 3700 aaronmk
localDirName := $(notdir $(realpath $(local)))
84
remote := $(src_user)@$(src_server):/home/bien/svn/$(localDirName)/
85 3697 aaronmk
86 6915 aaronmk
# DB
87
mkSchemaCmd = 'CREATE SCHEMA $(1);'
88
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
89
90 3697 aaronmk
##### General targets
91
92 3765 aaronmk
all: # must be first target in Makefile, so add an empty version here
93 3697 aaronmk
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 3765 aaronmk
101
clean: # make sure `make clean` always works
102 6929 aaronmk
103 7076 aaronmk
# Run with `make -s` to avoid echoing make commands
104 6929 aaronmk
version: _always
105
	echo $(version)