Linux下Makefile的作用是使用8086编译器将bootsect.s和setup.s分别编译成各自执行的模块,使用gcc编译其它linux文件,生成模块system,最后使用tools目录下的build工具,将三者组合成一个可执行的映像image。
在makefile文件当中:
①.ROOT_DEV=dev/hd6指的是创建内核镜像时,所使用的默认文件系统所在的设备。
②.为什么要使用.a和.lib文件?
在大多数时候,由于源文件太多,编译生成的中间目标文件太多,而在链接时需要明显地指出中间目标文件名,这对于编译很不方便,所以,我们要给中间目标文件打个包,在Windows下这种包叫“库文件”(Library File),也就是 .lib 文件,在UNIX下,是Archive File,也就是 .a 文件。
③.解释下面这段代码的含义?
dep:
sed '//#/#/# Dependencies/q' < Makefile > tmp_make
//如果是一个比较大型的工程,你必需清楚哪些C文件包含了哪些头文件,并且,你在加入或删除头文件时,也需要小心地修改Makefile,这是一个很没有维护性的工作。为了避免这种繁重而又容易出错的事情,我们可以使用C/C++编译的一个功能。大多数的C/C++编译器都支持一个“-M”的选项,即自动找寻源文件中包含的头文件,并生成一个依赖关系。
(for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make
cp tmp_make Makefile
(cd fs; make dep)
(cd kernel; make dep)
(cd mm; make dep)
### Dependencies:
init/main.o : init/main.c include/unistd.h include/sys/stat.h /
include/sys/types.h include/sys/times.h include/sys/utsname.h /
include/utime.h include/time.h include/linux/tty.h include/termios.h /
include/linux/sched.h include/linux/head.h include/linux/fs.h /
include/linux/mm.h include/signal.h include/asm/system.h include/asm/io.h /
include/stddef.h include/stdarg.h include/fcntl.h
通过这个makefile文件,可以看到linux 0.11源代码的概貌。