xref: /freebsd/sys/modules/linux64/Makefile (revision 8b959dd6a3921c35395bef4a6d7ad2426a3bd88e)
1# $FreeBSD$
2
3.PATH: ${SRCTOP}/sys/compat/linux ${SRCTOP}/sys/${MACHINE}/linux
4.if ${MACHINE_CPUARCH} == "amd64"
5.PATH: ${SRCTOP}/sys/x86/linux
6.endif
7
8KMOD=	linux64
9SRCS=	linux_elf64.c linux_fork.c linux_dummy_machdep.c linux_file.c \
10	linux_event.c linux_futex.c linux_getcwd.c linux_ioctl.c linux_ipc.c \
11	linux_machdep.c linux_misc.c linux_ptrace.c linux_signal.c \
12	linux_socket.c linux_stats.c linux_sysctl.c linux_sysent.c \
13	linux_sysvec.c linux_time.c linux_vdso.c linux_timer.c \
14	opt_compat.h opt_inet6.h opt_posix.h opt_usb.h \
15	vnode_if.h device_if.h bus_if.h \
16	linux_support.s
17.if ${MACHINE_CPUARCH} == "amd64"
18SRCS+=	linux_dummy_x86.c linux_vdso_tsc_selector_x86.c
19.endif
20DPSRCS=	assym.inc linux_genassym.c
21
22# XXX: for assym.inc
23SRCS+=  opt_kstack_pages.h opt_nfs.h opt_hwpmc_hooks.h
24
25CLEANFILES=	linux_assym.h linux_genassym.o linux_locore.o \
26		genassym.o linux_vdso_gtod.o linux_vdso.so.o
27
28OBJS=	linux_vdso.so
29
30linux_assym.h: linux_genassym.o
31	sh ${SYSDIR}/kern/genassym.sh linux_genassym.o > ${.TARGET}
32
33.if ${MACHINE_CPUARCH} == "amd64"
34VDSOFLAGS=-mcmodel=small -msoft-float
35VDSODEPS=linux_vdso_gettc_x86.inc
36.elif ${MACHINE_CPUARCH} == "aarch64"
37# The Linux uses tiny memory model, but our ld does not know about
38# some of relocation types which is generated by cc
39VDSOFLAGS=-mgeneral-regs-only -mcmodel=small -ffixed-x18
40.endif
41
42linux_locore.o: linux_assym.h assym.inc
43	${CC} -c -x assembler-with-cpp -DLOCORE \
44	-fPIC -pipe -O2 -Werror ${VDSOFLAGS} \
45	-nostdinc -fasynchronous-unwind-tables \
46	-fno-omit-frame-pointer -foptimize-sibling-calls \
47	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
48	    ${.IMPSRC} -o ${.TARGET}
49
50linux_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS}
51	${CC} -c -fPIC -pipe -O2 -Werror ${VDSOFLAGS} \
52	-nostdinc -fasynchronous-unwind-tables \
53	-fno-omit-frame-pointer -foptimize-sibling-calls \
54	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
55	    ${.IMPSRC} -o ${.TARGET}
56
57linux_vdso.so.o: linux_locore.o linux_vdso_gtod.o
58	${LD} --shared --eh-frame-hdr -soname=linux-vdso.so.1 \
59	--no-undefined --hash-style=both -warn-common -nostdlib \
60	--strip-debug -s --build-id=sha1 -Bsymbolic \
61	-T${SRCTOP}/sys/${MACHINE}/linux/linux_vdso.lds.s \
62	-o ${.TARGET} ${.ALLSRC:M*.o}
63
64.if ${MACHINE_CPUARCH} == "aarch64"
65OBJCOPY_TARGET=--output-target elf64-littleaarch64 --binary-architecture aarch64
66.elif ${MACHINE_CPUARCH} == "amd64"
67OBJCOPY_TARGET=--output-target elf64-x86-64 --binary-architecture i386:x86-64
68.else
69.error ${MACHINE_CPUARCH} not yet supported by linux64
70.endif
71
72linux_vdso.so: linux_vdso.so.o
73	${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \
74	    linux_vdso.so.o ${.TARGET}
75	${STRIPBIN} -N _binary_linux_vdso_so_o_size ${.TARGET}
76
77linux_support.o: assym.inc linux_assym.h
78	${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \
79	    ${.IMPSRC} -o ${.TARGET}
80
81linux_genassym.o: offset.inc
82	${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC}
83
84.if !defined(KERNBUILDDIR)
85.warning Building Linuxulator outside of a kernel does not make sense
86.endif
87
88.include <bsd.kmod.mk>
89