added script for Grub2 image creation;
[MuString.git] / Makefile
blob1439a8b689a920f01c57a5856fa489ecff0b927f
1 KERNEL_NAME := Quoppa
2 KERNEL_MAJOR_VER := 0
3 KERNEL_MIDDLE_VER := 1
4 KERNEL_MINOR_VER := 2
6 ifndef $(BUILD_ROOT)
7 BUILD_ROOT := $(CURDIR)
8 endif
10 KERNELVERSION := $(KERNEL_MAJOR_VER).$(KERNEL_MIDDLE_VER).$(KERNEL_MINOR_VER)
11 VERFILE := include/version.h
12 OBJECTS :=
13 CC := $(TOOLCHAIN)gcc
14 AR := $(TOOLCHAIN)ar
15 AS := $(TOOLCHAIN)as
16 LD := $(TOOLCHAIN)ld
17 OBJDUMP := $(TOOLCHAIN)objdump
18 OBJCOPY := $(TOOLCHAIN)objcopy
20 HOSTCC := gcc
21 HOSTLD := ld
23 -include .config
25 ifdef CONFIG_ARCH
26 ARCH := $(shell echo $(CONFIG_ARCH) | sed 's|"||g')
27 endif
29 ODIR := mstring_dumps
30 SCRIPTS_DIR := $(BUILD_ROOT)/scripts
31 ARCH_DIR := $(BUILD_ROOT)/kernel/arch/$(ARCH)
32 ARCH_COM_DIR := $(BUILD_ROOT)/kernel/arch/common
34 GREP := grep
35 GMAP := $(SCRIPTS_DIR)/gmap.py
36 MKLINKS := $(SCRIPTS_DIR)/mklinks.sh
37 LN := ln
38 RM := rm
39 CP := cp
40 MKDIR := mkdir
41 ECHO := /bin/echo
43 ifeq ($(VERBOSE),y)
44 Q :=
45 MAKE := make
46 else
47 Q := @
48 MAKE := make -s
49 endif
51 OPTIMIZATION ?= -g
52 CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fomit-frame-pointer -nodefaultlibs \
53 $(OPTIMIZATION) $(KERN_CFLAGS)
55 LDFLAGS += -M
56 INCLUDE += -Iinclude
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)
70 GENERICS += tests
71 endif
73 all: host vmuielf
75 -include kernel/arch/$(ARCH)/Makefile.inc
77 host:
78 $(call echo-header,"kconfig")
79 $(Q)$(MAKE) all -C kconfig BUILD_ROOT=$(BUILD_ROOT)
81 vmuielf: muielf
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))
93 prepare: include/arch
94 $(Q)$(MKDIR) -p $(ODIR)
95 $(Q)$(MKLINKS) clear
96 $(Q)$(MKLINKS) create
98 include/arch:
99 $(Q)$(LN) -s $(BUILD_ROOT)/kernel/arch/$(ARCH)/include $(BUILD_ROOT)/include/arch
101 check_config:
102 ifeq ($(shell [ -f $(BUILD_ROOT)/.config ] && echo "y"),)
103 $(Q)$(MAKE) help_config
104 endif
106 generic_%:
107 $(call echo-header,"$(subst generic_,,$@)")
108 $(Q)$(MAKE) -f rules.mak target=$(subst generic_,,$@)
110 clean_%:
111 $(call echo-header,"Cleaning $(subst clean_,,$@):")
112 $(Q)$(MAKE) -f rules.mak target=$(subst clean_,,$@) clean
114 clean:
115 $(Q)$(RM) -rf $(ODIR)
116 $(Q)$(RM) -f muielf vmuielf boot.img $(BUILD_ROOT)/include/arch
117 $(Q)$(MKLINKS) clear
118 $(Q)$(MAKE) -C. $(addprefix clean_, $(GENERICS))
120 clean_host:
121 $(call echo-header,"Cleaning host")
122 $(Q)$(MAKE) -C kconfig clean
124 cleanconf:
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
131 $(call create_rmap)
133 collect_objects:
134 $(eval OBJECTS := $(call collect_objects))
136 image: vmuielf
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:
143 @mformat c:
144 @mmd c:/boot
145 @mmd c:/boot/grub
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
155 @echo
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"
160 @echo " boot: disk"
161 @echo "*********************************************************************************"
162 endif
164 image2: vmuielf
165 ifneq ($(NOBUILDIMG),y)
166 # Creates a 512 MB bootable ext2 HD image: OS default geometry
167 ./scripts/mkimage.sh ./boot2.img ./vmuielf
168 endif
170 $(VERFILE):
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)
182 config: host
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
187 menuconfig: host
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
193 help:
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-"
222 $(Q)$(ECHO)
224 help_config:
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."
228 $(Q)$(ECHO)
229 $(Q)exit 2