diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-02-09 02:26:21 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-02-09 02:26:21 +0200 |
commit | 0aa2659072280dea2d501c2aa0505329d9383d13 (patch) | |
tree | 4e74d25b985cc4b7112a0c4398c2b2fdc13055fa /build.rs | |
parent | c22a141b140528e72b19b2058285e8243e56151e (diff) |
meli: add cli-docs feature
Optionally build manpages to text with mandoc and print them from the
command line.
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..03465d76 --- /dev/null +++ b/build.rs @@ -0,0 +1,66 @@ +/* + * meli - build.rs + * + * Copyright 2020 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + +fn main() { + #[cfg(feature = "cli-docs")] + { + const MANDOC_OPTS: &[&'static str] = &["-T", "utf8", "-I", "os=Generated by mandoc(1)"]; + use std::env; + use std::fs::File; + use std::io::prelude::*; + use std::path::Path; + use std::process::Command; + let out_dir = env::var("OUT_DIR").unwrap(); + let mut out_dir_path = Path::new(&out_dir).to_path_buf(); + + // Note that there are a number of downsides to this approach, the comments + // below detail how to improve the portability of these commands. + let output = Command::new("mandoc") + .args(MANDOC_OPTS) + .arg("meli.1") + .output() + .unwrap(); + + out_dir_path.push("meli.txt"); + let mut file = File::create(&out_dir_path).unwrap(); + file.write_all(&output.stdout).unwrap(); + out_dir_path.pop(); + + out_dir_path.push("meli.conf.txt"); + let output = Command::new("mandoc") + .args(MANDOC_OPTS) + .arg("meli.conf.5") + .output() + .unwrap(); + let mut file = File::create(&out_dir_path).unwrap(); + file.write_all(&output.stdout).unwrap(); + out_dir_path.pop(); + + out_dir_path.push("meli-themes.txt"); + let output = Command::new("mandoc") + .args(MANDOC_OPTS) + .arg("meli-themes.5") + .output() + .unwrap(); + let mut file = File::create(&out_dir_path).unwrap(); + file.write_all(&output.stdout).unwrap(); + } +} |