Skip to content

Commit

Permalink
Merge pull request #9 from jonludlam/configure
Browse files Browse the repository at this point in the history
Add configure script
  • Loading branch information
djs55 committed May 17, 2013
2 parents 42ff4ca + 056854d commit 1616f66
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
.PHONY: all clean install build
.PHONY: all clean install build reinstall uninstall distclean
all: build

NAME=xenops
J=4

BINDIR ?= /usr/bin
SBINDIR ?= /usr/sbin
LIBEXECDIR ?= /usr/lib/xcp/lib
SCRIPTSDIR ?= /usr/lib/xcp/scripts
ETCDIR ?= /etc
DESTDIR ?= /
clean:
@obuild clean
@rm -f setup.data setup.log setup.bin

distclean: clean
@rm -f config.mk

-include config.mk

export OCAMLRUNPARAM=b

Expand All @@ -20,14 +22,18 @@ XEN := --enable-xen
SIMULATOR := --enable-simulator

.PHONY: build
build: configure.done
build: dist/setup
obuild build

configure.done: xenopsd.obuild
dist/setup: xenopsd.obuild config.mk
obuild configure
touch configure.done

.PHONY: install
config.mk:
@echo
@echo "Please run configure before building"
@echo
@exit 1

install:
install -D ./dist/build/xenopsd_libvirt/xenopsd_libvirt $(DESTDIR)/$(SBINDIR)/xenopsd_libvirt
install -D ./dist/build/xenopsd_qemu/xenopsd_qemu $(DESTDIR)/$(SBINDIR)/xenopsd_qemu
Expand All @@ -40,7 +46,7 @@ install:
install -D ./scripts/setup-vif-rules $(DESTDIR)/$(LIBEXECDIR)/setup-vif-rules
install -D ./scripts/common.py $(DESTDIR)/$(LIBEXECDIR)/common.py
install -D ./scripts/network.conf $(DESTDIR)/$(ETCDIR)/xcp/network.conf
DESTDIR=$(DESTDIR) SBINDIR=$(SBINDIR) LIBEXECDIR=$(LIBEXECDIR) SCRIPTSDIR=$(SCRIPTSDIR) ./scripts/make-custom-xenopsd.conf
DESTDIR=$(DESTDIR) SBINDIR=$(SBINDIR) LIBEXECDIR=$(LIBEXECDIR) SCRIPTSDIR=$(SCRIPTSDIR) ETCDIR=$(ETCDIR) ./scripts/make-custom-xenopsd.conf

reinstall: install
@ocamlfind remove $(NAME) || true
Expand All @@ -58,6 +64,3 @@ uninstall:
rm -f $(DESTDIR)/$(LIBEXECDIR)/setup-vif-rules
rm -f $(DESTDIR)/$(ETCDIR)/xcp/network.conf

clean:
@obuild clean
@rm -f setup.data setup.log setup.bin
63 changes: 63 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env ocaml

#use "topfind"
#require "cmdliner"

let config_mk = "config.mk"

(* Configure script *)
open Cmdliner

let bindir =
let doc = "Set the directory for installing binaries" in
Arg.(value & opt string "/usr/bin" & info ["bindir"] ~docv:"BINDIR" ~doc)

let sbindir =
let doc = "Set the directory for installing superuser binaries" in
Arg.(value & opt string "/usr/sbin" & info ["sbindir"] ~docv:"SBINDIR" ~doc)

let libexecdir =
let doc = "Set the directory for installing helper executables" in
Arg.(value & opt string "/usr/lib/xenopsd/bin" & info ["libexecdir"] ~docv:"LIBEXECDIR" ~doc)

let scriptsdir =
let doc = "Set the directory for installing helper scripts" in
Arg.(value & opt string "/usr/lib/xenopsd/scripts" & info ["scriptsdir"] ~docv:"SCRIPTSDIR" ~doc)

let etcdir =
let doc = "Set the directory for installing configuration files" in
Arg.(value & opt string "/etc" & info ["etcdir"] ~docv:"ETCDIR" ~doc)

let info =
let doc = "Configures a package" in
Term.info "configure" ~version:"0.1" ~doc

let output_file filename lines =
let oc = open_out filename in
let lines = List.map (fun line -> line ^ "\n") lines in
List.iter (output_string oc) lines;
close_out oc

let configure bindir sbindir libexecdir scriptsdir etcdir =
Printf.printf "Configuring with:\n\tbindir=%s\n\tsbindir=%s\n\tlibexecdir=%s\n\tscriptsdir=%s\n\tetcdir=%s\n\n" bindir sbindir libexecdir scriptsdir etcdir;

(* Write config.mk *)
let lines =
[ "# Warning - this file is autogenerated by the configure script";
"# Do not edit";
Printf.sprintf "BINDIR=%s" bindir;
Printf.sprintf "SBINDIR=%s" sbindir;
Printf.sprintf "LIBEXECDIR=%s" libexecdir;
Printf.sprintf "SCRIPTSDIR=%s" scriptsdir;
Printf.sprintf "ETCDIR=%s" etcdir;
] in
output_file config_mk lines

let configure_t = Term.(pure configure $ bindir $ sbindir $ libexecdir $ scriptsdir $ etcdir )

let () =
match
Term.eval (configure_t, info)
with
| `Error _ -> exit 1
| _ -> exit 0

0 comments on commit 1616f66

Please sign in to comment.