xref: /freebsd/sys/modules/linux/Makefile (revision 3f9d360c82e0724bfb61346038236bf15c5d4d84)
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 \
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 linux_vdso_tsc_selector_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.c imgact_linux.c linux_util.c linux_mib.c linux_mmap.c \
44	linux_dummy.c linux_emul.c linux_errno.c opt_cpu.h linux.c
45.endif
46
47.if ${MACHINE_CPUARCH} == "i386"
48EXPORT_SYMS=
49EXPORT_SYMS+=	linux_emul_path
50EXPORT_SYMS+=	linux_get_osname
51EXPORT_SYMS+=	linux_get_osrelease
52EXPORT_SYMS+=	linux_ioctl_register_handler
53EXPORT_SYMS+=	linux_ioctl_unregister_handler
54.endif
55
56CLEANFILES=	linux${SFX}_assym.h linux${SFX}_genassym.o linux${SFX}_locore.o \
57		genassym.o linux${SFX}_vdso_gtod.o linux${SFX}_vdso.so.o
58
59linux${SFX}_assym.h: linux${SFX}_genassym.o
60	sh ${SYSDIR}/kern/genassym.sh linux${SFX}_genassym.o > ${.TARGET}
61
62.if ${MACHINE_CPUARCH} == "amd64"
63VDSOFLAGS=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 -m32
64.endif
65
66linux${SFX}_locore.o: linux${SFX}_assym.h assym.inc
67	${CC} -c -x assembler-with-cpp -DLOCORE -fPIC -pipe -O2 -Werror \
68	-msoft-float -mregparm=0 \
69	-mcmodel=small -fno-common -nostdinc -fasynchronous-unwind-tables \
70	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
71	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
72	    ${.IMPSRC} -o ${.TARGET}
73
74linux${SFX}_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS}
75	${CC} -c -fPIC -pipe -O2 -Werror -msoft-float -mregparm=0 \
76	-mcmodel=small -fno-common -nostdinc -fasynchronous-unwind-tables \
77	-fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \
78	-fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \
79	    ${.IMPSRC} -o ${.TARGET}
80
81linux${SFX}_vdso.so.o: linux${SFX}_locore.o linux${SFX}_vdso_gtod.o
82	${LD} -m elf_i386 --shared --eh-frame-hdr -soname=linux-gate.so.1 \
83	--no-undefined --hash-style=both -warn-common -nostdlib \
84	--strip-debug -s --build-id=sha1 --Bsymbolic \
85	-T${SRCTOP}/sys/${MACHINE}/linux${SFX}/linux${SFX}_vdso.lds.s \
86	-o ${.TARGET} ${.ALLSRC:M*.o}
87
88.if ${MACHINE_CPUARCH} == "amd64"
89OBJCOPY_TARGET=--output-target elf64-x86-64-freebsd --binary-architecture i386
90.elif ${MACHINE_CPUARCH} == "i386"
91OBJCOPY_TARGET=--output-target elf32-i386-freebsd --binary-architecture i386
92.else
93.error ${MACHINE_CPUARCH} not yet supported by linux
94.endif
95
96linux${SFX}_vdso.so: linux${SFX}_vdso.so.o
97	${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \
98	    linux${SFX}_vdso.so.o ${.TARGET}
99	${STRIPBIN} -N _binary_linux${SFX}_vdso_so_o_size ${.TARGET}
100
101.if ${MACHINE_CPUARCH} == "amd64"
102linux${SFX}_support.o: linux${SFX}_assym.h assym.inc
103	${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \
104	    ${.IMPSRC} -o ${.TARGET}
105.endif
106
107linux${SFX}_genassym.o: offset.inc
108	${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC}
109
110.if !defined(KERNBUILDDIR)
111.warning Building Linuxulator outside of a kernel does not make sense
112.endif
113
114.include <bsd.kmod.mk>
115