kernel: Add simpler make depend variant for kernel.
[dragonfly.git] / sys / conf / kern.pre.mk
CommitLineData
edbe133c
SS
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# build this target if none is specified on the command line
9.MAIN: all
10
a9295349
MD
11# Set the platform and machine architectures
12#
0955fd91 13P= ${MACHINE_PLATFORM}
edbe133c
SS
14M= ${MACHINE_ARCH}
15
16SIZE?= size
17OBJCOPY?= objcopy
18
dfad150f 19COPTFLAGS?=-O2 -pipe
2d84cb50 20#COPTFLAGS?=-O -pipe -flto -fno-fat-lto-objects
116b7e3c
MD
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
edbe133c
SS
25.if !defined(NO_CPU_COPTFLAGS)
26COPTFLAGS+= ${_CPUCFLAGS}
27.endif
493c0012 28# don't use -I- so we can use proper source-relative locality for local
a9295349
MD
29# includes.
30#
31# -I. - this is to access the opt_*.h and use_*.h header files generated
32# in the kernel build directory.
33#
34# -Iinclude
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.
39#
40INCLUDES= -nostdinc -I. -Iinclude -I$S
edbe133c
SS
41# This hack is to allow kernel compiles to succeed on machines w/out srcdist
42.if exists($S/../include)
43INCLUDES+= -I$S/../include
44.else
45INCLUDES+= -I/usr/include
46.endif
47
0fe46dc6
MD
48# For <openssl/headerfile>
49#
50INCLUDES+= -I$S/../crypto/libressl/include
51
edbe133c
SS
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"
55INCLUDES+= -I${.OBJDIR} -I"$S/${OSACPI_MI_DIR}" -I"$S/${ACPICA_DIR}/include"
56
50a82a17
SW
57# ... and the same for Atheros HAL
58INCLUDES+= -I$S/dev/netif/ath/ath_hal -I$S/contrib/dev/ath/ath_hal
edbe133c 59
18e26a6d
FT
60# Same thing for drm includes
61INCLUDES+= -I$S/dev/drm/include
62
faba9d16 63COPTS= ${INCLUDES} ${IDENT} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
56f51086 64CFLAGS= ${COPTFLAGS} ${KCFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
edbe133c
SS
65
66# XXX LOCORE means "don't declare C stuff" not "for locore.s".
2d84cb50 67ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS:N-flto}
edbe133c
SS
68
69DEFINED_PROF= ${PROF}
70.if defined(PROF)
71CFLAGS+= -falign-functions=16
72.if ${PROFLEVEL} >= 2
73IDENT+= -DGPROF4 -DGUPROF
edbe133c
SS
74.endif
75.endif
76
77# Put configuration-specific C flags last (except for ${PROF}) so that they
78# can override the others.
79CFLAGS+= ${CONF_CFLAGS}
80
319f97f7 81# XXX handle this explicitly, fw wrappers use implicit .c.o: rule (LINT64)
82.if defined(FASTER_DEPEND)
83CFLAGS+= -MD
84.endif
85
edbe133c
SS
86NORMAL_C= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
87NORMAL_C_C= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
88NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${.IMPSRC}
89PROFILE_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
90
91NORMAL_M= awk -f $S/tools/makeobjops.awk -- -c $<; \
92 ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c
93
6e65b53f
SW
94NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
95NORMAL_FWO= ${LD} -b binary -d -warn-common -r -o ${.TARGET} ${.ALLSRC:M*.fw}
96
b399af11 97.if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc50")
40ec0564
SW
98WERROR=-Werror
99.endif
100
0955fd91 101GEN_CFILES= $S/platform/$P/$M/genassym.c
edbe133c 102SYSTEM_CFILES= ioconf.c config.c
0955fd91 103SYSTEM_SFILES= $S/platform/$P/$M/locore.s
edbe133c
SS
104SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
105SYSTEM_OBJS= locore.o ${OBJS} ioconf.o config.o hack.So
fa810433 106SYSTEM_LD= @${CC} -nostdlib -ffreestanding -Wl,--hash-style=sysv \
107 -Wl,-Bdynamic -Wl,-T,$S/platform/$P/conf/ldscript.$M \
108 -Wl,--export-dynamic -Wl,--dynamic-linker,/red/herring \
109 -o ${.TARGET} -Wl,-X ${SYSTEM_OBJS} vers.o
ed9f17e4 110
2d84cb50 111# In case of LTO provide all standard CFLAGS!
112.if ${CFLAGS:M-flto}
113SYSTEM_LD+= ${CFLAGS}
ac61251d 114## This one eats a lot of ram, may be needed to correctly link the kernel.
115## Default "balanced" might create kernel that "Fatal trap 12" on boot!!!
116#. if !${CFLAGS:M-flto-partition=*}
117#SYSTEM_LD+= -flto-partition=one -flto-report-wpa
118#. endif
2d84cb50 119.endif
120
ed9f17e4 121# The max-page-size for gnu ld is 0x200000 on x86_64
0a80a445 122# For the gold linker, it is only 0x1000 on both x86_64
ed9f17e4
JM
123# The penalty for changing the gold default for x86_64 is larger binaries
124# and shared libraries, and forcing them to use more address space than
125# required. The only application that needs such a large page size is the
126# kernel itself, so leave the gold default alone and treat the kernel
127# page size as an exception.
128#
2e136f9a 129.if ${P} == "pc64"
fa810433 130SYSTEM_LD+= -Wl,-z,max-page-size=0x200000
ed9f17e4
JM
131.endif
132
edbe133c
SS
133SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
134 ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
0955fd91 135SYSTEM_DEP+= $S/platform/$P/conf/ldscript.$M
edbe133c
SS
136
137# Normalize output files to make it absolutely crystal clear to
138# anyone examining the build directory.
139#
140.if defined(DEBUG)
141FULLKERNEL= ${KERNEL}.debug
142.if defined(INSTALLSTRIPPED)
143SELECTEDKERNEL= ${KERNEL}.stripped
144.else
145SELECTEDKERNEL= ${KERNEL}.debug
146.endif
147.else
148FULLKERNEL= ${KERNEL}.nodebug
149SELECTEDKERNEL= ${KERNEL}.stripped
150.endif
151
152
153MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR} BUILDING_WITH_KERNEL=${.OBJDIR}
154.if defined(MODULES_OVERRIDE)
155MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}"
156.endif
157.if defined(DEBUG)
158MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}"
159.endif
160.if defined(INSTALLSTRIPPED) || defined(INSTALLSTRIPPEDMODULES)
161MKMODULESENV+= INSTALLSTRIPPEDMODULES=1
162.endif
982b0507 163MKMODULESENV+= MACHINE_ARCH=${MACHINE_ARCH} MACHINE=${MACHINE} MACHINE_PLATFORM=${MACHINE_PLATFORM}
edbe133c 164