forked from mirage/ocaml-solo5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (78 loc) · 3.17 KB
/
Makefile
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
.PHONY: all clean install uninstall distclean
include Makeconf
FREESTANDING_LIBS=openlibm/libopenlibm.a \
ocaml/runtime/libasmrun.a \
nolibc/libnolibc.a
all: $(FREESTANDING_LIBS) ocaml-freestanding.pc
Makeconf:
./configure.sh
TOP=$(abspath .)
FREESTANDING_CFLAGS+=-I$(TOP)/nolibc/include -include _freestanding/overrides.h
FREESTANDING_LDFLAGS+=
openlibm/libopenlibm.a:
$(MAKE) -C openlibm "CFLAGS=$(FREESTANDING_CFLAGS)" libopenlibm.a
ocaml/Makefile:
cp -r `ocamlfind query ocaml-src` ./ocaml
# OCaml >= 4.08.0 uses an autotools-based build system. In this case we
# convince it to think it's using the Solo5 compiler as a cross compiler, and
# let the build system do its work with as little additional changes on our
# side as possible.
#
# Notes:
#
# - CPPFLAGS must be set for configure as well as CC, otherwise it complains
# about headers due to differences of opinion between the preprocessor and
# compiler.
# - ARCH must be overridden manually in Makefile.config due to the use of
# hardcoded combinations in the OCaml configure.
# - HAS_XXX must be defined manually since our invocation of configure cannot
# link against nolibc (which would need to produce complete Solo5 binaries).
# - We override OCAML_OS_TYPE since configure just hardcodes it to "Unix".
OCAML_CFLAGS=$(FREESTANDING_CFLAGS) -I$(TOP)/openlibm/include -I$(TOP)/openlibm/src
OCAML_LDFLAGS=$(FREESTANDING_LDFLAGS) -L$(TOP)/openlibm/
ocaml/Makefile.config: ocaml/Makefile
cd ocaml && \
CC="cc $(OCAML_CFLAGS) -nostdlib" \
LDFLAGS="$(OCAML_LDFLAGS)" \
LIBS="-lopenlibm" \
AS="as" \
ASPP="cc $(OCAML_CFLAGS) -c" \
LD="ld" \
CPPFLAGS="$(OCAML_CFLAGS)" \
./configure --host=$(BUILD_ARCH)-unknown-none
echo "ARCH=$(OCAML_BUILD_ARCH)" >> ocaml/Makefile.config
echo 'SAK_CC=cc' >> ocaml/Makefile.config
echo 'SAK_CFLAGS=$(OC_CFLAGS) $(OC_CPPFLAGS)' >> ocaml/Makefile.config
echo 'SAK_LINK=$(SAK_CC) $(SAK_CFLAGS) $(OUTPUTEXE)$(1) $(2)' >> ocaml/Makefile.config
echo '#define HAS_GETTIMEOFDAY' >> ocaml/runtime/caml/s.h
echo '#define HAS_SECURE_GETENV' >> ocaml/runtime/caml/s.h
echo '#define HAS_TIMES' >> ocaml/runtime/caml/s.h
echo '#undef OCAML_OS_TYPE' >> ocaml/runtime/caml/s.h
echo '#define OCAML_OS_TYPE "None"' >> ocaml/runtime/caml/s.h
ocaml/runtime/caml/version.h: ocaml/Makefile.config
ocaml/tools/make-version-header.sh > $@
ocaml/runtime/libasmrun.a: ocaml/Makefile.config ocaml/runtime/caml/version.h
$(MAKE) -C ocaml/runtime libasmrun.a
NOLIBC_CFLAGS=$(FREESTANDING_CFLAGS) -I$(TOP)/openlibm/src -I$(TOP)/openlibm/include
nolibc/libnolibc.a:
$(MAKE) -C nolibc \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)" \
"SYSDEP_OBJS=$(NOLIBC_SYSDEP_OBJS)"
ocaml-freestanding.pc: ocaml-freestanding.pc.in Makeconf
sed -e 's!@@PKG_CONFIG_DEPS@@!$(PKG_CONFIG_DEPS)!' \
-e 's!@@PKG_CONFIG_EXTRA_LIBS@@!$(PKG_CONFIG_EXTRA_LIBS)!' \
ocaml-freestanding.pc.in > $@
install: all
./install.sh
uninstall:
./uninstall.sh
clean:
-$(MAKE) -C ocaml/runtime clean
$(MAKE) -C openlibm clean
$(MAKE) -C nolibc \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)" \
"SYSDEP_OBJS=$(NOLIBC_SYSDEP_OBJS)" \
clean
$(RM) Makeconf ocaml-freestanding.pc
distclean: clean
$(RM) -r ocaml/