Skip to content

Commit

Permalink
Use a Makefile to build libmirage-xen_bindings.a
Browse files Browse the repository at this point in the history
The C code in bindings/ *must* be built using exact C flags and linked
only statically. Until there is a way to do this in an OCaml + dune +
Mirage environment, we need to use Makefile here.
  • Loading branch information
mato committed Oct 14, 2020
1 parent 976fd36 commit b00b76b
Show file tree
Hide file tree
Showing 76 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(lang dune 2.0)
(lang dune 2.6)
(name mirage-xen)
18 changes: 18 additions & 0 deletions lib/bindings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PKG_CONFIG_PATH := $(shell opam config var prefix)/lib/pkgconfig

CC ?= cc
FREESTANDING_CFLAGS := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags ocaml-freestanding)
CFLAGS := $(FREESTANDING_CFLAGS) \
-O2 -std=c99 -Wall -Werror \
-Iinclude -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__

.PHONY: all clean
all: libmirage-xen_bindings.a

OBJS=alloc_pages_stubs.o atomic_stubs.o barrier_stubs.o bmap.o checksum_stubs.o clock_stubs.o cstruct_stubs.o evtchn.o gnttab.o main.o mm_stubs.o

libmirage-xen_bindings.a: $(OBJS)
$(AR) r $@ $^

clean:
$(RM) $(OBJS) libmirage-xen_bindings.a
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 11 additions & 12 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
(name oS)
(public_name mirage-xen)
(libraries lwt cstruct xenstore.client shared-memory-ring-lwt
mirage-profile logs io-page fmt mirage-runtime)
(foreign_archives mirage-xen_bindings))
mirage-profile logs io-page fmt mirage-runtime))

(foreign_library
(archive_name mirage-xen_bindings)
(language c)
(include_dirs ../include)
(names main bmap evtchn gnttab
alloc_pages_stubs atomic_stubs barrier_stubs checksum_stubs clock_stubs
cstruct_stubs mm_stubs)
(flags (:include cflags.sexp) -O2 -std=c99 -Wall -Werror
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__))
(rule
(deps (source_tree bindings))
(targets libmirage-xen_bindings.a)
(action
(no-infer
(progn
(chdir bindings (run make))
(copy bindings/libmirage-xen_bindings.a libmirage-xen_bindings.a)))))

(include_subdirs unqualified)

(rule (with-stdout-to cflags.sexp (run ./cflags.sh)))

(install
(section lib)
(files (bindings/mirage-xen.pc as ../pkgconfig/mirage-xen.pc)))
(files (bindings/mirage-xen.pc as ../pkgconfig/mirage-xen.pc)
(libmirage-xen_bindings.a as libmirage-xen_bindings.a)))

0 comments on commit b00b76b

Please sign in to comment.