You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.6 KiB

  1. /*
  2. * meli - build.rs
  3. *
  4. * Copyright 2020 Manos Pitsidianakis
  5. *
  6. * This file is part of meli.
  7. *
  8. * meli is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * meli is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with meli. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. extern crate proc_macro;
  22. extern crate quote;
  23. extern crate syn;
  24. mod config_macros;
  25. fn main() {
  26. println!("cargo:rerun-if-changed=build.rs");
  27. config_macros::override_derive(&[
  28. ("src/conf/pager.rs", "PagerSettings"),
  29. ("src/conf/listing.rs", "ListingSettings"),
  30. ("src/conf/notifications.rs", "NotificationsSettings"),
  31. ("src/conf/shortcuts.rs", "Shortcuts"),
  32. ("src/conf/composing.rs", "ComposingSettings"),
  33. ("src/conf/tags.rs", "TagsSettings"),
  34. ("src/conf/pgp.rs", "PGPSettings"),
  35. ]);
  36. #[cfg(feature = "cli-docs")]
  37. {
  38. use flate2::Compression;
  39. use flate2::GzBuilder;
  40. const MANDOC_OPTS: &[&str] = &["-T", "utf8", "-I", "os=Generated by mandoc(1)"];
  41. use std::env;
  42. use std::fs::File;
  43. use std::io::prelude::*;
  44. use std::path::Path;
  45. use std::process::Command;
  46. let out_dir = env::var("OUT_DIR").unwrap();
  47. let mut out_dir_path = Path::new(&out_dir).to_path_buf();
  48. let mut cl = |filepath: &str, output: &str| {
  49. out_dir_path.push(output);
  50. let output = Command::new("mandoc")
  51. .args(MANDOC_OPTS)
  52. .arg(filepath)
  53. .output()
  54. .or_else(|_| Command::new("man").arg("-l").arg(filepath).output())
  55. .unwrap();
  56. let file = File::create(&out_dir_path).unwrap();
  57. let mut gz = GzBuilder::new()
  58. .comment(output.stdout.len().to_string().into_bytes())
  59. .write(file, Compression::default());
  60. gz.write_all(&output.stdout).unwrap();
  61. gz.finish().unwrap();
  62. out_dir_path.pop();
  63. };
  64. cl("docs/meli.1", "meli.txt.gz");
  65. cl("docs/meli.conf.5", "meli.conf.txt.gz");
  66. cl("docs/meli-themes.5", "meli-themes.txt.gz");
  67. cl("docs/meli.7", "meli.7.txt.gz");
  68. }
  69. }