1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
srcdir := $(realpath $(dir $(THIS_MAKEFILE)))
BITSTRING ?= $(srcdir)/contrib/bitstring
BATTERIES ?= $(srcdir)/contrib/batteries-included/_build/src
UINT ?= $(srcdir)/contrib/ocaml-uint/_build/lib
export CAML_LD_LIBRARY_PATH := $(BITSTRING) $(CAML_LD_LIBRARY_PATH)
LEM ?= ~/bitbucket/lem/lem
LEMLIB ?= ~/bitbucket/lem/ocaml-lib/_build/
OCAMLFLAGS += -I $(LEMLIB) # FIXME
.PHONY: all sail test clean doc lib power test_power test_idempotence contrib install_elf
all: sail lib doc
full: all power test test
sail: sail.native sail_lib.cma sail_lib.cmxa
interpreter: _build/lem_interp/extract.cmxa _build/lem_interp/extract.cma
sail.native sail_lib.cma sail_lib.cmxa:
ocamlbuild sail.native sail_lib.cma sail_lib.cmxa
_build/lem_interp/extract.cmxa:
ocamlbuild lem_interp/extract.cmxa
_build/lem_interp/extract.cma:
ocamlbuild lem_interp/extract.cma
test: sail interpreter
ocamlbuild test/run_tests.native
./run_tests.native
contrib:
cd contrib && ./checkout.sh
install_elf:
cp -p ../../system-v-abi/src/*.lem elf_model/
cp -p ../../system-v-abi/src/*.ml elf_model/
%.ml: %.lem
$(LEM) -outdir $$(dirname "$<") -ocaml -only_changed_output "$<"
# HACK: special case for bitstring_local
elf_model/bitstring_local.ml: elf_model/bitstring.lem
$(LEM) -outdir $$(dirname "$<") -ocaml -only_changed_output "$<"
# HACK: why doesn't ocamldep know this one?
elf_model/show.cmx: elf_model/missing_pervasives.cmx
ELF_LEM_SRC := $(addprefix elf_model/,missing_pervasives.lem show.lem endianness.lem bitstring.lem elf_types.lem elf_interpreted_segment.lem elf_header.lem elf_file1.lem elf_program_header_table.lem elf_executable_file2.lem elf_section_header_table.lem elf_executable_file3.lem string_table.lem elf_executable_file4.lem elf_executable_file5.lem sail_interface.lem main.lem)
vpath _build/%.lem .
vpath _build/%.cmx .
CAMLP4FLAGS += -nolib
CAMLP4FLAGS += -I $(BITSTRING)
CAMLP4FLAGS += -parser o -parser op -printer p
CAMLP4FLAGS += unix.cma
CAMLP4FLAGS += bitstring.cma
CAMLP4FLAGS += bitstring_persistent.cma
CAMLP4FLAGS += pa_bitstring.cmo
# HACK: rewrite for bitstring_local
ELF_ML_LEM := $(filter-out elf_model/bitstring.ml,$(patsubst %.lem,%.ml,$(ELF_LEM_SRC))) elf_model/bitstring_local.ml
ELF_ML_SRC := $(addprefix elf_model/,error.ml ml_bindings.ml)
ELF_ML := $(ELF_ML_SRC) $(ELF_ML_LEM)
ELF_ML_DEPS := $(patsubst %.ml,%.d,$(ELF_ML))
ELF_CMX := $(patsubst %.ml,%.cmx,$(ELF_ML))
$(ELF_CMX): OCAMLFLAGS += \
-I $(BITSTRING) -pp 'env CAML_LD_LIBRARY_PATH=$(BITSTRING) camlp4o $(CAMLP4FLAGS)' \
-I $(BATTERIES) \
-I $(UINT) \
-I elf_model
$(ELF_ML_DEPS): OCAMLFLAGS += \
-I $(BITSTRING) -pp 'env CAML_LD_LIBRARY_PATH=$(BITSTRING) camlp4o $(CAMLP4FLAGS)' \
-I $(BATTERIES) \
-I $(UINT) \
-I $(srcdir)/elf_model
$(ELF_ML_DEPS): %.d: %.ml
ocamldep -native $(OCAMLFLAGS) "$<" > "$@" || (rm -f "$@"; false)
ifneq ($(MAKECMDGOALS),clean)
-include $(ELF_ML_DEPS)
endif
elf_extract.cmxa: OCAMLFLAGS += \
-I $(BITSTRING) -package bitstring,bitstring.syntax -syntax bitstring \
-I $(BATTERIES) -package batteries \
-I $(UINT) -package bitstring \
-pp 'camlp4 $(CAMLP4FLAGS)' \
-I $(LEMLIB)/../ocaml-lib/_build
LEM_CMX := $(addprefix $(LEMLIB)/../ocaml-lib/,nat_num.cmx lem.cmx lem_function.cmx lem_list.cmx)
%.cmx: %.ml
echo CAML_LD_LIBRARY_PATH is $$CAML_LD_LIBRARY_PATH
ocamlopt $(OCAMLFLAGS) -c "$<"
elf_model/elf_extract.cmxa: $(ELF_CMX)
ocamlopt $(OCAMLFLAGS) -a -o "$@" $+
elf: $(ELF_CMX) $(LEM_CMX) elf_model/elf_extract.cmxa
_build/test/power.lem: sail.native test/power.sail
mkdir -p _build/test
cp -p test/* _build/test/
cd _build/test && \
../../sail.native -lem_ast power.sail
pprint/src/_build/PPrintLib.cmxa:
$(MAKE) -C $(srcdir)/pprint/src
_build/test/run_power.native: OCAMLFLAGS += \
-I $(LEMLIB) \
-I $(srcdir)/_build/lem_interp/ \
-I $(srcdir)/elf_model/ \
-I $(UINT)
_build/test/run_power.native: OCAMLLIBS += \
$(LEMLIB)/extract.cmxa
_build/test/power.ml: _build/test/power.lem
cd _build/test && $(LEM) -ocaml -only_changed_output -lib $(srcdir)/lem_interp/ power.lem
touch "$@" # HACK HACK HACK! why didn't lem update the timestamp?
_build/test/run_power.native: pprint/src/_build/PPrintLib.cmxa _build/lem_interp/extract.cmxa elf_model/elf_extract.cmxa _build/test/power.ml test/run_power.ml
cd _build/test && \
ocamlopt $(OCAMLFLAGS) $(OCAMLLIBS) $(addprefix $(srcdir)/,$+) -o run_power.native
power: run_power.native
run_power.native: _build/test/run_power.native
ln -fs _build/test/run_power.native run_power.native
test_power: power
./run_power.native --file ../../../rsem/idl/power/binary/main.bin
test_power_interactive: power
./run_power.native --interactive --file ../../../rsem/idl/power/binary/main.bin
test_power_interactive_srcs:
ebig ~/rsem/idl/power/generated/power.sail ../../../rsem/idl/power/binary/hello.c ../../../rsem/idl/power/binary/hello.s
# or test/power.sail for cut-down one
test_idempotence: sail
@cd test; for file in *.sail; do \
./idempotence.sh $$file; echo ;\
done
clean:
#-ocamlbuild -clean
-rm -rf _build *.native
-rm -rf $(srcdir)/elf_model/*.o $(srcdir)/elf_model/*.cmx $(srcdir)/elf_model/*.cmi $(ELF_ML_LEM) $(ELF_ML_DEPS)
-rm -rf html-doc
-rm -rf tex-doc
-rm -rf lem lib
-rm -rf sail.docdir
doc:
ocamlbuild sail.docdir/index.html
lib:
ocamlbuild pretty_print.cmxa pretty_print.cma
|