Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

# $NetBSD: Makefile.usermode,v 1.44 2018/09/22 12:24:03 rin Exp $

MKCTF?=				no
USETOOLS?=			no
NEED_OWN_INSTALL_TARGET?=	no
.include <bsd.own.mk>

##
## (1) port identification
##
USERMODE=	$S/arch/usermode
GENASSYM_CONF=	${USERMODE}/usermode/genassym.cf

## support for crosscompiling
.if ${MACHINE_ARCH:Uunset} == "unset"
MACHINE_ARCH!=uname -p
.endif

##
## (2) compile settings
##
USERMODE_HOSTOS!=uname -s
USERMODE_HOSTMACHINE!=uname -m
USERMODE_LIBS= -L${DESTDIR}/usr/lib -lrt
USERMODE_CPPFLAGS=${DEBUG} -U_KERNEL
USERMODE_CPPFLAGS+=-I${DESTDIR}/usr/include
USERMODE_CPPFLAGS+=${CWARNFLAGS} ${NOGCCERROR:D:U-Werror}

## XXX hack to make it work under build.sh
.if ${TOOLDIR:Uno} != "no"
USERMODE_LIBS+= crti.o
SYSTEM_LD_FIX= cp ${DESTDIR}/usr/lib/crt0.o ${DESTDIR}/usr/lib/crtbegin.o ${DESTDIR}/usr/lib/crtend.o ${DESTDIR}/usr/lib/crti.o .;
.endif

.if ${USERMODE_HOSTOS} == "Linux"
USERMODE_LIBS+=	-lpthread
CPPFLAGS+=-Dstrtoul=netbsd_strtoul
CPPFLAGS+=-Dstrtoll=netbsd_strtoll
CPPFLAGS+=-Dstrtoull=netbsd_strtoull
CPPFLAGS+=-D__NetBSD__ -Wno-unused-but-set-variable
.endif

DEFCOPTS=	-fno-omit-frame-pointer
CPPFLAGS+=	-Dusermode
CPPFLAGS+=	-Dsyscall=kernel_syscall
CPPFLAGS.init_main.c+=	-Dmain=kernmain

CPPFLAGS.thunk.c+=	${USERMODE_CPPFLAGS}

##
## (3) libkern and compat
##
OPT_MODULAR=	%MODULAR%

##
## (4) local objects, compile rules, and dependencies
##
MD_OBJS=	thunk.o
MD_CFILES=	${USERMODE}/usermode/thunk.c
MD_SFILES=

MD_OBJS+=	cpu_${MACHINE_CPU}.o
MD_CFILES+=	${USERMODE}/target/${MACHINE_CPU}/cpu_${MACHINE_CPU}.c

##
## (5) link settings
##
TEXTADDR?=	  %TEXTADDR%

LINKFLAGS_NORMAL=	-X
KERNLDSCRIPT?=	${USERMODE}/conf/kern.ldscript

SYSTEM_LD=	@do_system_ld() { \
		${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
		${_MKSHECHO}\
		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Wl,-Ttext,${TEXTADDR} '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o netbsd.ldscript ${USERMODE_LIBS} $$@; \
		${SYSTEM_LD_FIX} \
		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Wl,-Ttext,${TEXTADDR} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o netbsd.ldscript ${USERMODE_LIBS} $$@; \
		}; \
		do_system_ld
NVFLAGS=	-n

##
## (6) port specific target dependencies
##

.if !make(obj) && !make(clean) && !make(cleandir)
.BEGIN::
	-@rm -f i386 && \
		ln -s $S/arch/i386/include i386
	-@rm -f amd64 && \
		ln -s $S/arch/amd64/include amd64
	-@rm -f arm && \
		ln -s $S/arch/arm/include arm
.endif

thunk.d: ${USERMODE}/usermode/thunk.c
	${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \
	    ${CPPFLAGS.thunk.c} ${USERMODE}/usermode/thunk.c

thunk.o: ${USERMODE}/usermode/thunk.c
	${CC} ${COPTS} ${CPPFLAGS.thunk.c} -c -o $@ ${USERMODE}/usermode/thunk.c

cpu_${MACHINE_CPU}.o:	${USERMODE}/target/${MACHINE_CPU}/cpu_${MACHINE_CPU}.c

##
## (7) misc settings
##

##
## (8) config(8) generated machinery
%INCLUDES

%OBJS

%CFILES

%SFILES

%LOAD

%RULES

##
## (9) port independent kernel machinery
##
.include "$S/conf/Makefile.kern.inc"

##
## (10) appending make options
##
%MAKEOPTIONSAPPEND