ref: 9f9d134454de4f796e3e7338a2c59e0ee59a3560
dir: /install.myr/
use std use "config.use" use "deps.use" use "opts.use" use "parse.use" use "subdir.use" use "types.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 [.name=bin, .inputs=leaves, .install=true]: movefile(delete, bin, opt_instroot, opt_destdir, "bin") | `Lib [.name=lib, .inputs=leaves, .install=true]: 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: subdirs(p, subs, `std.None) | `Man mans: /* FIXME: figure out man section by number */ for m in mans moveman(delete, m) ;; ;; ;; -> 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\n", file) | `std.Ok buf: if !std.blat(path, buf) std.put("Could not write %s\n", file) ;; std.slfree(buf) ;; ;; std.slfree(path) } const moveman = {delete, man var sect, manrel match std.strrfind(man, ".") | `std.None: std.fatal(1, "manpage %s has no section\n", man) | `std.Some s: sect = s + 1 if s + 1 == man.len std.fatal(1, "manpage %s missing suffix\n", man) ;; ;; manrel = std.fmt("share/man/man%s", man[sect:]) movefile(delete, man, opt_instroot, opt_destdir, manrel) std.slfree(manrel) }