build into build dir with build script

This commit is contained in:
Konstantin Stepanov 2015-12-10 21:04:25 +03:00
parent 5dae359a1e
commit 76a9e3a5ca
3 changed files with 13 additions and 21 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
target/
build/
Makefile

View File

@ -45,7 +45,7 @@ persistent = $(if $(filter $(enable_persistent),yes),True,False)
all: $(builddir) $(outputs)
clean:
rm -rf $(outdir)
rm -rf $(outdir) $(builddir)
distprep: $(distdir)
cp -a configure $(distdir)
@ -53,7 +53,7 @@ distprep: $(distdir)
cp -a LICENSE $(distdir)
cp -a README.md $(distdir)
cp -a VERSION $(distdir)
cp -a src $(distdir)
cp -a src $(distdir)
dist: $(tarball)
@ -63,20 +63,7 @@ test: all
cargo test
build: all
cargo build --release
cp -a target/release/systemd-crontab-generator \
target/release/crontab \
target/release/remove-stale-stamps \
target/release/mail-on-failure \
target/release/boot-delay \
$(builddir)/bin/
cp -a target/release/build/systemd-crontab-generator-*/out/*.target \
target/release/build/systemd-crontab-generator-*/out/*.service \
target/release/build/systemd-crontab-generator-*/out/*.timer \
target/release/build/systemd-crontab-generator-*/out/*.path \
$(builddir)/units/
cp -a target/release/build/systemd-crontab-generator-*/out/*.[1578] \
$(builddir)/man/
cargo install --path . --root $(builddir)
install: build
install -m2755 -g `getent group cron || echo root` -s -D $(builddir)/bin/crontab $(DESTDIR)$(bindir)/crontab

View File

@ -3,7 +3,7 @@ extern crate rustc_serialize;
use std::env;
use std::path::Path;
use std::fs::{self, File};
use std::fs::{self, File, create_dir_all};
use std::io::{Read, Write};
use std::collections::BTreeMap;
@ -15,7 +15,11 @@ static MAN_DIR: &'static str = "man";
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let output = Path::new(&*out_dir);
let units_out_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let output = Path::new(&*units_out_dir).join("out").join("build");
create_dir_all(output.join("units")).unwrap();
create_dir_all(output.join("man")).unwrap();
let data = build_render_data();
@ -33,15 +37,15 @@ fn main() {
for schedule_unit in [ "target", "timer", "service" ].iter() {
compile_template(
format!("{}/cron-schedule.{}.in", UNITS_DIR, schedule_unit),
output.join(format!("cron-{}.{}", schedule, schedule_unit)),
output.join("units").join(format!("cron-{}.{}", schedule, schedule_unit)),
&data);
}
}
data.as_object_mut().unwrap().insert("schedules".to_owned(), schedules.to_json());
compile_templates(UNITS_DIR, output, &data);
compile_templates(MAN_DIR, output, &data);
compile_templates(UNITS_DIR, output.join("units"), &data);
compile_templates(MAN_DIR, output.join("man"), &data);
}
fn compile_template<S: AsRef<Path>, T: AsRef<Path>>(source_file: S, target_file: T, data: &Json) {