xref: /freebsd/sys/modules/linux/Makefile (revision 3078531de10dcae44b253a35125c949ff4235284)
1# $FreeBSD$
2
3.if ${MACHINE_CPUARCH} == "amd64"
4SFX= 32
5CFLAGS+=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32
6.endif
7
8.PATH: ${SRCTOP}/sys/compat/linux ${SRCTOP}/sys/${MACHINE_CPUARCH}/linux${SFX}
9.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
10.PATH: ${SRCTOP}/sys/x86/linux
11.endif
12
13KMOD=	linux
14SRCS=	linux_fork.c linux${SFX}_dummy_machdep.c linux_file.c linux_event.c \
15	linux_futex.c linux_getcwd.c linux_ioctl.c linux_ipc.c \
16	linux${SFX}_machdep.c linux_misc.c linux_signal.c \
17	linux_socket.c linux_stats.c linux_sysctl.c linux${SFX}_sysent.c \
18	linux${SFX}_sysvec.c linux_uid16.c linux_time.c \
19	linux_timer.c linux_vdso.c linux_rseq.c \
20	opt_inet6.h opt_compat.h opt_posix.h opt_usb.h vnode_if.h \
21	device_if.h bus_if.h
22.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
23SRCS+=	linux_dummy_x86.c
24VDSODEPS=linux_vdso_gettc_x86.inc
25.endif
26.if ${MACHINE_CPUARCH} == "amd64"
27SRCS+=	linux${SFX}_support.s
28SRCS+=	linux_elf32.c
29.else
30SRCS+=	linux_copyout.c
31.endif
32DPSRCS=	assym.inc linux${SFX}_genassym.c
33
34# XXX: for assym.inc
35SRCS+=  opt_kstack_pages.h opt_nfs.h opt_hwpmc_hooks.h
36.if ${MACHINE_CPUARCH} == "i386"
37SRCS+=	opt_apic.h
38.endif
39
40OBJS=	linux${SFX}_vdso.so
41
42.if ${MACHINE_CPUARCH} == "i386"
43SRCS+=	linux_ptrace_machdep.c imgact_linux.c linux_util.c linux_mib.c \
44	linux_mmap.c linux_dummy.c linux_emul.c linux_errno.c opt_cpu.h linux.c \
45	linux_x86.c linux_vdso_selector_x86.c
46.endif
47
48.if ${MACHINE_CPUARCH} == "i386"
49EXPORT_SYMS=
50EXPORT_SYMS+=	linux_emul_path
51EXPORT_SYMS+=	linux_get_osname
52EXPORT_SYMS+=	linux_get_osrelease
53EXPORT_SYMS+=	linux_ioctl_register_handler
54EXPORT_SYMS+=	linux_ioctl_unregister_handler
55.endif
56
57CLEANFILES=	linux${SFX}_assym.h linux${SFX}_genassym.o linux${SFX}_locore.o \
58		genassym.o linux${SFX}_vdso_gtod.o linux${SFX}_vdso.so.o
59
60linux${SFX}_assym.h: linux${SFX}_genassym.o
61	sh ${SYSDIR}/kern/genassym.sh linux${SFX}_genassym.o > ${.TARGET}
62
63.if ${MACHINE_CPUARCH} == "amd64"
64VDSOFLAGS=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 -m32
65.else
66VDSOFLAGS=-mregparm=0
67.endif
68
69linux${SFX}_locore.o: linux${SFX}_assym.h assym.inc
70	${CC} -c -x assembler-with-cpp -DLOCORE -fPIC -pipe -O2 -Werror \
71	-msoft-float \
72	-fno-common -nostdinc -fasynchronous-unwind-tables \
73	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
74	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
75	    ${.IMPSRC} -o ${.TARGET}
76
77linux${SFX}_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS}
78	${CC} -c -fPIC -pipe -O2 -Werror -msoft-float \
79	-fno-common -nostdinc -fasynchronous-unwind-tables \
80	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
81	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
82	    ${.IMPSRC} -o ${.TARGET}
83
84linux${SFX}_vdso.so.o: linux${SFX}_locore.o linux${SFX}_vdso_gtod.o
85	${LD} -m elf_i386 --shared --eh-frame-hdr -soname=linux-gate.so.1 \
86	--no-undefined --hash-style=both -warn-common -nostdlib \
87	--strip-debug -s --build-id=sha1 --Bsymbolic \
88	-T${SRCTOP}/sys/${MACHINE}/linux${SFX}/linux${SFX}_vdso.lds.s \
89	-o ${.TARGET} ${.ALLSRC:M*.o}
90
91.if ${MACHINE_CPUARCH} == "amd64"
92OBJCOPY_TARGET=--output-target elf64-x86-64-freebsd --binary-architecture i386
93.elif ${MACHINE_CPUARCH} == "i386"
94OBJCOPY_TARGET=--output-target elf32-i386-freebsd --binary-architecture i386
95.else
96.error ${MACHINE_CPUARCH} not yet supported by linux
97.endif
98
99linux${SFX}_vdso.so: linux${SFX}_vdso.so.o
100	${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \
101	    linux${SFX}_vdso.so.o ${.TARGET}
102	${STRIPBIN} -N _binary_linux${SFX}_vdso_so_o_size ${.TARGET}
103
104.if ${MACHINE_CPUARCH} == "amd64"
105linux${SFX}_support.o: linux${SFX}_assym.h assym.inc
106	${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \
107	    ${.IMPSRC} -o ${.TARGET}
108.endif
109
110linux${SFX}_genassym.o: offset.inc
111	${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC}
112
113.if !defined(KERNBUILDDIR)
114.warning Building Linuxulator outside of a kernel does not make sense
115.endif
116
117EXPORT_SYMS=	YES
118
119.include <bsd.kmod.mk>
120