#练习一 Makefile
#1.1 OS镜像文件ucore.img 是如何一步步生成的?
- cc kern/init/init.c
- cc kern/libs/readline.c
- cc kern/libs/stdio.c
- cc kern/debug/kdebug.c
- cc kern/debug/kmonitor.c
- cc kern/debug/panic.c
kern/debug/panic.c: In function ‘__panic’:
kern/debug/panic.c:27:5: warning: implicit declaration of function ‘print_stackframe’ [-Wimplicit-function-declaration]
print_stackframe();
^ - cc kern/driver/clock.c
- cc kern/driver/console.c
- cc kern/driver/intr.c
- cc kern/driver/picirq.c
- cc kern/trap/trap.c
- cc kern/trap/trapentry.S
- cc kern/trap/vectors.S
- cc kern/mm/pmm.c
- cc libs/printfmt.c
- cc libs/string.c
- ld bin/kernel
- cc boot/bootasm.S
- cc boot/bootmain.c
- cc tools/sign.c
tools/sign.c: In function ‘main’:
tools/sign.c:17:5: warning: unknown conversion type character ‘l’ in format [-Wformat=]
printf("’%s’ size: %lld bytes\n", argv[1], (long long)st.st_size);
^
tools/sign.c:17:5: warning: too many arguments for format [-Wformat-extra-args]
tools/sign.c:19:9: warning: unknown conversion type character ‘l’ in format [-Wformat=]
fprintf(stderr, “%lld >> 510!!\n”, (long long)st.st_size);
^
tools/sign.c:19:9: warning: too many arguments for format [-Wformat-extra-args] - ld bin/bootblock
‘obj/bootblock.out’ size: 480 bytes
build 512 bytes boot sector: ‘bin/bootblock’ success!
其中Makefile文件中include tools/function.mk 其中定义了一些Makefile中用到的函数
生成ucore.img 需要kernel和bootblock 如下:
create ucore.img
UCOREIMG := $(call totarget,ucore.img)
$(UCOREIMG): $(kernel) $(bootblock)
( V ) d d i f = / d e v / z e r o o f = (V)dd if=/dev/zero of= (V)ddif=/dev/zeroof=@ count=10000
( V ) d d i f = (V)dd if= (V)ddif=(bootblock) of=$@ conv=notrunc
( V ) d d i f = (V)dd if= (V)ddif=(kernel) of=$@ seek=1 conv=notrunc
$(call create_target,ucore.img)
kernel编译链接:
#-------------------------------------------------------------------
#kernel
#kernel中头文件目录
KINCLUDE += kern/debug/
kern/driver/
kern/trap/
kern/mm/
#kernel的源代码目录
KSRCDIR += kern/init
kern/libs
kern/debug
kern/driver
kern/trap
kern/mm
#在编译选项中添加头文件包含目录
KCFLAGS += ( a d d p r e f i x − I , (addprefix -I, (addprefix−I,(KINCLUDE))
#调用function.mk中的add_files_cc函数,将kernel的全部源文件编译,将源文件和编译生成的OBJ文件加入kernel包(packet)中
( c a l l a d d f i l e s c c , (call add_files_cc, (calladdfilescc,(call listf_cc, ( K S R C