xref: /minix/minix/lib/libmagicrt/Makefile (revision d2532d3d)
1# Makefile for libmagicrt
2#
3# The magic runtime library is the runtime state transfer component for live
4# update.  It is not a regular library.  First of all, it is only built when
5# MKMAGIC is enabled, which also implies that we are building bitcode.
6# Second, the produced file is a single bitcode object containing basically the
7# concatenation of the individual bitcode objects produced from the source
8# files.  The final bitcode object is used to link against system services
9# during the rest of the compilation process.  It is installed only because
10# this makes it easier to refer to it during the rest of the compilation
11# process.  However, both the library's generation and its installation cannot
12# be done with regular bsd.lib.mk rules, which is why this Makefile is rather
13# nonstandard.
14
15.include <bsd.own.mk>
16
17LIBNAME=	libmagicrt.bcc
18
19SRCS=		magic.c magic_analysis.c magic_asr.c magic_ds.c
20SRCS+=		magic_eval.c magic_eval_lib.c magic_mem.c magic_range.c
21SRCS+=		magic_selement.c magic_sentry.c magic_splay_tree.c
22SRCS+=		magic_st.c magic_util.c
23
24OBJS=		${SRCS:.c=.bc}
25
26CPPFLAGS+=	-D__MINIX -D_MINIX_SYSTEM -D_SYSTEM
27CPPFLAGS+=	-I${.CURDIR}/include
28CPPFLAGS+=	-I${NETBSDSRCDIR}/minix/llvm/include # for magic_common.h
29CPPFLAGS.magic_ds.c+=	-I${NETBSDSRCDIR}/minix/servers # for ds/store.h
30
31# XXX: there is essential code in assert() statements, so force asserts on..
32CPPFLAGS+=	-UNDEBUG
33
34# All functions and data must be assigned to nonstandard sections.  However,
35# the magic_st module has different rules from the rest.
36SECTIONIFY=	-sectionify-no-override \
37	-sectionify-data-section-map=^_____magic_instr_.*/magic_instr_data,.*/magic_data \
38	-sectionify-function-section-map=.*/magic_functions
39SECTIONIFY.magic_st.c=	\
40	-sectionify-data-section-map=.*/magic_data_st \
41	-sectionify-function-section-map=.*/magic_functions_st
42
43# HACK: keep the "temporary" .bc.o files generated as part of running the
44# sectionify pass, so that we can trick clang into taking bitcode objects
45# during the linking phase, because its driver refuses to take objects with
46# the .bc suffix even when using the gold plugin.  This works only because
47# we are using sectionify on all objects here, and because bsd.lib.mk uses
48# temporary names convenient for us.  See also the comment in bsd.lib.mk.
49SECTIONIFYMV=cp
50
51LDFLAGS+=-nostdlib -rdynamic -shared -Wl,--plugin \
52	-Wl,${NETBSDSRCDIR}/minix/llvm/bin/LLVMgold.so \
53	-Wl,-plugin-opt=-disable-fp-elim -Wl,-plugin-opt=emit-llvm
54
55realall: ${LIBNAME}
56
57${LIBNAME}: ${OBJS}
58	${_MKTARGET_LINK}
59	${LINK.c} -o ${.TARGET} ${OBJS:.bc=.bc.o}
60
61# The following block is a modified copy of similar blocks in bsd.lib.mk.
62_LIB=${DESTDIR}/${LIBDIR}/${LIBNAME}
63libinstall:: ${_LIB}
64.PRECIOUS: ${_LIB}
65.if ${MKUPDATE} == "no"
66.if !defined(BUILD) && !make(all) && !make(${LIBNAME})
67${_LIB}! .MADE
68.endif
69${_LIB}! ${LIBNAME} __archiveinstall
70.else
71.if !defined(BUILD) && !make(all) && !make(${LIBNAME})
72${_LIB}: .MADE
73.endif
74${_LIB}: ${LIBNAME} __archiveinstall
75.endif
76
77CLEANFILES+=	${LIBNAME} ${OBJS:.bc=.bc.o}
78
79.include <bsd.lib.mk>
80