1# 2# This Makefile covers the top part of the MI kernel build instructions 3# 4 5# Can be overridden by makeoptions or /etc/make.conf 6KERNEL?= kernel 7 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. 12# 13# /usr/local/bin must be removed from the path. 14# 15RMLDPATH=/usr/local/bin 16PATH:=${PATH:C/${RMLDPATH}//g} 17.export PATH 18 19fubar: 20 echo ${PATH} 21 22# build this target if none is specified on the command line 23.MAIN: all 24 25# Set the platform and machine architectures 26# 27P= ${MACHINE_PLATFORM} 28M= ${MACHINE_ARCH} 29 30SIZE?= size 31OBJCOPY?= objcopy 32 33COPTFLAGS?=-O2 -pipe 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) 40COPTFLAGS+= ${_CPUCFLAGS} 41.endif 42# don't use -I- so we can use proper source-relative locality for local 43# includes. 44# 45# -I. - this is to access the opt_*.h and use_*.h header files generated 46# in the kernel build directory. 47# 48# -Iinclude 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. 53# 54INCLUDES= -nostdinc -I. -Iinclude -I$S 55# Real kernel builds do not need /usr/include, but vkernel builds do. 56# 57.if ${MACHINE_PLATFORM} == "vkernel64" 58.if exists($S/../include) 59INCLUDES+= -I$S/../include 60.else 61INCLUDES+= -I/usr/include 62.endif 63.endif 64 65# This hack lets us use the Intel ACPICA code without spamming a new 66# include path into 100+ source files. 67.include "$S/conf/acpi.mk" 68INCLUDES+= -I${.OBJDIR} -I$S/${OSACPI_MI_DIR} -I$S/${ACPICA_DIR}/include 69 70# ... and the same for Atheros HAL 71INCLUDES+= -I$S/dev/netif/ath/ath_hal -I$S/contrib/dev/ath/ath_hal 72 73# Same thing for drm includes 74INCLUDES+= -I$S/dev/drm/include 75INCLUDES+= -I$S/dev/drm/include/drm 76INCLUDES+= -I$S/dev/drm/include/uapi 77INCLUDES+= -I$S/dev/drm/amd/include 78 79COPTS= ${INCLUDES} ${IDENT} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h 80CFLAGS= ${COPTFLAGS} ${KCFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS} 81 82# XXX LOCORE means "don't declare C stuff" not "for locore.s". 83ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS:N-flto} 84 85# Put configuration-specific C flags last so that they 86# can override the others. 87CFLAGS+= ${CONF_CFLAGS} 88 89# XXX handle this explicitly, fw wrappers use implicit .c.o: rule (LINT64) 90.if defined(FASTER_DEPEND) 91CFLAGS+= -MD 92.endif 93 94NORMAL_C= ${CC} -c ${CFLAGS} ${.IMPSRC} 95NORMAL_C_C= ${CC} -c ${CFLAGS} ${.IMPSRC} 96NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${.IMPSRC} 97 98NORMAL_M= awk -f $S/tools/makeobjops.awk -- -c $<; \ 99 ${CC} -c ${CFLAGS} ${.PREFIX}.c 100 101NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC} 102NORMAL_FWO= ${LD} -b binary -d -warn-common -r -o ${.TARGET} ${.ALLSRC:M*.fw} 103 104.if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc80") 105WERROR=-Werror 106.endif 107 108# NOTE: -lgcc only needed for muldivu64 (__udivti3) 109# 110GEN_CFILES= $S/platform/$P/$M/genassym.c 111SYSTEM_CFILES= ioconf.c config.c 112SYSTEM_SFILES= $S/platform/$P/$M/locore.s 113SYSTEM_DEP= Makefile ${SYSTEM_OBJS} 114SYSTEM_OBJS= locore.o ${OBJS} ioconf.o config.o hack.So 115SYSTEM_LD= @${CC} -nostdlib -ffreestanding -Wl,--hash-style=sysv \ 116 -Wl,-Bdynamic -Wl,-T,$S/platform/$P/conf/ldscript.$M \ 117 -Wl,--export-dynamic -Wl,--dynamic-linker,/red/herring \ 118 -o ${.TARGET} -Wl,-X ${SYSTEM_OBJS} vers.o -lgcc 119 120# In case of LTO provide all standard CFLAGS! 121.if ${CFLAGS:M-flto} 122SYSTEM_LD+= ${CFLAGS} 123## This one eats a lot of ram, may be needed to correctly link the kernel. 124## Default "balanced" might create kernel that "Fatal trap 12" on boot!!! 125#. if !${CFLAGS:M-flto-partition=*} 126#SYSTEM_LD+= -flto-partition=one -flto-report-wpa 127#. endif 128.endif 129 130# The max-page-size for gnu ld is 0x200000 on x86_64 131# For the gold linker, it is only 0x1000 on both x86_64 132# The penalty for changing the gold default for x86_64 is larger binaries 133# and shared libraries, and forcing them to use more address space than 134# required. The only application that needs such a large page size is the 135# kernel itself, so leave the gold default alone and treat the kernel 136# page size as an exception. 137# 138.if ${P} == "pc64" 139SYSTEM_LD+= -Wl,-z,max-page-size=0x200000 140.endif 141 142SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \ 143 ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET} 144SYSTEM_DEP+= $S/platform/$P/conf/ldscript.$M 145 146# Normalize output files to make it absolutely crystal clear to 147# anyone examining the build directory. 148# 149.if defined(DEBUG) 150FULLKERNEL= ${KERNEL}.debug 151.if defined(INSTALLSTRIPPED) 152SELECTEDKERNEL= ${KERNEL}.stripped 153.else 154SELECTEDKERNEL= ${KERNEL}.debug 155.endif 156.else 157FULLKERNEL= ${KERNEL}.nodebug 158SELECTEDKERNEL= ${KERNEL}.stripped 159.endif 160 161 162MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR} BUILDING_WITH_KERNEL=${.OBJDIR} 163.if defined(MODULES_OVERRIDE) 164MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}" 165.endif 166.if defined(DEBUG) 167MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}" 168.endif 169.if defined(INSTALLSTRIPPED) || defined(INSTALLSTRIPPEDMODULES) 170MKMODULESENV+= INSTALLSTRIPPEDMODULES=1 171.endif 172MKMODULESENV+= MACHINE_ARCH=${MACHINE_ARCH} MACHINE=${MACHINE} MACHINE_PLATFORM=${MACHINE_PLATFORM} 173 174