网站公告列表

  没有公告

加入收藏
设为首页
联系本站
您现在的位置: AnalogCN安诺电子 >> 文章 >> 技术交流 >> 文章正文
  host-i686-pc-cygwin/libiberty/Makefile解析           ★★★ 【字体:
host-i686-pc-cygwin/libiberty/Makefile解析
作者:快乐虾    文章来源:http://blog.csdn.net/lights_joy    点击数:    更新时间:2008-8-22    

cygwin gcc 3.4.4环境下构建交叉编译器bfin-uclinux-gcc时,首先执行的是configure –target=bfin-uclinux-gnu命令,然后执行make操作,它将创建host-i686-pc-cygwin/libiberty子目录,并调用libiberty/configure脚本生成Makefile,然后在主控Makefile中调用make生成目标,此时传递进来的目标为all

本文就是分析这个动态生成的host-i686-pc-cygwin/libiberty/Makefile

1.1    all

# FIXME: add info once we're sure it works for everyone.

all: stamp-picdir $(TARGETLIB) needed-list required-list all-subdir

       @: $(MAKE) ; exec $(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=all

在这里TARGETLIB的定义为:

TARGETLIB = ./libiberty.a

stamp-picdir这个依赖关系只是简单的创建一个stamp-picdir的文件,没有其它的操作。

$(TARGETLIB)这个依赖关系将生成libiberty.a所需要的所有.o文件。

needed-list这个依赖关系将生成一个叫needed-list,内容为空的文件。

required-list这个依赖关系将生成一个叫required-list的文件。

all-subdir这个依赖关系将进入testsuite子目录并进行make操作。

1.2    stamp-picdir

这是一个最终目标:

stamp-picdir:

       if [ x"$(PICFLAG)" != x ] && [ ! -d pic ]; then \

         mkdir pic; \

       else true; fi

       touch stamp-picdir

在这里PICFLAG的定义为:

PICFLAG =

它将生成一个stamp-picdir的文件,当然,这个文件没有任何内容。

 

1.3    $(TARGETLIB)

这个目标定义为:

$(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)

       -rm -f $(TARGETLIB) pic/$(TARGETLIB)

       $(AR) $(AR_FLAGS) $(TARGETLIB) \

         $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)

       $(RANLIB) $(TARGETLIB)

       if [ x"$(PICFLAG)" != x ]; then \

         cd pic; \

         $(AR) $(AR_FLAGS) $(TARGETLIB) \

           $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \

         $(RANLIB) $(TARGETLIB); \

         cd ..; \

       else true; fi

在这里TARGETLIB的定义为:

TARGETLIB = ./libiberty.a

REQUIRED_OFILES定义为:

# These are always included in the library.  The first four are listed

# first and by compile time to optimize parallel builds.

REQUIRED_OFILES = ./regex.o ./cplus-dem.o ./cp-demangle.o ./md5.o  \

       ./alloca.o ./argv.o                                       \

       ./choose-temp.o ./concat.o ./cp-demint.o                   \

       ./dyn-string.o                                            \

       ./fdmatch.o ./fibheap.o ./filename_cmp.o ./floatformat.o     \

       ./fnmatch.o ./fopen_unlocked.o                                \

       ./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o          \

       ./hashtab.o ./hex.o                                     \

       ./lbasename.o ./lrealpath.o                                 \

       ./make-relative-prefix.o ./make-temp-file.o                 \

       ./objalloc.o ./obstack.o                               \

       ./partition.o ./pexecute.o ./physmem.o                       \

       ./pex-common.o ./pex-one.o ./pex-unix.o                          \

       ./safe-ctype.o ./sort.o ./spaces.o ./splay-tree.o ./strerror.o  \

        ./strsignal.o                                             \

       ./unlink-if-ordinary.o                                         \

       ./xatexit.o ./xexit.o ./xmalloc.o ./xmemdup.o ./xstrdup.o     \

        ./xstrerror.o ./xstrndup.o

EXTRA_OFILES的定义为:

# A configuration can specify extra .o files that should be included,

# even if they are in libc. (Perhaps the libc version is buggy.)

EXTRA_OFILES =

LIBOBJS的定义为:

LIBOBJS =  ./insque$U.o ./mkstemps$U.o ./sigsetmask$U.o ./stpcpy$U.o ./stpncpy$U.o ./strverscmp$U.o

再往下还定义了一个依赖关系:

$(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS): stamp-picdir

当然,由于stamp-picdir什么事也不做,因此可直接跳过。

当这些指定的o文件都生成后,将调用ar将它们链接成libiberty.a文件,此时ar的调用参数中AR_FLAGS = rc

1.3.1   ./regex.o

这个文件的依赖关系为:

./regex.o: $(srcdir)/regex.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/xregex.h \

       $(INCDIR)/xregex2.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/regex.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/regex.c $(OUTPUT_OPTION)

这里regex.cgcc-4.3.1/libiberty目录下的文件。而INCDIR则为:

srcdir = ../.././libiberty

MULTISRCTOP =

INCDIR=$(srcdir)/$(MULTISRCTOP)../include

因此它指向的实际目录为:gcc-4.3.1/includeansidecl.hxregex.hxregex2.h都是这个目录下的文件。

这里$(COMPILE.c)定义为:

COMPILE.c = $(CC) -c -DHAVE_CONFIG_H $(LIBCFLAGS) -I. -I$(INCDIR) $(HDEFINES) -W -Wall -Wwrite-strings -Wstrict-prototypes –pedantic

因此这段脚本就是调用gcc来编译libiberty/regex.c,关键的两个参数是:

-DHAVE_CONFIG_H

-I$(INCDIR)

1.3.1.1             stamp-h

这个依赖关系为:

Makefile: $(srcdir)/Makefile.in config.status

       CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) ./config.status

 

# Depending on Makefile makes sure that config.status has been re-run

# if needed.  This prevents problems with parallel builds.

config.h: stamp-h ; @true

stamp-h: $(srcdir)/config.in config.status Makefile

       CONFIG_FILES= CONFIG_HEADERS=config.h:$(srcdir)/config.in $(SHELL) ./config.status

注释已经很清楚说明了这个文件的作用,但在cygwin下编译时无此问题,其实这里可以略过。

1.3.2   ./cplus-dem.o

这个文件的生成方式为:

./cplus-dem.o: $(srcdir)/cplus-dem.c stamp-h $(INCDIR)/ansidecl.h \

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

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/cplus-dem.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/cplus-dem.c $(OUTPUT_OPTION)

这个文件的生成与regex.c相似。

 

1.3.3   ./cp-demangle.o

这个文件的生成方式为:

./cp-demangle.o: $(srcdir)/cp-demangle.c stamp-h $(INCDIR)/ansidecl.h \

       $(srcdir)/cp-demangle.h $(INCDIR)/demangle.h \

       $(INCDIR)/dyn-string.h $(INCDIR)/getopt.h $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/cp-demangle.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/cp-demangle.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.4   ./md5.o

这个文件的生成方式为:

./md5.o: $(srcdir)/md5.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/md5.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/md5.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/md5.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.5   ./alloca.o

这个文件的生成方式为:

./alloca.o: $(srcdir)/alloca.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/alloca.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/alloca.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.6   ./argv.o

这个文件的生成方式为:

./argv.o: $(srcdir)/argv.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/argv.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/argv.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.7   ./choose-temp.o

这个文件的生成方式为:

./choose-temp.o: $(srcdir)/choose-temp.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/choose-temp.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/choose-temp.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.8   ./concat.o

这个文件的生成方式为:

./concat.o: $(srcdir)/concat.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/concat.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/concat.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.9   ./cp-demint.o

这个文件的生成方式为:

./cp-demint.o: $(srcdir)/cp-demint.c stamp-h $(INCDIR)/ansidecl.h \

       $(srcdir)/cp-demangle.h $(INCDIR)/demangle.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/cp-demint.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/cp-demint.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.10 ./dyn-string.o

这个文件的生成方式为:

./dyn-string.o: $(srcdir)/dyn-string.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/dyn-string.h $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/dyn-string.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/dyn-string.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.11 ./fdmatch.o

这个文件的生成方式为:

./fdmatch.o: $(srcdir)/fdmatch.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/fdmatch.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/fdmatch.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.12 ./fibheap.o

这个文件的生成方式为:

./fibheap.o: $(srcdir)/fibheap.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/fibheap.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/fibheap.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.13 ./filename_cmp.o

这个文件的生成方式为:

./filename_cmp.o: $(srcdir)/filename_cmp.c stamp-h $(INCDIR)/filenames.h \

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/filename_cmp.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/filename_cmp.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.14 ./floatformat.o 

这个文件的生成方式为:

./floatformat.o: $(srcdir)/floatformat.c stamp-h $(INCDIR)/ansidecl.h \

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

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/floatformat.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/floatformat.c $(OUTPUT_OPTION)

没有特殊的东西。

但是在vs2005下编译就会遇到麻烦,问题出现在NAN上面:

#ifndef NAN

#ifdef DBL_QNAN

#define NAN DBL_QNAN

#else

#define NAN (0.0 / 0.0)

#endif

#endif

当遇到NAN的使用时,就会发生一个错误:

error C2124: divide or mod by zero

实际上vcxmath.h中定义了NAN,当然,这个头文件只适用于VC,因此必须在floatformat.c中加上这样的语句:

#ifdef _MSC_VER

#include <xmath.h>

#endif

 

1.3.15 ./fnmatch.o

这个文件的生成方式为:

./fnmatch.o: $(srcdir)/fnmatch.c stamp-h $(INCDIR)/fnmatch.h \

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/fnmatch.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/fnmatch.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.16 ./fopen_unlocked.o

这个文件的生成方式为:

./fopen_unlocked.o: $(srcdir)/fopen_unlocked.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/fopen_unlocked.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/fopen_unlocked.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.17 ./getopt.o

这个文件的生成方式为:

./getopt.o: $(srcdir)/getopt.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/getopt.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/getopt.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/getopt.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.18 ./getopt1.o

这个文件的生成方式为:

./getopt1.o: $(srcdir)/getopt1.c stamp-h $(INCDIR)/getopt.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/getopt1.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/getopt1.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.19 ./getpwd.o

这个文件的生成方式为:

./getpwd.o: $(srcdir)/getpwd.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/getpwd.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/getpwd.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.20 ./getruntime.o

这个文件的生成方式为:

./getruntime.o: $(srcdir)/getruntime.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/getruntime.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/getruntime.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.21 ./hashtab.o

这个文件的生成方式为:

./hashtab.o: $(srcdir)/hashtab.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/hashtab.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/hashtab.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/hashtab.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.22 ./hex.o

这个文件的生成方式为:

./hex.o: $(srcdir)/hex.c stamp-h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/hex.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/hex.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.23 ./lbasename.o

这个文件的生成方式为:

./lbasename.o: $(srcdir)/lbasename.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/filenames.h $(INCDIR)/libiberty.h \

       $(INCDIR)/safe-ctype.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/lbasename.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/lbasename.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.24 ./lrealpath.o

这个文件的生成方式为:

./lrealpath.o: $(srcdir)/lrealpath.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/lrealpath.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/lrealpath.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.25 ./make-relative-prefix.o

这个文件的生成方式为:

./make-relative-prefix.o: $(srcdir)/make-relative-prefix.c stamp-h \

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

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/make-relative-prefix.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/make-relative-prefix.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.26 ./make-temp-file.o

这个文件的生成方式为:

./make-temp-file.o: $(srcdir)/make-temp-file.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/libiberty.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/make-temp-file.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/make-temp-file.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.27 ./objalloc.o

这个文件的生成方式为:

./objalloc.o: $(srcdir)/objalloc.c stamp-h $(INCDIR)/ansidecl.h \

       $(INCDIR)/objalloc.h

       if [ x"$(PICFLAG)" != x ]; then \

         $(COMPILE.c) $(PICFLAG) $(srcdir)/objalloc.c -o pic/$@; \

       else true; fi

       $(COMPILE.c) $(srcdir)/objalloc.c $(OUTPUT_OPTION)

没有特殊的东西。

 

1.3.28 ./obstack.o

这个文件的生成方式为:

./obstack.o: $(srcdir)/obstack.c stamp-h $(INCDIR)/obstack.h