-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefs.fish
73 lines (60 loc) · 1.67 KB
/
defs.fish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# ----------------------------------------------------------------------
# defs.fish: definitions common to all subdirectories
# ----------------------------------------------------------------------
# Users of this file should set LEVEL first
if not set -q LEVEL
set -gx LEVEL .
end
redo-ifchange $LEVEL/defs.fish
set -gx CC clang
set -gx CCFLAGS -std=c99
function redo-ifchange-d -d 'Redo if dependencies changed'
for arg in $argv
tr '\n' ' ' < $arg | read deps
set deps (echo $deps | sed -e 's/^.*: *//' -e 's/\\\\//g')
echo $deps
end | xargs redo-ifchange
end
function echoerr -d 'Echo args to stderr'
echo $argv 1>&2
end
function evald -d 'Eval with echo to stderr if DEBUG set'
if set -q DEBUG
echoerr $argv
end
eval $argv
end
function debug -d 'Turn build debugging on'
set -gx DEBUG 1
end
function nodebug -d 'Turn build debugging off'
set -e DEBUG
end
function doall -d 'Do command on all files matching regex'
if not test (count $argv) = 2
echo 'usage: doall command regex' 1>&2
return 1
end
set cmd $argv[1]
set regex $argv[2]
set line 'find . -name '\'$regex\'' -print0 | xargs -0 '$cmd
eval $line
end
function rm-tmp -d 'Remove temporary files'
doall rm '*~'
doall rm '*redo*tmp'
end
function rm-redo -d 'Remove redo database files'
doall 'rm -R' .redo
end
function make-exec -d 'Build an executable file'
set base (basename $argv[1])
set cfile src/$base.c
set dfile depend/$base.d
set ofile build/$base
set lib $LEVEL/lib
set include -Iinclude -I$lib/include
redo-ifchange $cfile $lib/build/libst.a
evald $CC -MD -MF $dfile $CCFLAGS $include -L$lib/build -lst $cfile -o $argv[3]
redo-ifchange-d $dfile
end