����5‑1 linux/Makefile�ļ�
1 #
2 # if you want the ram-disk device, define this to be the
3 # size in blocks.
4 #
# �����Ҫʹ��RAM��(RAMDISK)�豸�Ļ��Ͷ����Ĵ�С������Ĭ��RAMDISKû�ж��壨ע�͵��ˣ���
# ����gcc����ʱ�����ѡ��'-DRAMDISK=512'���μ���13�С�
5 RAMDISK = #-DRAMDISK=512
7 AS86 =as86 -0 -a # 8086���������������������б���Ľ��ܡ�����IJ�������ֱ�
8 LD86 =ld86 -0 # �ǣ�-0 ����8086Ŀ�����-a ������gas��gld���ּ��ݵĴ��롣
10 AS =gas # GNU���������������������б���Ľ��ܡ�
11 LD =gld
# ������GNU������gld����ʱ�õ���ѡ������ǣ�-s ����ļ���ʡ�����еķ�����Ϣ��-x ɾ��
# ���оֲ����ţ�-M ��ʾ��Ҫ�ڱ�����豸(��ʾ��)�ϴ�ӡ����ӳ��(link map)����ָ�����ӳ���
# ������һ���ڴ��ַӳ�������г��˳����װ�뵽�ڴ��е�λ����Ϣ������������������Ϣ��
# • Ŀ���ļ���������Ϣӳ�䵽�ڴ��е�λ�ã�
# • ����������η��ã�
# • �����а����������ļ���Ա�������õķ��š�
12 LDFLAGS =-s -x -M
# gcc��GNU C���������������UNIX��Ľű�(script)������ԣ������ö���ı�ʶ��ʱ������ǰ
# �����$���Ų���������ס��ʶ����
13 CC =gcc $(RAMDISK)
# ����ָ��gccʹ�õ�ѡ�ǰһ������'\'���ű�ʾ��һ�������С�ѡ���Ϊ��-Wall ��ӡ����
# ������Ϣ��-O �Դ�������Ż���'-f��־'ָ��������صı����־������-fstrength-reduce��
# ���Ż�ѭ����䣻-fcombine-regs����ָ������������ϱ���ΰѸ���һ���Ĵ�������һ���Ĵ�
# ����ָ�������һ��-fomit-frame-pointer ָ����������ָ֡�루Frame pointer���ĺ�����Ҫ
# ��ָ֡�뱣���ڼĴ����С������ں����п��Ա����ָ֡��IJ�����ά����-mstring-insns ��
# Linus��ѧϰgcc������ʱΪgcc���ӵ�ѡ�����gcc-1.40�ڸ��ƽṹ�Ȳ���ʱʹ��386 CPU��
# �ַ���ָ�����ȥ����
14 CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
15 -fcombine-regs -mstring-insns
# ����cpp��gcc��ǰ(Ԥ)����������ǰ���������ڽ��г����еĺ��滻�������������봦���Լ�
# ������ָ���ļ������ݣ�����ʹ��'#include'ָ�����ļ�����������Դ�����ļ��������Է���'#'
# ��ʼ���о���Ҫ��ǰ���������д���������������'#define'����ĺ궼��ʹ���䶨�岿���滻����
# ����������'#if'��'#ifdef'��'#ifndef'��'#endif'�������б�������ȷ���Ƿ������ָ����Χ��
# ����䡣
# '-nostdinc -Iinclude'�����Dz�Ҫ������ͷ�ļ�Ŀ¼�е��ļ���������ϵͳ/usr/include/Ŀ¼
# �µ�ͷ�ļ�������ʹ��'-I'ѡ��ָ����Ŀ¼�������ڵ�ǰĿ¼������ͷ�ļ���
16 CPP =cpp -nostdinc -Iinclude
18 #
19 # ROOT_DEV specifies the default root-device when making the image.
20 # This can be either FLOPPY, /dev/xxxx or empty, in which case the
21 # default of /dev/hd6 is used by 'build'.
22 #
# ROOT_DEVָ���ڴ����ں�ӳ��(image)�ļ�ʱ��ʹ�õ�Ĭ�ϸ��ļ�ϵͳ��
# �ڵ��豸�������������(FLOPPY)��/dev/xxxx���߸ɴ���ţ�����ʱ
# build������tools/Ŀ¼�У���ʹ��Ĭ��ֵ/dev/hd6��
#
# ����/dev/hd6��Ӧ��2��Ӳ�̵ĵ�1������������Linus����Linux�ں�ʱ�Լ��Ļ����ϸ�
# �ļ�ϵͳ���ڵķ���λ�á�/dev/hd2��ʾ�ѵ�1��Ӳ�̵ĵ�2��������������������
23 ROOT_DEV=/dev/hd6
24 SWAP_DEV=/dev/hd2
# ������kernelĿ¼��mmĿ¼��fsĿ¼��������Ŀ������ļ���Ϊ�˷������������ォ������
# ARCHIVES���鵵�ļ�����ʶ����ʾ��
26 ARCHIVES=kernel/kernel.o mm/mm.o fs/fs.o
# ����ַ��豸���ļ���'.a'��ʾ���ļ��Ǹ��鵵�ļ���Ҳ�������������ִ�ж����ƴ����ӳ���
# ���ϵĿ��ļ���ͨ������GNU��ar�������ɡ�ar��GNU�Ķ������ļ������������ڴ�������
# �Լ��ӹ鵵�ļ��г�ȡ�ļ���
27 DRIVERS =kernel/blk_drv/blk_drv.a kernel/chr_drv/chr_drv.a
28 MATH =kernel/math/math.a # ��ѧ������ļ���
29 LIBS =lib/lib.a # ��lib/Ŀ¼�е��ļ����������ɵ�ͨ�ÿ��ļ���
# ������make��ʽ����ʽ��������ָʾmake���������������е�'.c'�ļ���������'.s'
# ������':'��ʾ�����Ǹù������������ʾ��gcc����ǰ��CFLAGS��ָ����ѡ���Լ���ʹ
# ��include/Ŀ¼�е�ͷ�ļ������ʵ��ر�����л���ֹͣ��-S�����Ӷ�����������ĸ���C
# �ļ���Ӧ�Ļ��������ʽ�Ĵ����ļ���Ĭ��������������Ļ������ļ���ԭC�ļ���ȥ��'.c'��
# �ټ���'.s'����'-o'��ʾ���������ļ�����ʽ������'$*.s'����'$@'�����Զ�Ŀ�������'$<'
# ������һ���Ⱦ����������T�Ƿ�������'*.c'���ļ���
# ������3����ͬ����ֱ����ڲ�ͬ�IJ���Ҫ����Ŀ����.s�ļ�����Դ�ļ���.c�ļ����ʹ
# �õ�һ��������Ŀ¼��.o����ԭ�ļ���.s����ʹ�õ�2��������Ŀ����.o�ļ���ԭ�ļ�
# ��c�ļ������ֱ��ʹ�õ�3������
31 .c.s:
32 $(CC) $(CFLAGS) \
33 -nostdinc -Iinclude -S -o $*.s $<
# ��ʾ������.s�������ļ������.oĿ���ļ��� �����ʾʹ��gas������������������.o
# Ŀ���ļ���-c ��ʾֻ������࣬�����������Ӳ�����
34 .s.o:
35 $(AS) -c -o $*.o $<
# �������棬*.c�ļ�-��*.oĿ���ļ��������ʾʹ��gcc��C�����ļ������Ŀ���ļ��������ӡ�
36 .c.o:
37 $(CC) $(CFLAGS) \
38 -nostdinc -Iinclude -c -o $*.o $<
# ����'all'��ʾ����Makefile��֪������Ŀ�ꡣ���T��Image�ļ����������ɵ�Image�ļ�
# ��������������ӳ���ļ�bootimage��������д�����̾Ϳ���ʹ�ø���������Linuxϵͳ�ˡ���
# Linux�½�Imageд�����̵�����μ�46�С�DOSϵͳ�¿���ʹ������rawrite.exe��
40 all: Image
# ˵��Ŀ�꣨Image�ļ�������ð�ź����4��Ԫ�ز������ֱ���boot/Ŀ¼�е�bootsect��setup
# �ļ���tools/Ŀ¼�е�system��build�ļ���42--43������ִ�е����42�б�ʾʹ��toolsĿ
# ¼�µ�build���߳��������˵��������ɣ���bootsect��setup��system�ļ���$(ROOT_DEV)
# Ϊ���ļ�ϵͳ�豸��װ���ں�ӳ���ļ�Image����43�е�syncͬ����������ʹ�������������д��
# �����³����顣
42 Image: boot/bootsect boot/setup tools/system tools/build
43 tools/build boot/bootsect boot/setup tools/system $(ROOT_DEV) \
44 $(SWAP_DEV) > Image
45 sync
# ��ʾdisk���Ŀ��Ҫ��Image������ddΪUNIX���������һ���ļ�������ѡ�����ת����
# ʽ����bs=��ʾһ�ζ�/д���ֽ�����if=��ʾ������ļ���of=��ʾ��������ļ�������/dev/PS0��
# ָ��һ������������(�豸�ļ�)����Linuxϵͳ��ʹ��/dev/fd0��
47 disk: Image
48 dd bs=8192 if=Image of=/dev/PS0
50 tools/build: tools/build.c # ��toolsĿ¼�µ�build.c��������ִ�г���build��
51 $(CC) $(CFLAGS) \
52 -o tools/build tools/build.c # ��������ִ�г���build�����
54 boot/head.o: boot/head.s # �������������.s.o��������head.oĿ���ļ���
# ��ʾtoolsĿ¼�е�system�ļ�Ҫ��ð���ұ����е�Ԫ�����ɡ�56--61��������system�����
# ���� > System.map ��ʾgld��Ҫ������ӳ���ض�������System.map�ļ��С�
# ����System.map�ļ�����;�μ�ע�ͺ��˵����
56 tools/system: boot/head.o init/main.o \
57 $(ARCHIVES) $(DRIVERS) $(MATH) $(LIBS)
58 $(LD) $(LDFLAGS) boot/head.o init/main.o \
59 $(ARCHIVES) \
60 $(DRIVERS) \
61 $(MATH) \
62 $(LIBS) \
63 -o tools/system > System.map
# ��ѧЭ���������ļ�math.a��64���ϵ�����ʵ�֣�����kernel/math/Ŀ¼������make���߳���
65 kernel/math/math.a:
66 (cd kernel/math; make)
68 kernel/blk_drv/blk_drv.a: # ���ɿ��豸���ļ�blk_drv.a�����к��п��ض�λĿ���ļ���
69 (cd kernel/blk_drv; make)
71 kernel/chr_drv/chr_drv.a: # �����ַ��豸�����ļ�chr_drv.a��
72 (cd kernel/chr_drv; make)
74 kernel/kernel.o: # �ں�Ŀ��ģ��kernel.o
75 (cd kernel; make)
77 mm/mm.o: # �ڴ����ģ��mm.o
78 (cd mm; make)
80 fs/fs.o: # �ļ�ϵͳĿ��ģ��fs.o
81 (cd fs; make)
83 lib/lib.a: # �⺯��lib.a
84 (cd lib; make)
86 boot/setup: boot/setup.s # ���↑ʼ��������ʹ��8086����������
87 $(AS86) -o boot/setup.o boot/setup.s # ��setup.s�ļ����б�������setup�ļ���
88 $(LD86) -s -o boot/setup boot/setup.o # -s ѡ���ʾҪȥ��Ŀ���ļ��еķ�����Ϣ��
90 boot/setup.s: boot/setup.S include/linux/config.h # ִ��C����Ԥ�������滻*.S��
91 $(CPP) -traditional boot/setup.S -o boot/setup.s # ���еĺ����ɶ�Ӧ��*.s�ļ���
92
93 boot/bootsect.s: boot/bootsect.S include/linux/config.h
94 $(CPP) -traditional boot/bootsect.S -o boot/bootsect.s
95
96 boot/bootsect: boot/bootsect.s # ͬ�ϡ�����bootsect.o���������顣
97 $(AS86) -o boot/bootsect.o boot/bootsect.s
98 $(LD86) -s -o boot/bootsect boot/bootsect.o
# ��ִ��'make clean'ʱ���ͻ�ִ��98--103���ϵ����ȥ�����б����������ɵ��ļ���
# 'rm'���ļ�ɾ�����ѡ��-f�����Ǻ��Բ����ڵ��ļ������Ҳ���ʾɾ����Ϣ��
100 clean:
101 rm -f Image System.map tmp_make core boot/bootsect boot/setup \
102 boot/bootsect.s boot/setup.s
103 rm -f init/*.o tools/system tools/build boot/*.o
104 (cd mm;make clean) # ����mm/Ŀ¼��ִ�и�Ŀ¼Makefile�ļ��е�clean����
105 (cd fs;make clean)
106 (cd kernel;make clean)
107 (cd lib;make clean)
# �ù�������ִ�������clean����Ȼ���linux/Ŀ¼����ѹ��������'backup.Z'ѹ���ļ���
# 'cd .. '��ʾ�˵�linux/����һ��������Ŀ¼��'tar cf - linux'��ʾ��linux/Ŀ¼ִ��tar�鵵
# ����'-cf'��ʾ��Ҫ�����µĹ鵵�ļ� '| compress -'��ʾ��tar�����ִ��ͨ���ܵ�����('|')
# ���ݸ�ѹ������compress������ѹ�������������backup.Z�ļ���
109 backup: clean
110 (cd .. ; tar cf - linux | compress - > backup.Z)
111 sync # ��ʹ�������������д�̲����´��̳����顣
113 dep:
# ��Ŀ���������ڲ������ļ�֮���������ϵ��������Щ������ϵ��Ϊ����make������������ȷ��
# �Ƿ���Ҫ�ؽ�һ��Ŀ������統ij��ͷ�ļ����Ķ�����make����ͨ�����ɵ�������ϵ������
# �������ͷ�ļ��йص�����*.c�ļ������巽�����£�
# ʹ���ַ����༭����sed��Makefile�ļ������T�DZ��ļ������д��������Ϊɾ����Makefile
# �ļ���'### Dependencies'�к���������У���ɾ���������122��ʼ���ļ�ĩ�������У�������
# һ����ʱ�ļ�tmp_make��Ҳ��114�е����ã���Ȼ���ָ��Ŀ¼�£�init/����ÿһ��C�ļ�����ʵ
# ֻ��һ���ļ�main.c��ִ��gccԤ������������־'-M'����Ԥ��������cpp�������ÿ��Ŀ���ļ�
# ����ԵĹ�������Щ�������make�������ÿһ��Դ�ļ���Ԥ������������һ��������
# �����ʽ������ӦԴ�����ļ���Ŀ���ļ���������������ϵ������Դ�ļ��а���������ͷ�ļ��б���
# Ȼ���Ԥ������������ӵ���ʱ�ļ�tmp_make�У������ʱ�ļ����Ƴ��µ�Makefile�ļ���
# 115���ϵ�'$$i'ʵ������'$($i) '������'$i'�����ǰ���shell����'i'��ֵ��
114 sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
115 (for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make
116 cp tmp_make Makefile
117 (cd fs; make dep) # ��fs/Ŀ¼�µ�Makefile�ļ�Ҳ��ͬ���Ĵ�����
118 (cd kernel; make dep)
119 (cd mm; make dep)
121 ### Dependencies:
122 init/main.o : init/main.c include/unistd.h include/sys/stat.h \
123 include/sys/types.h include/sys/time.h include/time.h include/sys/times.h \
124 include/sys/utsname.h include/sys/param.h include/sys/resource.h \
125 include/utime.h include/linux/tty.h include/termios.h include/linux/sched.h \
126 include/linux/head.h include/linux/fs.h include/linux/mm.h \
127 include/linux/kernel.h include/signal.h include/asm/system.h \
128 include/asm/io.h include/stddef.h include/stdarg.h include/fcntl.h \
129 include/string.h