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