2 # This Makefile covers the top part of the MI kernel build instructions
5 # Can be overridden by makeoptions or /etc/make.conf
8 # build this target if none is specified on the command line
11 # Set the platform and machine architectures
13 P= ${MACHINE_PLATFORM}
20 #COPTFLAGS?=-O -pipe -flto -fno-fat-lto-objects
21 #COPTFLAGS?=-O -fthread-jumps -fcse-follow-jumps -fcrossjumping -frerun-cse-after-loop -fno-guess-branch-probability --param min-crossjump-insns=1 -pipe
22 #COPTFLAGS?=-O -fcrossjumping -pipe
23 #COPTFLAGS?=-Os -fno-strict-aliasing -pipe
24 #COPTFLAGS?=-O2 -fno-strict-aliasing -pipe
25 .if !defined(NO_CPU_COPTFLAGS)
26 COPTFLAGS+= ${_CPUCFLAGS}
28 # don't use -I- so we can use proper source-relative locality for local
31 # -I. - this is to access the opt_*.h and use_*.h header files generated
32 # in the kernel build directory.
35 # - this is used to access forwarding header files for
36 # <machine/*.h> that exist in the cpu architecture but do not
37 # exist in the platform (machine/) architecture. This allows
38 # the platform to trivially override the cpu header files.
40 INCLUDES= -nostdinc -I. -Iinclude -I$S
41 # This hack is to allow kernel compiles to succeed on machines w/out srcdist
42 .if exists($S/../include)
43 INCLUDES+= -I$S/../include
45 INCLUDES+= -I/usr/include
48 # For <openssl/headerfile>
50 INCLUDES+= -I$S/../crypto/libressl/include
52 # This hack lets us use the Intel ACPICA code without spamming a new
53 # include path into 100+ source files.
54 .include "$S/conf/acpi.mk"
55 INCLUDES+= -I${.OBJDIR} -I"$S/${OSACPI_MI_DIR}" -I"$S/${ACPICA_DIR}/include"
57 # ... and the same for Atheros HAL
58 INCLUDES+= -I$S/dev/netif/ath/ath_hal -I$S/contrib/dev/ath/ath_hal
60 # Same thing for drm includes
61 INCLUDES+= -I$S/dev/drm/include -I$S/dev/drm/include/uapi
63 COPTS= ${INCLUDES} ${IDENT} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
64 CFLAGS= ${COPTFLAGS} ${KCFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
66 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
67 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS:N-flto}
69 # Put configuration-specific C flags last so that they
70 # can override the others.
71 CFLAGS+= ${CONF_CFLAGS}
73 # XXX handle this explicitly, fw wrappers use implicit .c.o: rule (LINT64)
74 .if defined(FASTER_DEPEND)
78 NORMAL_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
79 NORMAL_C_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
80 NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${.IMPSRC}
82 NORMAL_M= awk -f $S/tools/makeobjops.awk -- -c $<; \
83 ${CC} -c ${CFLAGS} ${.PREFIX}.c
85 NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
86 NORMAL_FWO= ${LD} -b binary -d -warn-common -r -o ${.TARGET} ${.ALLSRC:M*.fw}
88 .if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc50" || ${CCVER} == "gcc80")
92 GEN_CFILES= $S/platform/$P/$M/genassym.c
93 SYSTEM_CFILES= ioconf.c config.c
94 SYSTEM_SFILES= $S/platform/$P/$M/locore.s
95 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
96 SYSTEM_OBJS= locore.o ${OBJS} ioconf.o config.o hack.So
97 SYSTEM_LD= @${CC} -nostdlib -ffreestanding -Wl,--hash-style=sysv \
98 -Wl,-Bdynamic -Wl,-T,$S/platform/$P/conf/ldscript.$M \
99 -Wl,--export-dynamic -Wl,--dynamic-linker,/red/herring \
100 -o ${.TARGET} -Wl,-X ${SYSTEM_OBJS} vers.o
102 # In case of LTO provide all standard CFLAGS!
104 SYSTEM_LD+= ${CFLAGS}
105 ## This one eats a lot of ram, may be needed to correctly link the kernel.
106 ## Default "balanced" might create kernel that "Fatal trap 12" on boot!!!
107 #. if !${CFLAGS:M-flto-partition=*}
108 #SYSTEM_LD+= -flto-partition=one -flto-report-wpa
112 # The max-page-size for gnu ld is 0x200000 on x86_64
113 # For the gold linker, it is only 0x1000 on both x86_64
114 # The penalty for changing the gold default for x86_64 is larger binaries
115 # and shared libraries, and forcing them to use more address space than
116 # required. The only application that needs such a large page size is the
117 # kernel itself, so leave the gold default alone and treat the kernel
118 # page size as an exception.
121 SYSTEM_LD+= -Wl,-z,max-page-size=0x200000
124 SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
125 ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
126 SYSTEM_DEP+= $S/platform/$P/conf/ldscript.$M
128 # Normalize output files to make it absolutely crystal clear to
129 # anyone examining the build directory.
132 FULLKERNEL= ${KERNEL}.debug
133 .if defined(INSTALLSTRIPPED)
134 SELECTEDKERNEL= ${KERNEL}.stripped
136 SELECTEDKERNEL= ${KERNEL}.debug
139 FULLKERNEL= ${KERNEL}.nodebug
140 SELECTEDKERNEL= ${KERNEL}.stripped
144 MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR} BUILDING_WITH_KERNEL=${.OBJDIR}
145 .if defined(MODULES_OVERRIDE)
146 MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}"
149 MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}"
151 .if defined(INSTALLSTRIPPED) || defined(INSTALLSTRIPPEDMODULES)
152 MKMODULESENV+= INSTALLSTRIPPEDMODULES=1
154 MKMODULESENV+= MACHINE_ARCH=${MACHINE_ARCH} MACHINE=${MACHINE} MACHINE_PLATFORM=${MACHINE_PLATFORM}