summaryrefslogtreecommitdiff
path: root/mbld/install.myr
blob: e2119ed39c12c5bd0e97cb435c7b7ed77abfe665 (plain)
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
use std

use "config"
use "opts"
use "types"
use "util"
use "build"

pkg bld =
	const install	: (p : build#	-> bool)
	const uninstall	: (p : build#	-> bool)
;;

const install = {b
	-> buildtarg(b, "all") && movetargs(b, false)
}

const uninstall = {b
	-> movetargs(b, true)
}

const movetargs = {b, rm
	var inst

	inst = std.htgetv(b.deps.targs, "all", [][:])
	for n : inst
		if n.instdir.len == 0
			continue
		;;
		for g : n.gen
			if !movefile(b, rm, g, n.instdir, n.instmod)
				-> false
			;;
		;;
	;;
	-> true

}

const movefile = {b, rm, file, prefix, perm
	var path, ok

	ok = true
	path = std.pathjoin([opt_destdir, opt_instbase, prefix, std.basename(file)][:])
	if rm
		mbldput("\trm {}\n", path)
		if !std.remove(path)
			mbldput("\t\tno such file {}\n", file)
		;;
	else
		std.remove(path)
		std.mkpath(std.dirname(path))
		match std.slurp(file)
		| `std.Err m:	std.fatal("could not open {} for reading\n", file)
		| `std.Ok buf:
			mbldput("\t{} => {}\n", file, path)
			if !std.blat(path, buf, perm)
				mbldput("could not write {}\n", file)
				ok = false
			;;
		;;
	;;
	std.slfree(path)
	-> ok
}