binutils-2.18/ld/Makefile分析

来源:互联网 发布:java软件培训机构 编辑:程序博客网 时间:2024/05/24 01:02

 

快乐虾

http://blog.csdn.net/lights_joy/

lights@hb165.com

 

本文适用于

binutils-2.18

configure –target=bfin-uclinux-gnu

Blackfin系列DSP

Cygwin gcc 3.4.4

 

欢迎转载,但请保留作者信息

 

 

1       ld/Makefile

这个文件由主控Makefile调用configure脚本生成并执行make操作。要求生成的目标为all

1.1    all

Makefile中的第一个目标就是all

all: config.h

       $(MAKE) $(AM_MAKEFLAGS) all-recursive

all-recursive这个目标的生成是由RECURSIVE_TARGETS来完成的。

RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive /

       html-recursive info-recursive install-data-recursive /

       install-exec-recursive install-info-recursive /

       install-recursive installcheck-recursive installdirs-recursive /

       pdf-recursive ps-recursive uninstall-info-recursive /

       uninstall-recursive

# This directory's subdirectories are mostly independent; you can cd

# into them and run `make' without going through this Makefile.

# To change the values of `make' variables: instead of editing Makefiles,

# (1) if the variable is set in `config.status', edit `config.status'

#     (which will cause the Makefiles to be regenerated when you run `make');

# (2) otherwise, pass the desired values on the `make' command line.

$(RECURSIVE_TARGETS):

       @failcom='exit 1'; /

       for f in x $$MAKEFLAGS; do /

         case $$f in /

           *=* | --[!k]*);; /

           *k*) failcom='fail=yes';; /

         esac; /

       done; /

       dot_seen=no; /

       target=`echo $@ | sed s/-recursive//`; /

       list='$(SUBDIRS)'; for subdir in $$list; do /

         echo "Making $$target in $$subdir"; /

         if test "$$subdir" = "."; then /

           dot_seen=yes; /

           local_target="$$target-am"; /

         else /

           local_target="$$target"; /

         fi; /

         (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) /

         || eval $$failcom; /

       done; /

       if test "$$dot_seen" = "no"; then /

         $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; /

       fi; test -z "$$fail"

在这段脚本中将分别进入各子目录并执行make xxx操作,xxx-recusive目标的前面一部分。

在此略过子目录不做分析。当在ld目录下执行all-recursive操作时,上述脚本转而执行all-am目标,因此下面转而分析all-am目标。这条规则定义为:

all-am: Makefile $(PROGRAMS) $(MANS) config.h

PROGRAMS = $(noinst_PROGRAMS)

noinst_PROGRAMS = ld-new$(EXEEXT)

MANS = $(man_MANS)

man_MANS = ld.1

因此这个目标实际依赖于ld-new$(EXEEXT),它的规则定义为:

ld-new$(EXEEXT): $(ld_new_OBJECTS) $(ld_new_DEPENDENCIES)

       @rm -f ld-new$(EXEEXT)

       $(LINK) $(ld_new_LDFLAGS) $(ld_new_OBJECTS) $(ld_new_LDADD) $(LIBS)

在生成所有的.o文件后,这段脚本将之链接为ld-new.exe

1.1.1   $(ld_new_OBJECTS)

这个变量定义为:

ld_new_OBJECTS = $(am_ld_new_OBJECTS)

am_ld_new_OBJECTS = ldgram.$(OBJEXT) ldlex.$(OBJEXT) lexsup.$(OBJEXT) /

       ldlang.$(OBJEXT) mri.$(OBJEXT) ldctor.$(OBJEXT) /

       ldmain.$(OBJEXT) ldwrite.$(OBJEXT) ldexp.$(OBJEXT) /

       ldemul.$(OBJEXT) ldver.$(OBJEXT) ldmisc.$(OBJEXT) /

       ldfile.$(OBJEXT) ldcref.$(OBJEXT) sha1.$(OBJEXT)

因而有以下依赖关系:

1.1.1.1             ldgram.$(OBJEXT)

这条规则定义为:

ldgram.o:

       $(COMPILE) -c $< $(NO_WERROR)

同时有以下依赖关系:

ldgram.o: ldgram.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h ld.h ldexp.h ldver.h ldlang.h ldfile.h /

  ldemul.h ldmisc.h ldmain.h mri.h ldctor.h ldlex.h

直接编译即可。

1.1.1.2             ldlex.$(OBJEXT)

这条规则定义为:

ldlex.o:

       $(COMPILE) -c $< $(NO_WERROR)

同时有以下依赖关系:

ldlex.o: ldlex.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/safe-ctype.h $(INCDIR)/bfdlink.h ld.h ldmisc.h /

  ldexp.h ldlang.h ldgram.h ldfile.h ldlex.h ldmain.h /

  $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h

直接编译即可。

 

1.1.1.3             lexsup.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

lexsup.o: lexsup.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  ../bfd/bfdver.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/safe-ctype.h $(INCDIR)/bfdlink.h ld.h ldmain.h /

  ldmisc.h ldexp.h ldlang.h ldgram.h ldlex.h ldfile.h /

  ldver.h ldemul.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h

直接编译即可。

 

1.1.1.4             ldlang.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldlang.o: ldlang.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h /

  $(INCDIR)/obstack.h $(INCDIR)/bfdlink.h ld.h ldmain.h /

  ldexp.h ldlang.h ldgram.h ldlex.h ldmisc.h ldctor.h /

  ldfile.h ldemul.h $(INCDIR)/fnmatch.h $(INCDIR)/demangle.h /

  $(INCDIR)/libiberty.h $(INCDIR)/hashtab.h

直接编译即可。

 

1.1.1.5             mri.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

mri.o: mri.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  ld.h ldexp.h ldlang.h ldmisc.h mri.h ldgram.h $(INCDIR)/libiberty.h /

  $(INCDIR)/ansidecl.h

直接编译即可。

 

1.1.1.6             ldctor.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldctor.o: ldctor.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h ldexp.h /

  ldlang.h ldmisc.h ldgram.h ldmain.h ldctor.h

直接编译即可。

 

1.1.1.7             ldmain.$(OBJEXT)

这条规则定义为:

ldmain.o: ldmain.c config.status

       $(COMPILE) -c -DDEFAULT_EMULATION='"$(EMUL)"' /

         -DSCRIPTDIR='"$(scriptdir)"' -DBINDIR='"$(bindir)"' /

         -DTOOLBINDIR='"$(tooldir)/bin"' /

         -DTARGET='"bfin-unknown-uclinux-gnu"' -DTARGET_SYSTEM_ROOT=/"/" /

         $(srcdir)/ldmain.c

还有以下的依赖关系:

ldmain.o: ldmain.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/safe-ctype.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/progress.h $(INCDIR)/bfdlink.h $(INCDIR)/filenames.h /

  ld.h ldmain.h ldmisc.h ldwrite.h ldexp.h ldlang.h ldgram.h /

  ldlex.h ldfile.h ldemul.h ldctor.h

直接编译即可。

 

1.1.1.8             ldwrite.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldwrite.o: ldwrite.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/safe-ctype.h ld.h ldexp.h ldlang.h ldwrite.h /

  ldmisc.h ldgram.h ldmain.h

直接编译即可。

 

1.1.1.9             ldexp.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldexp.o: ldexp.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h ld.h ldmain.h ldmisc.h ldexp.h /

  ldlex.h ldgram.h ldlang.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/safe-ctype.h

直接编译即可。

 

1.1.1.10       ldemul.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldemul.o: ldemul.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h ld.h ldmisc.h ldexp.h ldlang.h /

  ldfile.h ldemul.h ldmain.h ldemul-list.h

在这里ldemul-list.h文件需要动态生成,规则如下:

ldemul-list.h: Makefile

       (echo "/* This file is automatically generated.  DO NOT EDIT! */";/

       for f in `echo " " ${EMULATION_OFILES} "" /

        | sed -e 's/ e/ ld/g' -e 's/ ld/ /g' -e 's/[.]o//g'`; do /

           echo "extern ld_emulation_xfer_type ld_$${f}_emulation;"; /

       done;/

       echo "";/

       echo "#define EMULATION_LIST //";/

       for f in `echo " " ${EMULATION_OFILES} "" /

        | sed -e 's/ e/ ld/g' -e 's/ ld/ /g' -e 's/[.]o//g'`; do /

           echo "  &ld_$${f}_emulation, //"; /

       done;/

       echo "  0") >ldemul-tmp.h

       mv ldemul-tmp.h ldemul-list.h

生成此文件后直接编译即可。

 

1.1.1.11       ldver.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldver.o: ldver.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  ../bfd/bfdver.h ld.h ldver.h ldexp.h ldlang.h ldfile.h /

  ldemul.h ldmain.h

直接编译即可。

 

1.1.1.12       ldmisc.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldmisc.o: ldmisc.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/demangle.h $(INCDIR)/libiberty.h ld.h ldmisc.h /

  ldexp.h ldlang.h ldgram.h ldlex.h ldmain.h ldfile.h /

  $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h /

  $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h

直接编译即可。

 

1.1.1.13       ldfile.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldfile.o: ldfile.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h ldmisc.h /

  ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h ldlex.h /

  ldemul.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/filenames.h

直接编译即可。

 

1.1.1.14       ldcref.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

ldcref.o: ldcref.c sysdep.h config.h $(INCDIR)/fopen-same.h /

  ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h /

  $(INCDIR)/bfdlink.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h /

  $(INCDIR)/demangle.h $(INCDIR)/libiberty.h $(INCDIR)/objalloc.h /

  ld.h ldmain.h ldmisc.h ldexp.h ldlang.h

直接编译即可。

 

1.1.1.15       sha1.$(OBJEXT)

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

同时有以下依赖关系:

sha1.o: sha1.c config.h sha1.h

直接编译即可。

 

1.1.2   $(ld_new_DEPENDENCIES)

这个变量定义为:

ld_new_DEPENDENCIES = $(EMULATION_OFILES) $(EMUL_EXTRA_OFILES) $(BFDLIB) $(LIBIBERTY) $(LIBINTL_DEP)

EMUL_EXTRA_OFILES =

EMULATION_OFILES =  eelf32bfin.o eelf32bfinfd.o

因而有以下依赖关系。

1.1.2.1             eelf32bfin.o

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

但是eelf32bfin.c则需要动态生成:

eelf32bfin.c: $(srcdir)/emulparams/bfin.sh /

  $(ELF_DEPS) /

  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}

       ${GENSCRIPTS} elf32bfin "$(tdir_elf32bfin)" bfin

生成这个c文件后将之编译为.o文件。

1.1.2.2             eelf32bfinfd.o

这个目标由通用规则生成:

.c.o:

       $(COMPILE) -c $<

但是eelf32bfinfd.c则需要动态生成:

eelf32bfinfd.c: $(srcdir)/emulparams/elf32bfinfd.sh $(srcdir)/emulparams/bfin.sh /

  $(ELF_DEPS) /

  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}

       ${GENSCRIPTS} elf32bfinfd "$(tdir_elf32bfinfd)" elf32bfinfd

生成这个c文件后将之编译为.o文件。

 

2       目标生成顺序

以下是所有目标的生成顺序:

ld/Makefile: info-recursive: begin

ld/Makefile: info-recursive: end

ld/Makefile: all: begin

ld/Makefile: all-recursive: begin

ld/Makefile: ldgram.o: begin

ld/Makefile: ldgram.o: end

ld/Makefile: ldlex.o: begin

ld/Makefile: ldlex.o: end

ld/Makefile: lexsup.o: begin

ld/Makefile: lexsup.o: end

ld/Makefile: ldlang.o: begin

ld/Makefile: ldlang.o: end

ld/Makefile: mri.o: begin

ld/Makefile: mri.o: end

ld/Makefile: ldctor.o: begin

ld/Makefile: ldctor.o: end

ld/Makefile: ldmain.o: begin

ld/Makefile: ldmain.o: end

ld/Makefile: ldwrite.o: begin

ld/Makefile: ldwrite.o: end

ld/Makefile: ldexp.o: begin

ld/Makefile: ldexp.o: end

ld/Makefile: ldemul-list.h: begin

ld/Makefile: ldemul-list.h: end

ld/Makefile: ldemul.o: begin

ld/Makefile: ldemul.o: end

ld/Makefile: ldver.o: begin

ld/Makefile: ldver.o: end

ld/Makefile: ldmisc.o: begin

ld/Makefile: ldmisc.o: end

ld/Makefile: ldfile.o: begin

ld/Makefile: ldfile.o: end

ld/Makefile: ldcref.o: begin

ld/Makefile: ldcref.o: end

ld/Makefile: sha1.o: begin

ld/Makefile: sha1.o: end

ld/Makefile: eelf32bfin.c: begin

ld/Makefile: eelf32bfin.c: end

ld/Makefile: eelf32bfin.o: begin

ld/Makefile: eelf32bfin.o: end

ld/Makefile: eelf32bfinfd.c: begin

ld/Makefile: eelf32bfinfd.c: end

ld/Makefile: eelf32bfinfd.o: begin

ld/Makefile: eelf32bfinfd.o: end

ld/Makefile: ld-new.exe: begin

ld/Makefile: ld-new.exe: end

ld/Makefile: all-recursive: end

ld/Makefile: all: end

3       参考资料

binutils-2.18/libiberty/Makefile分析2008-8-27

binutils-2.18/bfd/Makefile分析(2008-8-28)

binutils-2.18/gprof/Makefile分析(2008-8-29)