2 # This Makefile covers the top part of the MI kernel build instructions
5 # Can be overridden by makeoptions or /etc/make.conf
8 # If a different binutils is installed in /usr/local it probably
9 # won't recognize LDVER or use the default, creating an incompatibility
10 # between buildkernel and nativekernel as well as between buildkernel and
11 # manual make's inside /usr/obj/usr/src/sys/KERNEL_CONFIG.
13 # /usr/local/bin must be removed from the path.
15 RMLDPATH=/usr/local/bin
16 PATH:=${PATH:C/${RMLDPATH}//g}
22 # build this target if none is specified on the command line
25 # Set the platform and machine architectures
27 P= ${MACHINE_PLATFORM}
34 #COPTFLAGS?=-O -pipe -flto -fno-fat-lto-objects
35 #COPTFLAGS?=-O -fthread-jumps -fcse-follow-jumps -fcrossjumping -frerun-cse-after-loop -fno-guess-branch-probability --param min-crossjump-insns=1 -pipe
36 #COPTFLAGS?=-O -fcrossjumping -pipe
37 #COPTFLAGS?=-Os -fno-strict-aliasing -pipe
38 #COPTFLAGS?=-O2 -fno-strict-aliasing -pipe
39 .if !defined(NO_CPU_COPTFLAGS)
40 COPTFLAGS+= ${_CPUCFLAGS}
42 # don't use -I- so we can use proper source-relative locality for local
45 # -I. - this is to access the opt_*.h and use_*.h header files generated
46 # in the kernel build directory.
49 # - this is used to access forwarding header files for
50 # <machine/*.h> that exist in the cpu architecture but do not
51 # exist in the platform (machine/) architecture. This allows
52 # the platform to trivially override the cpu header files.
54 INCLUDES= -nostdinc -I. -Iinclude -I$S
55 # This hack is to allow kernel compiles to succeed on machines w/out srcdist
56 .if exists($S/../include)
57 INCLUDES+= -I$S/../include
59 INCLUDES+= -I/usr/include
62 # This hack lets us use the Intel ACPICA code without spamming a new
63 # include path into 100+ source files.
64 .include "$S/conf/acpi.mk"
65 INCLUDES+= -I${.OBJDIR} -I"$S/${OSACPI_MI_DIR}" -I"$S/${ACPICA_DIR}/include"
67 # ... and the same for Atheros HAL
68 INCLUDES+= -I$S/dev/netif/ath/ath_hal -I$S/contrib/dev/ath/ath_hal
70 # Same thing for drm includes
71 INCLUDES+= -I$S/dev/drm/include
72 INCLUDES+= -I$S/dev/drm/include/drm
73 INCLUDES+= -I$S/dev/drm/include/uapi
74 INCLUDES+= -I$S/dev/drm/amd/include
76 COPTS= ${INCLUDES} ${IDENT} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
77 CFLAGS= ${COPTFLAGS} ${KCFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
79 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
80 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS:N-flto}
82 # Put configuration-specific C flags last so that they
83 # can override the others.
84 CFLAGS+= ${CONF_CFLAGS}
86 # XXX handle this explicitly, fw wrappers use implicit .c.o: rule (LINT64)
87 .if defined(FASTER_DEPEND)
91 NORMAL_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
92 NORMAL_C_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
93 NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${.IMPSRC}
95 NORMAL_M= awk -f $S/tools/makeobjops.awk -- -c $<; \
96 ${CC} -c ${CFLAGS} ${.PREFIX}.c
98 NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
99 NORMAL_FWO= ${LD} -b binary -d -warn-common -r -o ${.TARGET} ${.ALLSRC:M*.fw}
101 .if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc80")
105 GEN_CFILES= $S/platform/$P/$M/genassym.c
106 SYSTEM_CFILES= ioconf.c config.c
107 SYSTEM_SFILES= $S/platform/$P/$M/locore.s
108 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
109 SYSTEM_OBJS= locore.o ${OBJS} ioconf.o config.o hack.So
110 SYSTEM_LD= @${CC} -nostdlib -ffreestanding -Wl,--hash-style=sysv \
111 -Wl,-Bdynamic -Wl,-T,$S/platform/$P/conf/ldscript.$M \
112 -Wl,--export-dynamic -Wl,--dynamic-linker,/red/herring \
113 -o ${.TARGET} -Wl,-X ${SYSTEM_OBJS} vers.o
115 # In case of LTO provide all standard CFLAGS!
117 SYSTEM_LD+= ${CFLAGS}
118 ## This one eats a lot of ram, may be needed to correctly link the kernel.
119 ## Default "balanced" might create kernel that "Fatal trap 12" on boot!!!
120 #. if !${CFLAGS:M-flto-partition=*}
121 #SYSTEM_LD+= -flto-partition=one -flto-report-wpa
125 # The max-page-size for gnu ld is 0x200000 on x86_64
126 # For the gold linker, it is only 0x1000 on both x86_64
127 # The penalty for changing the gold default for x86_64 is larger binaries
128 # and shared libraries, and forcing them to use more address space than
129 # required. The only application that needs such a large page size is the
130 # kernel itself, so leave the gold default alone and treat the kernel
131 # page size as an exception.
134 SYSTEM_LD+= -Wl,-z,max-page-size=0x200000
137 SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
138 ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
139 SYSTEM_DEP+= $S/platform/$P/conf/ldscript.$M
141 # Normalize output files to make it absolutely crystal clear to
142 # anyone examining the build directory.
145 FULLKERNEL= ${KERNEL}.debug
146 .if defined(INSTALLSTRIPPED)
147 SELECTEDKERNEL= ${KERNEL}.stripped
149 SELECTEDKERNEL= ${KERNEL}.debug
152 FULLKERNEL= ${KERNEL}.nodebug
153 SELECTEDKERNEL= ${KERNEL}.stripped
157 MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR} BUILDING_WITH_KERNEL=${.OBJDIR}
158 .if defined(MODULES_OVERRIDE)
159 MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}"
162 MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}"
164 .if defined(INSTALLSTRIPPED) || defined(INSTALLSTRIPPEDMODULES)
165 MKMODULESENV+= INSTALLSTRIPPEDMODULES=1
167 MKMODULESENV+= MACHINE_ARCH=${MACHINE_ARCH} MACHINE=${MACHINE} MACHINE_PLATFORM=${MACHINE_PLATFORM}