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