oMT7620N httpd_new的Makefile学习

/opt/ralink-toolchains/buildroot-gcc342/bin/mipsel-linux-uclibc-gcc -o httpd main.o httpd.o basic.o ej.o cgi_main.o cgi_object.o cgi_util.     o cgi_cmd.o cgi_dump.o cgi_upload.o -Wl,-rpath, -L/home/wudi/origin/trunk/targets/MT7620N/fs.install/lib -L/home/wudi/origin/trunk/targets     /MT7620N/fs.install/lib/private -L/home/wudi/origin/trunk/targets/MT7620N/fs.install/lib/public -lcms_dal -lcms_msg -lcms_util -lcms_boardctl -lcrypt -lutil -ldl -lcms_core -lnanoxml -ldl -lmdm -lc

EXE = httpd

    $(EXE): $(OBJS)

        $(CC) -o $@ $^ -Wl, -rpath, $(CMS_LIB_RPATH), $(CMS_LIB_PATH), $(LIBS)

 

#Include  the rule for making dependcy files.

#The "-" in front of the second include suppresses

#error messages when make cannot find  the .d files.

#It will just regenerate them.

#See Section 4.14 of Gnu make.

include $(BUILD_DIR)/make.deprules

-incude $(OBJS:.o=.d)

 

.o文件的生成是在-include $(OBJS:.o=.d)这一步生成的,按上述的英文描述, 在没有.d存在的时候,

仅仅是生成.d文件而没有报错。

.d的规则是在make.deprules中定义的。

 

 

 

1. make.common中

    (1)

    ifndef TOOLCHAIN_TOP

    TOOLCHAIN_TOP = /opt/toolchains/uclibc-crosstools-gcc-4.4.2.1

    endif

    CFLAGS = $(CMS_COMPILE_FLAGS) $(CUSTOM_CFLAGS) $(ALLOWED_INCLUDE_PATHS) $(CMS_WLAN_FLAGS)

    CFLAGS += -I$(TOOLCHAIN)/include -L$(TOOLCHAIN)/lib

    CFLAGS += $(BRCM_WERROR_CFLAGS)

    CFLAGS += DP$(PROFILE)

 

    (2)

    MT7620N profile中

    TOOLCHAIN_TOP_DIR="/opt/ralink-toolchains/buildroot-gcc342"

    UCLIBC=y

 

    (3)

    make.common中

    ifeq ($(strip $(MT7620N)), y)

    TOOLCHAIN_TOP = $(TOOLCHAIN_TOP_DIR: "%"=%)

    TOOLCHAIN = $(TOOLCHAIN_TOP)

    LIBDIR = $(TOOLCHAIN_TOP)/lib

    USRLIBDIR = $(TOOLCHAIN_TOP)/usr/lib

    EXTRALIBDIR = $(TOOLCHAIN_TOP)/LIB

    EXTRAINCDIR = $(TOOLCHAIN)/usr/lib/gcc/mips-linux-uclibc/4.4.2/include

    LIB_PATH = $(TOOLCHAIN_TOP)/lib

    LIBCDIR = $(TOOLCHAIN_TOP)/lib

 

    export BRCM_WERROR_CFLAGS :=

    BRCM_COMMON_FLAGS :=

     export BRCM_APP_CFLAGS := $(BRCM_COMMON_FLAGS)

    export BRCM_SO_CFLAGS := $(BRCM_COMMON_FLAGS)

    CROSS_COMPILE = $(TOOLCHAIN)/bin/mipsel-linux-uclibc-

    ACTURAL_KERNEL_DIR = mt7620/linux-2.6.36.x

    endif

 

    AR = $(CROSS_COMPILE)ar

    AS = $(CROSS_COMPILE)as

    LD = $(CROSS_COMPILE)ld

    CC = $(CROSS_COMPILE)gcc

    CXX = $(CROSS_COMPILE)g++

    CPP = $(CROSS_COMPILE)cpp

    NM = $(CROSS_COMPILE)nm

    STRIP = $(CROSS_COMPILE)strip

    SSTRIP = $(CROSS_COMPILE)sstrip

    OBJCOPY = $(CROSS_COMPILE)objcopy

    OBJDUMP = $(CROSS_COMPILE)objdump

    RANLIB = $(CROSS_COMPILE)ranlib

 

    export TOOLCHAIN_TIP  TOOLCHAIN  LEGACY_TOOLCHAIN CROSS_COMPILE \

               AR AS LD CC CXX CPP  NM STRIP SSTRIP OBJCOPY OBJDUMP RANLIB \

               LIB_PATH LIBDIR USRLIBDIR EXTRALIBDIR EXTRAINCDIR LIBCDIR BUILD_GDBSERVER

 

2. httpd_new的Makefile中

    all dynamic install: $(EXE) generic_exe_install cpall_html

    EXE = httpd

    $(EXE): $(OBJS)

        $(CC) -o $@ $^ -Wl, -rpath, $(CMS_LIB_RPATH), $(CMS_LIB_PATH), $(LIBS)

          (1) CC在make.common中定义了, 是toolchain下的gcc

            (2)  $@-目标文件,$^所有依赖的文件, $<第一个依赖的文件。

            (3)  -Wl(man ld), -W warning options,

                         -Wl, option, Linker Option

                  Linker Options

                  object-file-name  -l(library), -nostartfiles -nodefaultlibs, -nostdlib, -pie, -rdynamic,  -s,  -static,  -static-libgcc,  -static-libstdc++, 

                                            -shared, -shared-libgcc, -symboic, -T (script),     -Wl, option,     -Xlinker  (option),    -u (symbol)

                       Note: if the linker is being invoked indirectly, via a compiler driver (e.g. gcc), then all the linker command line options

                                shouled    be prefiixed by -Wl, (or whatever is appropriate for the particular compiler) like this:

                                    gcc -Wl, --start-group foo.o bar.o -Wl, --end-group  

 

                      当链接器被间接调用(如通过编译器gcc)时, 所有连接器的命令选项都需要加上-Wl前缀。 -W warning option, -l linker option.

                               This is important, because otherwise the compiler program may silently drop the linker options, resulting in a bad link.

                               Comfusion may also arise when passing options that require values through a driver, as the use of a space between

                               option and argument acts as seprator, and causes the driver to pass only the option to the linker and the argument

                               to the compiler. In this case, it is simplest to use the joined forms of both single- and multiple-letter options, such as

                                           gcc foo.o bar.o -Wl, -e(Entry) -Wl, -Map=a.map

                              -Map=mapfile

                                  Print a link map to the file mapfile. See the description of the -M option, above.

                                  -M

                                     --print-map

                                        Print a link map to the  standard output. A link map provides information about the link, including the following:

                                           ..Where object files are mapped into memory.

                                           ..How common symbols are allocated.

                                           .. All archive members included in the link, with a mention of the symbol which caused the archive member to

                                                   brought in.                                          

                                           .. The values assigned to symbols.

 

 

 

                         

                -rpath(man ld): Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects.

                                       All -rapth arguments are concatinated and passed  to the runtime linker, which uses  them to locate shared

                -L (man ld): -L searchdir

                                  Add path searchdir to the list  of paths that ld will search for archive libraries and ld control scripts.

                                  Directories specified on the command line are searched before the default directories.

                                  All -L options apply to all -l options, regardless of the order in which the options appear.

               -l (man ld): -l namespec

                                   Add the archive or object file spcified by namespec to the list of files to link.

                                   If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise

                                   it will search the library path for a file called libnamespec.a .

                                   On systems which support shared libraries, ld may also search for files other than libnamespec.a  .

                                   Specifically, on ELF and SunOS systems ld will search a directory for a library called libnamespec.so before

                                   searching for one called libnamespec.a (By convention, a ".so" extension indicates a shared library). Note

                                   that this behavior does not apply to :filename, which always specifies a file called filename.

                                  

 

               make.common中

               CMS_LIB_RPATH=

               CMS_LIB_PATH = $(patsubst %, -L$(INSTALL_DIR)%, $(subst :, ,$(ALLOWED_LIB_DIRS))

               INSTALL_DIR=$(PROFILE_DIR)/fs.install

               CMS_COMMON_LIBS := -lcms_util -lcms_broadctl -lcrypt -lutil

               CMS_CORE_LIBS := -lcms_core -lnanoxml -ldl -lmdm

               httpd_new的Makefile中

               LIBS = -lcms_dal -cms_msg $(CMS_COMMON_LIBS) -ldl $(CMS_CORE_LIBS)

               AllOWED_LIB_DIRS := /lib:/lib/private:/lib/public

               LIBS += -lc

           httpd_new的Makefile中:

           include $(BUILD_DIR)/make.deprules

           -include $(OBJS:.o=.d)

 

            make.deprules中

            ifneq ($(MAKECMDGOALS), clean)

            %.d: %.c

                @set -e; rm -f $@; \

                $(CC)  -M  $(CPPFLAGS) $(CFLAGS) $< > $@.SSSS  2>/dev/null;  \

                sed '' <  $@.SSSS > $@;  \

                rm -f $@.SSSS

            endif

           

posted @ 2014-02-18 10:30  安心种田  阅读(660)  评论(0编辑  收藏  举报