7 BUILD_ROOT
:= $(CURDIR
)
10 KERNELVERSION
:= $(KERNEL_MAJOR_VER
).
$(KERNEL_MIDDLE_VER
).
$(KERNEL_MINOR_VER
)
11 VERFILE
:= include/version.h
17 OBJDUMP
:= $(TOOLCHAIN
)objdump
18 OBJCOPY
:= $(TOOLCHAIN
)objcopy
26 ARCH
:= $(shell echo
$(CONFIG_ARCH
) | sed
's|"||g')
30 SCRIPTS_DIR
:= $(BUILD_ROOT
)/scripts
31 ARCH_DIR
:= $(BUILD_ROOT
)/kernel
/arch
/$(ARCH
)
32 ARCH_COM_DIR
:= $(BUILD_ROOT
)/kernel
/arch
/common
35 GMAP
:= $(SCRIPTS_DIR
)/gmap.py
36 MKLINKS
:= $(SCRIPTS_DIR
)/mklinks.sh
52 CFLAGS
= -Wall
-nostdlib
-nostdinc
-fno-builtin
-fomit-frame-pointer
-nodefaultlibs \
53 $(OPTIMIZATION
) $(KERN_CFLAGS
)
57 MENUCONFIG_COLOR ?
= mono
59 export CC LD AR OBJDUMP OBJCOPY GMAP GREP CPP AS ECHO
60 export HOSTCC HOSTLD HOSTCFLAGS HOSTLDFLAGS
61 export GREP MAKE LN RM GMAP MKDIR CP
62 export CFLAGS LDFLAGS INCLUDE
63 export BUILD_ROOT ARCH ARCH_DIR ARCH_COM_DIR OBJECTS
64 export KERNELVERSION MENUCONFIG_COLOR
66 include include/Makefile.inc
68 GENERICS
= kernel server
69 ifeq ($(CONFIG_TEST
),y
)
75 -include kernel
/arch
/$(ARCH
)/Makefile.inc
78 $(call echo-header
,"kconfig")
79 $(Q
)$(MAKE
) all -C kconfig BUILD_ROOT
=$(BUILD_ROOT
)
82 $(call echo-label
,"OBJCOPY",$< -> $@
)
83 $(Q
)$(OBJCOPY
) -O binary
$< $@
85 muielf
: mkbins collect_objects
$(ODIR
)/kernel.
ld
86 $(call echo-header
,"$@")
87 $(call echo-action
,"LD",$@
)
88 $(Q
)$(LD
) -T
$(ODIR
)/kernel.
ld $(LDFLAGS
) -q
$(OBJECTS
) -o
$@
-Map
$(ODIR
)/muielf.map
89 $(Q
)$(OBJDUMP
) -t
$(OBJECTS
) > $(ODIR
)/muielf.objdump
91 mkbins
: check_config prepare
$(addprefix generic_
, $(GENERICS
))
94 $(Q
)$(MKDIR
) -p
$(ODIR
)
99 $(Q
)$(LN
) -s
$(BUILD_ROOT
)/kernel
/arch
/$(ARCH
)/include $(BUILD_ROOT
)/include/arch
102 ifeq ($(shell [ -f
$(BUILD_ROOT
)/.config
] && echo
"y"),)
103 $(Q
)$(MAKE
) help_config
107 $(call echo-header
,"$(subst generic_,,$@)")
108 $(Q
)$(MAKE
) -f rules.mak target
=$(subst generic_
,,$@
)
111 $(call echo-header
,"Cleaning $(subst clean_,,$@):")
112 $(Q
)$(MAKE
) -f rules.mak target
=$(subst clean_
,,$@
) clean
115 $(Q
)$(RM
) -rf
$(ODIR
)
116 $(Q
)$(RM
) -f muielf vmuielf boot.img
$(BUILD_ROOT
)/include/arch
118 $(Q
)$(MAKE
) -C.
$(addprefix clean_
, $(GENERICS
))
121 $(call echo-header
,"Cleaning host")
122 $(Q
)$(MAKE
) -C kconfig
clean
125 $(call echo-header
,"Cleaning configs")
126 $(Q
)$(RM
) -rf .config
include/config.h
include/config
/ $(VERFILE
)
128 distclean: clean_host
clean cleanconf
130 $(ODIR
)/rmap.o
: $(ODIR
)/rmap.bin
134 $(eval OBJECTS
:= $(call collect_objects
))
137 ifneq ($(NOBUILDIMG
),y
)
138 # Creates a 20 MB bootable FAT HD image: 44 tracks, 16 heads, 63 sectors
139 @dd if
=/dev
/zero of
=boot.img count
=44352 bs
=512
140 @echo
"drive c: file=\"`pwd`/boot.img\" partition=1" > ~
/.mtoolsrc
141 @mpartition
-I
-s
63 -t
44 -h
16 c
:
142 @mpartition
-cpv
-s
63 -t
44 -h
16 c
:
146 @mcopy
/boot
/grub
/stage1 c
:/boot
/grub
147 @mcopy
/boot
/grub
/stage2 c
:/boot
/grub
148 @mcopy
/boot
/grub
/fat_stage1_5 c
:/boot
/grub
149 @echo
"(hd0) boot.img" > bmap
150 @printf
"geometry (hd0) 44 16 63\nroot (hd0,0)\nsetup (hd0)\n" |
/usr
/sbin
/grub
--batch
--device-map
=bmap
151 @printf
"default 0\ntimeout=2\ntitle=MString kernel\nkernel=/boot/grub/kernel.bin" > .
/menu.lst
152 @mcopy .
/menu.lst c
:/boot
/grub
153 @mcopy .
/vmuielf c
:/boot
/grub
/kernel.bin
154 @
rm -f .
/menu.lst ~
/.mtoolsrc bmap
156 @echo
"*********************************************************************************"
157 @echo
" Bootable HD image 'boot.img' was successfilly created."
158 @echo
" Make sure the following lines are present in your 'bochsrc' file:"
159 @echo
" ata0-master: type=disk, path=boot.img, mode=flat, cylinders=44, heads=16, spt=63"
161 @echo
"*********************************************************************************"
165 ifneq ($(NOBUILDIMG
),y
)
166 # Creates a 512 MB bootable ext2 HD image: OS default geometry
167 .
/scripts
/mkimage.sh .
/boot2.img .
/vmuielf
171 $(Q
)$(ECHO
) "#ifndef __VERSION_H__" > $(VERFILE
)
172 $(Q
)$(ECHO
) "#define __VERSION_H__" >> $(VERFILE
)
173 $(Q
)$(ECHO
) >> $(VERFILE
)
174 $(Q
)$(ECHO
) "#define KERNEL_VERSION $(KERNEL_MAJOR_VER)" >> $(VERFILE
)
175 $(Q
)$(ECHO
) "#define KERNEL_SUBVERSION $(KERNEL_MIDDLE_VER)" >> $(VERFILE
)
176 $(Q
)$(ECHO
) "#define KERNEL_RELEASE $(KERNEL_MINOR_VER)" >> $(VERFILE
)
177 $(Q
)$(ECHO
) >> $(VERFILE
)
178 $(Q
)$(ECHO
) "#define KERNEL_RELEASE_NAME \"$(KERNEL_NAME)\"" >> $(VERFILE
)
179 $(Q
)$(ECHO
) >> $(VERFILE
)
180 $(Q
)$(ECHO
) "#endif /* __VERSION_H__ */" >> $(VERFILE
)
183 $(Q
)$(MKDIR
) -p
$(BUILD_ROOT
)/include/config
184 $(Q
)$(MAKE
) -C kconfig conf BUILD_ROOT
=$(BUILD_ROOT
)
185 $(Q
)$(BUILD_ROOT
)/kconfig
/conf
$(BUILD_ROOT
)/kernel
/arch
/Kconfig
188 $(Q
)$(MKDIR
) -p
$(BUILD_ROOT
)/include/config
189 $(Q
)$(MAKE
) mconf
-C kconfig BUILD_ROOT
=$(BUILD_ROOT
)
190 $(Q
)$(BUILD_ROOT
)/kconfig
/mconf
$(BUILD_ROOT
)/kernel
/arch
/Kconfig
191 $(Q
)$(BUILD_ROOT
)/kconfig
/conf
-s
$(BUILD_ROOT
)/kernel
/arch
/Kconfig
194 $(Q
)$(ECHO
) "USAGE: make [action] [OPTIONS] [VARIABLES]"
195 $(Q
)$(ECHO
) " OPTIONS:"
196 $(Q
)$(ECHO
) " VERBOSE=[y/n] Enable/disable verbose mode (default: disabled)"
197 $(Q
)$(ECHO
) " target=<dir> Specify building directory"
198 $(Q
)$(ECHO
) " TOOLCHAIN=<prefix> Specify toolchain prefix"
199 $(Q
)$(ECHO
) " OPTIMIZATION=<level> Specify level of optimization for compiler. (default: -g)"
200 $(Q
)$(ECHO
) " MENUCONFIG_COLOR=<color_theme> Menuconfig color theme. (default: mono)"
201 $(Q
)$(ECHO
) " Customizible variables:"
202 $(Q
)$(ECHO
) " CFLAGS, LDFLAGS, INCLUDE, HOSTCC, HOSTCFLAGS, HOSTLDFLAGS, KERN_CFLAGS"
203 $(Q
)$(ECHO
) " Available actions:"
204 $(Q
)$(ECHO
) " make [config|menuconfig] - configure the kernel"
205 $(Q
)$(ECHO
) " make all - build all"
206 $(Q
)$(ECHO
) " make host - build host utilites"
207 $(Q
)$(ECHO
) " make vmuielf - build kernel image"
208 $(Q
)$(ECHO
) " make image - build runable kvm/qemu/bochs image with mString kernel"
209 $(Q
)$(ECHO
) " make clean - clean directories from object files"
210 $(Q
)$(ECHO
) " make cleanconf - remove config"
211 $(Q
)$(ECHO
) " make distclean - combines two actions above"
212 $(Q
)$(ECHO
) " make help - show this help message."
213 $(Q
)$(ECHO
) " Kernel building example:"
214 $(Q
)$(ECHO
) " 1) without toolchain:"
215 $(Q
)$(ECHO
) " 1.1) Run \"make config\" or \"make menuconfig\" (the second one use libncurses)"
216 $(Q
)$(ECHO
) " 1.2) Run \"make\""
217 $(Q
)$(ECHO
) " 2) with toolchain:"
218 $(Q
)$(ECHO
) " 2.1) Same as (1.1)"
219 $(Q
)$(ECHO
) " 2.2) make TOOLCHAIN=<path-to-your-toolchain>"
220 $(Q
)$(ECHO
) " Example: "
221 $(Q
)$(ECHO
) " % make TOOLCHAIN=/opt/crosstool/gcc-3.4.4-glibc-2.3.4/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-"
225 $(Q
)$(ECHO
) "ERROR: Before building kernel you should configure it"
226 $(Q
)$(ECHO
) "Run make config or << make menuconfig >>."
227 $(Q
)$(ECHO
) "Or run << make help >> to see all available commands and options."