ref: 3d69958a6f62b635c39a6cd958bcbf8877fe6e8f
parent: 722f307b48dabe6984334c0b40e995fdead9baf2
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 23 13:39:05 EDT 2014
Add support for 'install'/'uninstall.
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@
clean.myr \
config.myr \
deps.myr \
+ install.myr \
main.myr \
opts.myr \
parse.myr \
--- a/bldfile
+++ b/bldfile
@@ -1,2 +1,12 @@
# comment
-bin mbld2 = main.myr build.myr parse.myr deps.myr config.myr opts.myr util.myr clean.myr; # comment
+bin mbld2 =
+ build.myr
+ clean.myr
+ config.myr
+ deps.myr
+ install.myr
+ main.myr
+ opts.myr
+ parse.myr
+ util.myr
+; # comment
--- a/build.myr
+++ b/build.myr
@@ -8,8 +8,6 @@
pkg bld =
const buildall : (p : parser# -> bool)
- const install : (p : parser# -> bool)
- const uninstall : (p : parser# -> bool)
const test : (p : parser# -> bool)
const build : (p : parser#, target : byte[:] -> bool)
const buildbin : (bin : byte[:], inputs : byte[:][:] -> void)
@@ -32,16 +30,6 @@
;;
;;
-> true
-}
-
-const install = {p
- std.fatal(1, "installing not yet supported\n")
- -> false
-}
-
-const uninstall = {p
- std.fatal(1, "uninstalling not yet supported\n")
- -> false
}
const test = {p
--- /dev/null
+++ b/install.myr
@@ -1,0 +1,71 @@
+use std
+
+use "config.use"
+use "deps.use"
+use "opts.use"
+use "parse.use"
+use "util.use"
+
+pkg bld =
+ const install : (p : parser# -> bool)
+ const uninstall : (p : parser# -> bool)
+;;
+
+const install = {p
+ -> movetargs(p, false)
+}
+
+const uninstall = {p
+ -> movetargs(p, true)
+}
+
+const movetargs = {p, delete
+ var libarchive
+
+ for t in p.targs
+ match t
+ | `Bin (bin, leaves):
+ movefile(delete, bin, opt_instroot, opt_destdir, "bin")
+ | `Lib (lib, leaves):
+ movefile(delete, lib, opt_instroot, opt_destdir, "lib/myr")
+ libarchive = std.fmt("lib%s.a", lib)
+ movefile(delete, libarchive, opt_instroot, opt_destdir, "lib/myr")
+ std.slfree(libarchive)
+ | `Sub subs:
+ /*
+ for s in subs
+ dosub(s)
+ ;;
+ */
+ | `Man mans:
+ /* FIXME: figure out man section by number */
+ for m in mans
+ movefile(delete, m, opt_instroot, opt_destdir, "share/man1")
+ ;;
+ ;;
+ ;;
+ -> true
+}
+
+
+const movefile = {delete, file, instdir, destdir, prefix
+ var path
+
+ path = std.pathjoin([destdir, instdir, prefix, file][:])
+ if delete
+ std.put("\t%s deleted\n", path)
+ if (std.unlink(path) < 0)
+ std.put("\t\tno such file %s\n", file)
+ ;;
+ else
+ std.put("\t%s => %s\n", file, path)
+ std.unlink(path)
+ match std.slurp(file)
+ | `std.Fail m: std.fatal(1, "Could not open %s for reading", file)
+ | `std.Ok buf:
+ std.blat(path, buf)
+ std.slfree(buf)
+ ;;
+ ;;
+ std.slfree(path)
+}
--- a/main.myr
+++ b/main.myr
@@ -1,10 +1,11 @@
use std
-use "parse.use"
use "build.use"
use "clean.use"
-use "opts.use"
use "config.use"
+use "install.use"
+use "opts.use"
+use "parse.use"
const main = {args : byte[:][:]
var p : bld.parser#