交叉开发--------1.4Makefile

本文详细介绍了Makefile的基本概念、语法结构,包括变量的赋值与使用、函数和调用、依赖关系以及常见操作,如自定义函数、shell命令调用和内置函数wildcard和patsubst的应用。

目录

前言:我们从几个方面学习Makefile(智能化的自动编译工具)

1.Makefile是什么

2.了解Makefile中的一些语法(文件格式)

3.Makefile中的变量

    3.1  makefile中变量的赋值和使用

            1.简单赋值 :=(不会向上展开)

          2.递归赋值  =(会向上展开) 

            3.追加赋值  +=

            4.条件赋值  ?=

                3.2  自动变量 

                3.3 Makefile中的注释信息

4.Makefile中的函数和命令

    1.Makefile中运行自定义函数并且调用函数(类似与shell中函数)        2.Makefile中调用shell命令

    3.makefile中调用内置的函数


前言:我们从几个方面学习Makefile(智能化的自动编译工具)


    1.Makefile是什么?
    2.Makefile能做什么?
    3.了解Makefile中的一些语法,能够编写/修改简单的Makefile(一般的Makefile都是自动生成的)


1.Makefile是什么


    Makefile是make工具的配置文件,指导make如何去编译工程的文件

    什么是make呢?
        sudo apt install make 
        make是一个智能化的自动编译工程的管理工具(命令),它可以决定在一个工程中哪些文件需要被编译,哪些文件先编译,哪些文件后编译,以及如何去链接编译之后的文件
        make的功能之所以强大,是因为Makefile文件告诉了make如何去工作,以及如何产生目标文件
        把make的规则写入到Makefile文件中,make每一次编译都会更根据Makefile文件进行编译
        所以make的正常工作,是离不开makefile文件的

2.了解Makefile中的一些语法(文件格式)


    一个最简单的Makefile是由一些"目标和规则"组成的

    大概形式如下:
    TARGET:PREREQUISITES
    <Tab键>RECIPE
    <Tab键>RECIPE
    <Tab键>RECIPE
    .....
    TARGET2:PREREQUISITES
    <Tab键>RECIPE
    <Tab键>RECIPE
    <Tab键>RECIPE
    .....

    TARGET:是这一次make的目标名称,你这个Makefile的目的是什么
        一个Makefile中可以有很多个目标
        默认完成的是第一个目标,其他目标也叫做"伪目标"

    PREREQUISITES:依赖,完成前面的目标,需要依赖哪些文件或者库...(也可以为空)
        在Make的时候,第一步会检查当前目标依赖的文件是否存在
        如果存在:
            则按照目标下面的RECIPE命令列表生成对应的目标
        如果不存在:
            就搜索整个Makefile中,查看是否有以"依赖文件"为目标名的目标
            如果没有就报错,如果有,就先生成以"依赖文件"为目标名的目标,以此递归

    RECIPE:生成上面的目标需要执行的命令列表(前面必须有一个tab键)

    例子:
    现实生活中的Makefile,目标是西e

    TomatoFireEgg:Tomato Eggs
        echo "油,搞里头"
        echo "鸡蛋,搞里头"
        echo "西红柿,搞里头"
        echo "搞里头"
        echo "翻炒一下"

    Tomato:
        echo "生成一个Tomato"

    Eggs:KUN
        echo "Kun 生了一个egg"

    KUN:
        echo "唱跳两年半!"


    make的时候,默认是完成第一个目标!

    make的用法:
        make  会自动的取当前目录下面的Makefile中完成"目标"

        make + 目标名
            如果没有加目标,默认生成Makefile中的第一个目标

        make -C  目录 
            到指定的目录中去查找Makefile文件并且生成目标

    make在执行的时候,会自动的把执行过的命令打印到终端上面
    make是非常智能的,它能够根据文件的修改时间,去判断哪些文件需要先编译,哪些文件不需要被重新编译
    如:

    CC:=gcc 
    Graph:graph.o LKqueue.o main.o
        $(CC) graph.o LKqueue.o main.o -o Graph 

    graph.o:
        $(CC) -c graph.c -o graph.o
    LKqueue.o:
        $(CC) -c LKqueue.c -o LKqueue.o
    main.o:
        $(CC) -c main.c -o main.o

    clean:
        rm *.o
        rm Graph    


    我们的工程中,有很多C文件的编译格式是类似的,如果工程中增加一个源文件,就需要去修改Makefile文件,增加编译规则,这其实很麻烦
    我们能不能使用一些变量去表示Makefile中的文件列表呢?

3.Makefile中的变量


    Makefile中可以自己定义变量,也可以使用Makefile中自带的变量(环境变量)
    自定义变量:没有类型,都是字符串,而且变量名可以随意指定

    3.1  makefile中变量的赋值和使用


        变量可以不需要预先定义,和shell一样
        如果变量名没有预先定义并且赋值,则变量的值为空
        变量的定义方法:
            变量名
        如何使用变量:
            $(变量名)

        变量的定义不能放到指令列表中(一般放到Makefile的最前面)    
        在Makefile中给变量赋值有几种情况:


            1.简单赋值 :=(不会向上展开)

                B:=$(A)
                A:=12345
                
                B为空
                A为12345
                ---------------
                A:=12345
                B:=$(A)
                C:=A 

                $(A)    12345
                $(B)    12345
                $(C)    A


          2.递归赋值  =(会向上展开) 

                B=$(A)
                A=12345
                
                $(A)    12345
                $(B)    12345

                注意不要写成递归调用自己
                B=$(A)
                A=$(B)

            3.追加赋值  +=


                A:=123
                A+=456

                $(A)  123456


            4.条件赋值  ?=


                当变量以前没有定义或者没有值的时候,我们才会给他赋值

                A?=hello
                    因为A以前没有定义并且没有值,所有A为hello
                
                B:=123
                B?=ABC 
                    $(B) 123

            
    3.2  自动变量 


        系统已经帮我们定义好了的变量,我们只需要使用即可
        自动变量:make中的内置变量,make赋予这些变量一些特殊的含义
            $@  目标的完整名字
                写在哪一个目标下面,就表示哪一个目标的名字
            
            $+  所有依赖文件的名字,以空格隔开,可能包含重复的依赖名
                写在哪一个目标下面,就表示哪一个目标的依赖

            $^  所有依赖文件的名字,以空格隔开,不会包含重复的依赖名
                写在哪一个目标下面,就表示哪一个目标的依赖

            $<  第一个依赖文件的名字
                main:a.c b.c 
                    echo $<   -----> a.c 

            $?  所有时间戳比目标文件新的依赖文件名称(在make的时候,需要重新编译的文件)
                在生成目标文件之后,你又修改了的依赖文件


            
    3.3 Makefile中的注释信息


        以#开头的行是注释
        如:

        #目标名称
        TARGET:=Graph
        #头文件路径
        INC:=../inc 
        #库文件的路径
        LIB:= -lfind_max
        LIB_PATH:= -L../lib 
        #编译器名称
        CC:=gcc 
        $(TARGET):graph.o LKqueue.o main.o
            $(CC) $^ -o $@  -I$(INC) $(LIB) $(LIB_PATH)
        graph.o:graph.c
            $(CC) -c $^ -o $@
        LKqueue.o:LKqueue.c
            $(CC) -c $^ -o $@
        main.o:main.c
            $(CC) -c $^ -o $@
        
        clean:
            rm *.o
            rm Graph

    如果在上面的工程中,增加了一个C的源文件,可能需要修改Makefile
    修改的时候,也是增加一条关于.c ----->.o的规则 

    所有的.c----->.o的规则都是一样的,这本身也是一种规则,我们可以创建一个默认的规则,把上面的.c----->.o写成一个通用的形式(在增加C源文件之后,可以不需要修改Makefile)

    Makefile中的通配符
        %       表示任意一个文件名(不包括扩展名)
        %.o     表示任意一个以.o结尾的文件
        %.c     表示任意一个以.c结尾的文件
        同名的.o一般会依赖于同名的.c 
    =========>

    #目标名称
    TARGET:=Graph
    CC:=gcc 
    $(TARGET):graph.o Lkqueue.o main.o
        $(CC) $^ -o $@ 

    %.o:%.c 
        $(CC) -c $< -o $@
    clean:
        rm *.o
        rm $(TARGET)


    我们也可以自动的在指定的工程目录中去查找*.c/*.cpp文件
    使用内置的函数即可

4.Makefile中的函数和命令


    1.Makefile中运行自定义函数并且调用函数(类似与shell中函数)
    
    2.Makefile中调用shell命令


        格式:
            $(shell  命令名称  参数列表)
        如果你需要使用shell命令或者函数的结果
        =====>
        变量名=$(shell  命令名称  参数列表)    /   $(函数名  函数的参数列表)
        如:
        Date=$(shell  date)
        PWD=$(shell pwd)

    3.makefile中调用内置的函数


        格式:
        $(函数名  函数的参数列表)
        我们简单的了解几个常用的函数和使用方式即可
        wildcard:文件名展开函数
            展开指定的目录下面符合wildcard参数描述的文件名称,获取的文件名称之间使用空格隔开
            例子:
            CSRCS    表示C源文件列表
            CSRCS:=$(wildcard *.c)
            在当前的目录下面查找所有的以.c结尾的文件名,然后赋值给 CSRCS
        通过这种方式,我们就可以获取到所有的源文件名称

        patsubst:模式字符串替换函数
        把指定的字符串中符合某一个模式的字符串,替换为指定的字符串(可以使用通配符)
            例子:
            CSRCS:=$(wildcard *.c)
            OBJS:=$(patsubst  %.c,%.o,$(CSRCS))
            把$(CSRCS)中以.c结尾的字符串的文件名称,替换为同名的以.o结尾的文件名

        我们一般可以认识和使用一个简单通用的makefile即可

        
 

什么问题这个 Applying ./patches/010-fix-mod_webdav.patch using plaintext: patching file src/mod_webdav.c Applying ./patches/020-meson-mod_webdav_min.patch using plaintext: patching file src/meson.build Applying ./patches/030-fix-mips-gcc-not-support-__has_include-compile-error using plaintext: patching file src/mod_magnet.c Hunk #1 succeeded at 204 with fuzz 2. touch /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/.prepared_ca9f6165c1130812efd2b0b7b8318bed (cd /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/./; if [ -x ./configure ]; then /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/ -name config.guess | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/ -name config.guess | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.guess; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/ -name config.sub | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/ -name config.sub | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.sub; AR=arm-buildroot-linux-gnueabi-ar AS="arm-buildroot-linux-gnueabi-gcc -c " LD=arm-buildroot-linux-gnueabi-ld NM=arm-buildroot-linux-gnueabi-nm CC="arm-buildroot-linux-gnueabi-gcc" GCC="arm-buildroot-linux-gnueabi-gcc" CXX="arm-buildroot-linux-gnueabi-g++" RANLIB=arm-buildroot-linux-gnueabi-ranlib STRIP=arm-buildroot-linux-gnueabi-strip OBJCOPY=arm-buildroot-linux-gnueabi-objcopy OBJDUMP=arm-buildroot-linux-gnueabi-objdump SIZE=arm-buildroot-linux-gnueabi-size CFLAGS=" " CXXFLAGS=" " CPPFLAGS="-I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " LDFLAGS="-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib -Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib " ./configure --target=arm-openwrt-linux-uclibc --host=arm-openwrt-linux-uclibc --build=x86_64-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --with-webdav-props --with-webdav-locks --with-openssl --with-openssl-libs=/usr/lib --with-lua ; fi; ) configure: WARNING: unrecognized options: --disable-nls configure: loading site script /data/red-round3/red-round3/Iplatform/openwrt/include/site/arm-openwrt-linux-uclibc checking build system type... x86_64-pc-linux-gnu checking host system type... arm-openwrt-linux-uclibc checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for arm-openwrt-linux-uclibc-strip... arm-buildroot-linux-gnueabi-strip checking for a race-free mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether UID '1000' is supported by ustar format... yes checking whether GID '1000' is supported by ustar format... yes checking how to create a ustar tar archive... gnutar checking for arm-openwrt-linux-uclibc-gcc... arm-buildroot-linux-gnueabi-gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether the compiler supports GNU C... yes checking whether arm-buildroot-linux-gnueabi-gcc accepts -g... yes checking for arm-buildroot-linux-gnueabi-gcc option to enable C11 features... none needed checking whether arm-buildroot-linux-gnueabi-gcc understands -c and -o together... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of arm-buildroot-linux-gnueabi-gcc... gcc3 checking how to run the C preprocessor... arm-buildroot-linux-gnueabi-gcc -E checking for x86_64-pc-linux-gnu-gcc... no checking for gcc... gcc checking whether the compiler supports GNU C... yes checking whether gcc accepts -g... yes checking for gcc option to enable C11 features... -std=gnu11 checking whether gcc -std=gnu11 understands -c and -o together... yes checking dependency style of gcc -std=gnu11... gcc3 checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking how to run the C preprocessor... gcc -std=gnu11 -E checking for a sed that does not truncate output... /data/red-round3/red-round3/Iplatform/openwrt/staging_dir/host/bin/sed checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for fgrep... /bin/grep -F checking how to print strings... printf checking for ld used by arm-buildroot-linux-gnueabi-gcc... arm-buildroot-linux-gnueabi-ld checking if the linker (arm-buildroot-linux-gnueabi-ld) is GNU ld... yes checking how to run the C preprocessor... arm-buildroot-linux-gnueabi-gcc -E checking whether make sets $(MAKE)... (cached) yes checking for stdio.h... yes checking for stdlib.h... yes checking for string.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for strings.h... yes checking for sys/stat.h... yes checking for sys/types.h... yes checking for unistd.h... yes checking for wchar.h... yes checking for minix/config.h... no checking whether it is safe to define __EXTENSIONS__... yes checking whether _XOPEN_SOURCE should be defined... no checking for arm-openwrt-linux-uclibc-ar... arm-buildroot-linux-gnueabi-ar checking the archiver (arm-buildroot-linux-gnueabi-ar) interface... ar checking for inline... inline checking for C/C++ restrict keyword... __restrict__ checking for BSD- or MS-compatible name lister (nm)... arm-buildroot-linux-gnueabi-nm checking the name lister (arm-buildroot-linux-gnueabi-nm) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert x86_64-pc-linux-gnu file names to arm-openwrt-linux-uclibc format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for arm-buildroot-linux-gnueabi-ld option to reload object files... -r checking for arm-openwrt-linux-uclibc-file... no checking for file... file configure: WARNING: using cross tools not prefixed with host triplet checking for arm-openwrt-linux-uclibc-objdump... arm-buildroot-linux-gnueabi-objdump checking how to recognize dependent libraries... pass_all checking for arm-openwrt-linux-uclibc-dlltool... no checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for arm-openwrt-linux-uclibc-ar... (cached) arm-buildroot-linux-gnueabi-ar checking for archiver @FILE support... @ checking for arm-openwrt-linux-uclibc-strip... (cached) arm-buildroot-linux-gnueabi-strip checking for arm-openwrt-linux-uclibc-ranlib... arm-buildroot-linux-gnueabi-ranlib checking command to parse arm-buildroot-linux-gnueabi-nm output from arm-buildroot-linux-gnueabi-gcc object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for arm-openwrt-linux-uclibc-mt... no checking for mt... mt checking if mt is a manifest tool... no checking for dlfcn.h... yes checking for objdir... .libs checking if arm-buildroot-linux-gnueabi-gcc supports -fno-rtti -fno-exceptions... no checking for arm-buildroot-linux-gnueabi-gcc option to produce PIC... -fPIC -DPIC checking if arm-buildroot-linux-gnueabi-gcc PIC flag -fPIC -DPIC works... yes checking if arm-buildroot-linux-gnueabi-gcc static flag -static works... yes checking if arm-buildroot-linux-gnueabi-gcc supports -c -o file.o... yes checking if arm-buildroot-linux-gnueabi-gcc supports -c -o file.o... (cached) yes checking whether the arm-buildroot-linux-gnueabi-gcc linker (arm-buildroot-linux-gnueabi-ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking for shl_load... no checking for shl_load in -ldld... no checking for dlopen... no checking for dlopen in -ldl... yes checking whether a program can dlopen itself... cross checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no checking for sys/wait.h that is POSIX.1 compatible... yes checking for getopt.h... yes checking for inttypes.h... (cached) yes checking for poll.h... yes checking for pwd.h... yes checking for stdlib.h... (cached) yes checking for stdint.h... (cached) yes checking for strings.h... (cached) yes checking for sys/inotify.h... yes checking for sys/loadavg.h... no checking for sys/poll.h... yes checking for sys/prctl.h... yes checking for sys/procctl.h... no checking for sys/sendfile.h... yes checking for sys/time.h... yes checking for sys/uio.h... yes checking for sys/un.h... yes checking for syslog.h... yes checking for uuid/uuid.h... yes checking for an ANSI C-conforming const... yes checking for inline... (cached) inline checking for off_t... yes checking for pid_t... yes checking for size_t... yes checking for struct tm.tm_gmtoff... yes checking for socklen_t... yes checking for library containing socket... none required checking for library containing gethostbyname... none required checking for library containing clock_gettime... none required checking for library containing elftc_copyfile... no checking for library containing dlopen... -ldl checking for dlfcn.h... (cached) yes checking pkg-config is at least version 0.9.0... yes configure: ---------------------------------------- checking for libev support... no configure: ---------------------------------------- checking for MySQL support... no configure: ---------------------------------------- checking for PgSQL support... no configure: ---------------------------------------- checking for LibDBI support... no configure: ---------------------------------------- checking for LibSASL support... no configure: ---------------------------------------- checking for LDAP support... no configure: ---------------------------------------- checking for PAM support... configure: ---------------------------------------- checking for extended attributes support... no configure: ---------------------------------------- checking for valgrind... no configure: ---------------------------------------- checking for libunwind... no configure: ---------------------------------------- checking for kerberos5... no checking custom include directory for kerberos5... no checking custom lib directory for kerberos5... no configure: ---------------------------------------- checking for OpenSSL... yes checking custom include directory for openssl... no checking custom lib directory for openssl... /usr/lib checking for openssl/ssl.h... yes checking for RAND_bytes in -lcrypto... yes checking for SSL_new in -lssl... yes configure: ---------------------------------------- checking for wolfSSL... no configure: ---------------------------------------- checking for mbedTLS... no configure: ---------------------------------------- checking for Nettle... no configure: ---------------------------------------- checking for GnuTLS... no configure: ---------------------------------------- checking for NSS... no configure: ---------------------------------------- checking for perl regular expressions support... no configure: ---------------------------------------- checking for perl regular expressions support... yes checking for PCRE2... no checking for pcre2-config... no configure: error: pcre2-config not found, install the pcre2-devel package or build with --without-pcre2 Makefile:254: recipe for target '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/.configured_nnnnnnnnnnnynnnnynnnnnn' failed make[3]: *** [/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/lighttpd-1.4.71/.configured_nnnnnnnnnnnynnnnynnnnnn] Error 1 make[3]: Leaving directory '/data/red-round3/red-round3/Iplatform/packages/opensource/lighttpd' package/Makefile:133: recipe for target 'package/feeds/iplatform/lighttpd/compile' failed make[2]: *** [package/feeds/iplatform/lighttpd/compile] Error 2 make[2]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' /data/red-round3/red-round3/Iplatform/openwrt/include/toplevel.mk:184: recipe for target 'package/lighttpd/compile' failed make[1]: *** [package/lighttpd/compile] Error 2 make[1]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' Makefile:234: recipe for target 'iplatform_package/lighttpd/compile' failed make: *** [iplatform_package/lighttpd/compile] Error 2
09-27
<think>我们正在分析一个编译 lighttpd 软件包失败的日志。日志显示在配置阶段出现了错误,导致编译终止。 关键错误信息:`configure: error: pcre2-config not found, install the pcre2-devel package or build with --without-pcre2` 这意味着配置脚本在检查 PCRE2(Perl Compatible Regular Expressions, version 2)库时失败,因为没有找到 pcre2-config 工具。 整个流程: 1. 应用补丁:成功应用了三个补丁(010, 020, 030)。 2. 执行配置命令:在 lighttpd 的源代码目录中运行了 `configure` 脚本,设置了交叉编译环境变量(如CC、CFLAGS等)。 3. 配置过程中检查依赖:当检查到需要 PCRE2 库时,找不到 pcre2-config(该工具用于获取PCRE2的编译参数),因此报错。 原因分析: -交叉编译环境下,需要为目标平台(arm-openwrt-linux-uclibc)编译并安装 PCRE2 库,并且确保 pcre2-config 在PATH中者通过PKG_CONFIG_PATH指定。 - 当前环境中可能没有为目标平台安装 PCRE2 的开发包(即库和头文件),者虽然安装了但配置脚本找不到。 解决方案思路: 1. 在OpenWrt的编译系统中,通常需要先编译依赖库(如PCRE2)作为lighttpd的依赖。 2. 检查OpenWrt的menuconfig中是否已经选择了PCRE2(PCRE)支持。注意,lighttpd可能需要PCRE2,但有时也可以使用PCRE(旧版)。 3. 者,在配置选项中添加 `--without-pcre2` 来跳过PCRE2(如果不需要正则表达式支持者可以使用其他正则库替换)。 在OpenWrt中如何解决: - 在OpenWrt的包管理体系中,lighttpd的编译依赖通常在它的Makefile中定义。如果依赖包没有编译,则需要先编译依赖包。 - 可以尝试在编译lighttpd之前,先编译PCRE2包:`make package/feeds/packages/pcre2/compile`(具体路径可能不同,取决于pcre2包所在的feed)。 - 另一种方法:在menuconfig中启用PCRE2,然后重新编译。 如果不想使用PCRE2,可以修改lighttpd的配置选项,在编译时禁用PCRE2。这可以通过修改OpenWrt中lighttpd包的Makefile来实现,例如添加配置选项 `--without-pcre2`。 错误日志的最后几行显示编译失败,并退出。 因此,用户的问题可能是:编译lighttpd时因为缺少PCRE2库而失败,如何解决? 根据以上分析,我们可以提出相关问题。 </think>### 编译错误分析与解决 #### **1. 问题核心:PCRE2 依赖缺失** 日志末尾的关键错误信息: ``` configure: error: pcre2-config not found, install the pcre2-devel package or build with --without-pcre2 ``` - **原因**: 编译 lighttpd 时需依赖 **PCRE2 库**(Perl兼容正则表达式库),但交叉编译环境中未找到该库的开发文件(`pcre2-config` 工具)。 #### **2. 流程解析与错误定位** 1. **补丁应用阶段**(成功): - `010-fix-mod_webdav.patch`:修复 WebDAV 模块问题。 - `020-meson-mod_webdav_min.patch`:调整构建配置。 - `030-fix-mips-gcc...`:解决 MIPS 架构编译错误。 2. **配置检测阶段**(部分成功): - **交叉编译工具链**:正确识别(`arm-buildroot-linux-gnueabi-gcc`)。 - **关键依赖检查**: - OpenSSL 支持正常(`with-openssl`)。 - **PCRE2 检测失败**:未找到 `pcre2-config`(配置脚本终止)。 3. **编译终止**: ``` make[3]: *** [lighttpd编译目标] Error 1 make[1]: *** [顶层编译] Error 2 ``` --- #### **3. 根本原因分析** - **交叉编译环境问题**: - PCRE2 库未为目标平台(`arm-openwrt-linux-uclibc`)编译安装。 - 开发包(`pcre2-devel`)未包含在 SDK 编译依赖中。 - **配置冲突**: lighttpd 启用 `--with-webdav-props` 需正则表达式支持(强制依赖 PCRE2)。 --- #### **4. 解决方案** ##### 方案 1:安装 PCRE2 开发包 ```bash # 在主机环境中安装 PCRE2 sudo apt-get install libpcre2-dev # Debian/Ubuntu ``` **集成到交叉编译环境**: 1. 编译 PCRE2 目标平台版本: ```bash make package/feeds/packages/pcre2/compile ``` 2. 重新编译 lighttpd。 ##### 方案 2:禁用 PCRE2 依赖 修改 lighttpd 配置选项(需评估功能影响): ```diff - --with-webdav-props + --with-webdav-props --without-pcre2 # 禁用 PCRE2(可能导致正则功能失效) ``` ##### 方案 3:检查 OpenWrt 包依赖 验证 `lighttpd` 的 Makefile 是否正确定义依赖: ```makefile DEPENDS:= +libopenssl +libpcre2 # 确保包含 libpcre2 ``` --- #### **5. 预防措施** - **编译前验证依赖**: ```bash ./scripts/feeds install pcre2 # 确保 PCRE2 包已安装 ``` - **日志调试技巧**: 关注 `configure` 阶段的 `checking for PCRE2...` 输出,提前识别缺失依赖。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值