1.1 结构目录
-
cong@msi:/work/os/code/7int$ tree
-
.
-
├── boot
-
│ ├── loader.S
-
│ └── mbr.S
-
├── include
-
│ ├── interrupt.h
-
│ ├── io.h
-
│ ├── print.h
-
│ ├── stdarg.h
-
│ └── stdint.h
-
├── init
-
│ └── main.c
-
├── kernel
-
│ ├── interrupt.c
-
│ ├── kernel.S
-
│ └── Makefile -->每个目录下的Makefile,都编译成一个静态库
-
├── lib
-
│ ├── Makefile -->每个目录下的Makefile,都编译成一个静态库
-
│ ├── printf.c
-
│ └── put_char.S
-
└── Makefile -->总的Makefile,链接所有的静态库与main.o
1.2 顶层的Makefile
-
cong@msi:/work/os/code/7int$ cat Makefile
-
ENTRY_POINT = 0xc0001500
-
AS = nasm
-
CC = gcc
-
CPP =gcc -E -nostdinc -I ./include
-
LD = ld
-
INCLUDE = -I ./include
-
ASFLAGS = -f elf
-
CFLAGS = -Wall $(INCLUDE) -c -m32 -fno-builtin -W -Wstrict-prototypes -Wmissing-prototypes -nostdinc
-
LDFLAGS = -Ttext $(ENTRY_POINT) -m elf_i386 -e main -Map System.map
-
LIBS = lib/lib.a
-
KERNEL= kernel/kernel.a
-
-
all: mbr.bin loader.bin init/kernel.bin
-
mbr.bin:
-
$(AS) ./boot/mbr.S -I ./boot/include/ -o ./boot/mbr.bin
-
loader.bin:
-
$(AS) ./boot/loader.S -I ./boot/include/ -o ./boot/loader.bin
-
init/kernel.bin: init/main.o $(KERNEL) $(LIBS)
-
$(LD) $(LDFLAGS) -o $@ $^ -->把各个目录下的库都链接在一起
-
-
init/main.o: init/main.c
-
$(CC) $(CFLAGS) -c -o $*.o $<
-
-
$(KERNEL):
-
(cd kernel; make)
-
$(LIBS):
-
(cd lib; make)
-
-
clean:
-
-rm /work/os/code/disk.img ./boot/mbr.bin ./boot/loader.bin init/kernel.bin
-
-rm -f Image System.map tmp_make core
-
-rm -f init/*.o boot/*.o
-
(cd kernel;make clean)
-
(cd lib;make clean)
-
-
flash:
-
-rm /work/os/code/disk.img
-
dd if=/dev/zero of=/work/os/code/disk.img bs=1M count=30
-
dd if=./boot/mbr.bin of=/work/os/code/disk.img bs=512 count=1 conv=notrunc
-
dd if=./boot/loader.bin of=/work/os/code/disk.img bs=512 count=5 seek=2 conv=notrunc
-
dd if=./init/kernel.bin of=/work/os/code/disk.img bs=512 count=200 seek=9 conv=notrunc
-
show:
-
echo "show loader.bin"
-
xxd ./loader.bin
-
echo "show disk.img"
-
xxd -seek 0x400 -l 0x200 /work/os/code/disk.img
-
dep: -->这个dep是从linux0.11里面抄来的
-
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
-
(for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make
-
cp tmp_make Makefile
-
(cd kernel; make dep)
-
(cd lib; make dep)
1.2.a 说明
规则里面有三部分: mbr.bin loader.bin init/kernel.bin
其中mbr.bin loader.bin 以后就不用再动了
只需要init/kernel.bin需要改动
1.3 每个目录下的Makefile
-
cong@msi:/work/os/code/7int$ cat lib/Makefile
-
AS = nasm
-
CC = gcc
-
CPP =gcc -E -nostdinc -I ../include
-
LD = ld
-
INCLUDE= -I ../include
-
ASFLAGS = -f elf
-
CFLAGS = -Wall $(INCLUDE) -c -m32 -fno-builtin -W -Wstrict-prototypes -Wmissing-prototypes -nostdinc
-
LDFLAGS = -m elf_i386
-
-
TARGET = lib.a
-
OBJS= put_char.o printf.o -->以后直接在这儿添加就行了
-
-
.c.o:
-
$(CC) $(CFLAGS) -c -o $*.o $<
-
.S.o:
-
$(AS) $(ASFLAGS) -o $*.o $<
-
-
all: $(TARGET)
-
$(TARGET):$(OBJS)
-
$(AR) rcs $(TARGET) $(OBJS) -->把该目录下的所有目标文件都打包成库,然后在顶层的Makefile中链接成kernel.bin
-
clean:
-
rm -f core *.o *.a tmp_make
-
for i in *.c;do rm -f `basename $$i .c`.s;done
-
-
dep: -->这个dep是从linux0.11里面抄来的
-
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
-
(for i in *.c;do $(CPP) -M $$i;done) >> tmp_make
-
cp tmp_make Makefile
1.3.a 说明
以后新添加文件进行编译时,如要在lib下添加test.c, 只需要OBJS里面加入test.o就可以了,其它的都不用动
1.4 代码打包
7int_Makefile.rar (下载后改名为7int_Makefile.tar.gz)
阅读(923) | 评论(0) | 转发(0) |