Chinaunix首页 | 论坛 | 博客
  • 博客访问: 180200
  • 博文数量: 37
  • 博客积分: 171
  • 博客等级: 入伍新兵
  • 技术积分: 315
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-13 22:54
个人简介

寻找方向程序猿、攻城狮

文章存档

2023年(1)

2022年(4)

2019年(1)

2018年(1)

2017年(1)

2015年(2)

2014年(19)

2013年(2)

2012年(1)

2011年(5)

分类: LINUX

2014-03-18 17:34:21

在linux kernel 1.0的net目录下查看子目录及文件结构:

  1. [root@localhost net]# ls -R
  2. .:
  3. ddi.c inet Makefile socket.c Space.c unix
  4. ./inet:
  5. arp.c datagram.c dev.h eth.h icmp.h ip.c loopback.c packet.c protocol.c raw.c README route.h skbuff.h sock.h tcp.h udp.c utils.c
  6. arp.h dev.c eth.c icmp.c inet.h ip.h Makefile proc.c protocol.h raw.h route.c skbuff.c sock.c tcp.c timer.c udp.h
  7. ./unix:
  8. Makefile proc.c sock.c unix.h
可以看到net由ddi.c,socket.c和Space.c三个文件,inet和unix两个目录,还有Makefile组成。
暂时不理睬inet和unix目录下的文件,看看Makefile的内容:

  1. # Note! Dependencies are done automagically by 'make dep', which also
  2. # removes any old dependencies. DON'T put your own dependencies here
  3. # unless it's something special (ie not a .c file).
  4. #
  5. # Note 2! The CFLAGS definition is now in the main makefile...
  6. # only these two lines should need to be changed to remove inet sockets.
  7. # (and the inet/tcpip.o in net.o)
  8. SUBDIRS := unix inet
  9. SUBOBJS := $(foreach f,$(SUBDIRS),$f/$f.o)
  10. #SUBOBJS的值为 unix/unix.o inet/inet.o
  11. .c.o:
  12. $(CC) $(CFLAGS) -c $<
  13. .s.o:
  14. $(AS) -o $*.o $<
  15. .c.s:
  16. $(CC) $(CFLAGS) -S $<
  17. #老式makefile中的隐式规则定义
  18. #如果编译目标为xx.o:xx.c则自动引用第一个规则,依此类推
  19. OBJS = Space.o ddi.o socket.o
  20. all: subdirs net.o
  21. net.o: $(OBJS) network.a
  22. $(LD) -r -o net.o $(OBJS) network.a
  23. #将Space.o,ddi.o,socket.o和netowrk.a编译成net.o,net.o再编译进内核中。
  24. network.a: $(SUBOBJS)
  25. rm -f $@
  26. ar rc $@ $(SUBOBJS)
  27. ranlib $@
  28. #将unix/unix.o和inet/inet.o打包成network.a
  29. subdirs: dummy
  30. set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
  31. #进入各个子目录分别编译unix.o和inet.o
  32. dep:
  33. $(CPP) -M *.c > .depend
  34. set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i dep; done
  35. dummy:
  36. #假的target
  37. #
  38. # include a dependency file if one exists
  39. #
  40. ifeq (.depend,$(wildcard .depend))
  41. include .depend
  42. endif
  43. "Makefile" 51L, 1023C
下一篇开始分析源代码


阅读(2438) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~