xref: /freebsd/sys/modules/linux/Makefile (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
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${SFX}_dummy_machdep.c \
15	linux_elf32.c \
16	linux_event.c \
17	linux_file.c \
18	linux_fork.c \
19	linux_futex.c \
20	linux_getcwd.c \
21	linux_ioctl.c \
22	linux_ipc.c \
23	linux${SFX}_machdep.c \
24	linux_misc.c \
25	linux_rseq.c \
26	linux_signal.c \
27	linux_socket.c \
28	linux_stats.c \
29	linux${SFX}_syscalls.c \
30	linux_sysctl.c \
31	linux${SFX}_sysent.c \
32	linux${SFX}_sysvec.c \
33	linux_time.c \
34	linux_timer.c \
35	linux_uid16.c \
36	linux_vdso.c \
37	linux_xattr.c \
38	opt_inet6.h \
39	opt_ktrace.h \
40	opt_posix.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	opt_netlink.h
76.endif
77
78.if ${MACHINE_CPUARCH} == "i386"
79EXPORT_SYMS=
80EXPORT_SYMS+=	linux_get_osname
81EXPORT_SYMS+=	linux_get_osrelease
82EXPORT_SYMS+=	linux_ioctl_register_handler
83EXPORT_SYMS+=	linux_ioctl_unregister_handler
84.endif
85
86CLEANFILES=	linux${SFX}_assym.h linux${SFX}_genassym.o linux${SFX}_locore.o \
87		genassym.o linux${SFX}_vdso_gtod.o linux${SFX}_vdso.so.o
88
89linux${SFX}_assym.h: linux${SFX}_genassym.o
90	sh ${SYSDIR}/kern/genassym.sh linux${SFX}_genassym.o > ${.TARGET}
91
92.if ${MACHINE_CPUARCH} == "amd64"
93VDSOFLAGS=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 -m32
94.else
95VDSOFLAGS=-mregparm=0
96.endif
97
98linux${SFX}_locore.o: linux${SFX}_assym.h assym.inc
99	${CC} -c -x assembler-with-cpp -DLOCORE -fPIC -pipe -O2 -Werror \
100	-msoft-float \
101	-fno-common -nostdinc -fasynchronous-unwind-tables \
102	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
103	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
104	    ${.IMPSRC} -o ${.TARGET}
105
106linux${SFX}_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS}
107	${CC} -c -fPIC -pipe -O2 -Werror -msoft-float \
108	-fno-common -nostdinc -fasynchronous-unwind-tables \
109	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
110	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
111	    ${.IMPSRC} -o ${.TARGET}
112
113linux${SFX}_vdso.so.o: linux${SFX}_locore.o linux${SFX}_vdso_gtod.o
114	${LD} -m elf_i386 --shared --eh-frame-hdr -soname=linux-gate.so.1 \
115	--no-undefined --hash-style=both -warn-common -nostdlib \
116	--strip-debug -s --build-id=sha1 --Bsymbolic \
117	-T${SRCTOP}/sys/${MACHINE}/linux${SFX}/linux${SFX}_vdso.lds.s \
118	-o ${.TARGET} ${.ALLSRC:M*.o}
119
120.if ${MACHINE_CPUARCH} == "amd64"
121OBJCOPY_TARGET=--output-target elf64-x86-64-freebsd --binary-architecture i386
122.elif ${MACHINE_CPUARCH} == "i386"
123OBJCOPY_TARGET=--output-target elf32-i386-freebsd --binary-architecture i386
124.else
125.error ${MACHINE_CPUARCH} not yet supported by linux
126.endif
127
128linux${SFX}_vdso.so: linux${SFX}_vdso.so.o
129	${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \
130	    linux${SFX}_vdso.so.o ${.TARGET}
131	${STRIPBIN} -N _binary_linux${SFX}_vdso_so_o_size ${.TARGET}
132
133.if ${MACHINE_CPUARCH} == "amd64"
134linux${SFX}_support.o: linux${SFX}_support.S linux${SFX}_assym.h assym.inc
135	${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \
136	    ${.ALLSRC:M*.S:u} -o ${.TARGET}
137.endif
138
139linux${SFX}_genassym.o: offset.inc
140	${CC} -c ${CFLAGS:N-flto:N-fno-common} -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