1#
2# Copyright 2017, Data61
3# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4# ABN 41 687 119 230.
5# This software may be distributed and modified according to the terms of
6# the BSD 2-Clause license. Note that NO WARRANTY is provided.
7# See "LICENSE_BSD2.txt" for details.
8# @TAG(DATA61_BSD)
9#
10#
11include ../../global.mk
12include ${BUILDRUMP_TOOLFLAGS}
13
14default: all
15
16# Check if we're building for a supported target.
17supported= false
18MACHINE?= i386
19ifeq (${MACHINE},i386)
20SEL4_MACHINE_ARCH=i386
21supported:= true
22endif
23ifeq (${MACHINE},amd64)
24supported:= true
25endif
26ifeq (${MACHINE},evbarm)
27ARCHDIR=arm
28supported:= true
29endif
30ifneq (${supported},true)
31$(error only supported target is x86, you have ${MACHINE})
32endif
33
34ARCHDIR?= ${MACHINE}
35SEL4_MACHINE_ARCH?= ${MACHINE_GNU_ARCH}
36
37
38LDSCRIPT:=	$(abspath stage2.lds)
39SRCS+=		entry.c undefs.c kernel.c intr.c simple.c cons.c clock.c
40
41INSTALLTGTS+=	librumpsel4_stdio_install
42
43include ../Makefile.inc
44include arch/${ARCHDIR}/Makefile.inc
45
46# Add seL4 header files locations
47CFLAGS+= $(CFLAGS_SEL4)
48
49OBJS:=	$(patsubst %.c,${RROBJ}/platform/%.o,${SRCS}) \
50	$(patsubst %.S,${RROBJ}/platform/%.o,${ASMS})
51
52.PHONY:	clean cleandir all platform_obj platform_libs extra_libs
53
54all: links userlibs_no_librumprunfs_base platform_obj platform_libs extra_libs
55
56platform_obj: ${MAINOBJ}
57
58platform_libs: ${RROBJLIB}/librumprunfs_base/librumprunfs_base.a rumpkernlibs compiler_rt
59
60$(eval $(call BUILDLIB_target,librumpsel4_stdio,.))
61
62extra_libs: ${RROBJLIB}/librumpsel4_stdio/librumpsel4_stdio.a
63
64
65# These are required to provide hardware info to rumprun/libs/*
66${RROBJ}/include/sel4/machine:
67	@mkdir -p ${RROBJ}/include/sel4
68	@ln -sf $(shell pwd)/include/arch/${SEL4_MACHINE_ARCH} $@
69
70${RROBJ}/include/bmk-pcpu:
71	@ln -sf ${RROBJ}/include/sel4/machine $@
72
73links: ${RROBJ}/include/sel4/machine ${RROBJ}/include/bmk-pcpu
74
75${RROBJ}/platform/%.o: %.c ${RROBJ}/platform/archdirs.stamp
76	$(Q)$(call make-depend,$<,$@,$(patsubst %.o,%.d,$@))
77	${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@
78
79# Base directory of rumprun.  Will always be two directories higher than this.
80# This variable is used in rumprunlibs.mk
81RUMPRUN_BASE_DIR:= ../../
82include rumprunlibs.mk
83
84ifneq ($(abspath $(MAINOBJ)),$(abspath $(BASEFILE)))
85$(error $(BASEFILE) does not equal $(MAINOBJ). ${PWD})
86endif
87
88
89${INTERMEDIATE_BASEFILE}: ${OBJS}
90	echo "  [Building intermediate basefile]"
91	${CC} -nostdlib ${CFLAGS} ${OBJS} -o $@ $(LDFLAGS-y) -Wl,-r
92
93MAINOBJ_LD_FLAGS := $(LDFLAGS_SEL4) $(BASEFILE_LD_FLAGS)
94
95.PHONY: ${MAINOBJ}
96# Look away now
97${MAINOBJ}: ${INTERMEDIATE_BASEFILE} ${RROBJ}/platform/main.o platformlibs
98	echo "  [Building final basefile]"
99	# Generate the rumprun.o object file that is linked against apps that want to use rumprun.
100	# --whole-archive is used to ensure constructor symbols are included from some libraries
101	# --start-group because seL4 libraries have circular dependencies
102	${CC} -nostdlib ${CFLAGS} ${CRTOBJFILES_SEL4} ${RROBJ}/platform/main.o ${INTERMEDIATE_BASEFILE} ${FINOBJFILES_SEL4} -o $@ ${MAINOBJ_LD_FLAGS}
103	# Objcopy is used to promote all -G symbols to global symbols while hiding all other symbols.
104	${BASEFILE_OBJCOPY} $@
105
106clean: commonclean
107	rm -f ${OBJS_BMK} include/sel4/machine buildtest ${MAINOBJ}
108
109cleandir: clean
110
111
112DEPS = $(patsubst %.c,${RROBJ}/platform/%.d,$(SRCS)) $(patsubst %.cxx,${RROBJ}/platform/%.d,$(CXXFILES)) $(patsubst %.S,${RROBJ}/platform/%.d,$(ASMFILES))
113
114ifneq "$(MAKECMDGOALS)" "clean"
115  -include ${DEPS}
116endif
117
118# $(call make-depend,source-file,object-file,depend-file)
119define make-depend
120  ${CC} -MM            \
121         -MF $3         \
122         -MP            \
123         -MT $2         \
124         $(CFLAGS)      \
125         $(CPPFLAGS)    \
126         $1
127endef
128define make-cxx-depend
129  ${CXX} -MM            \
130         -MF $3         \
131         -MP            \
132         -MT $2         \
133         $(CXXFLAGS)    \
134         $(CPPFLAGS)    \
135         $1
136endef
137