代码之家  ›  专栏  ›  技术社区  ›  Mahmoud Al-Qudsi

在FreeBSD下的错误目录中启动

  •  0
  • Mahmoud Al-Qudsi  · 技术社区  · 8 年前

    all:
        cd src && make all
    

    我的目录结构 Makefile 位于顶级目录中):

    [I] mqudsi@php ~/bbcp> tree -d
    .
    ├── bin
    │   └── FreeBSD
    ├── obj
    │   └── FreeBSD
    ├── src
    └── utils
    

    这在Linux下运行得很好,但在FreeBSD下,它给出了一个关于 src

    为了调试,我将Makefile命令更新为 pwd; cd src && make all 我发现 当我跑步时 make ./obj ./obj/src/ cd 进入

    除了我不知道为什么它会这样做之外,我确信 gmake 制作 在FreeBSD下,我会处理好它,但事实并非如此(我松了一口气,因为我不敢相信BSD make和GNU make在核心运营方面有这么大的差异)。

    奇怪的是,删除 obj obj公司 目录 ./obj公司 第一否则,它会按预期执行。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Mahmoud Al-Qudsi    8 年前

    从FreeBSD make 手册页:

    .OBJDIR      A path to the directory where the targets are built.  Its
                 value is determined by trying to chdir(2) to the follow-
                 ing directories in order and using the first match:
    
                 1.   ${MAKEOBJDIRPREFIX}${.CURDIR}
    
                  (Only if `MAKEOBJDIRPREFIX' is set in the environ-
                  ment or on the command line.)
    
                 2.   ${MAKEOBJDIR}
    
                  (Only if `MAKEOBJDIR' is set in the environment or
                  on the command line.)
    
                 3.   ${.CURDIR}/obj.${MACHINE}
    
                 4.   ${.CURDIR}/obj
    
                 5.   /usr/obj/${.CURDIR}
    
                 6.   ${.CURDIR}
    
                 Variable expansion is performed on the value before it's
                 used, so expressions such as
                   ${.CURDIR:S,^/usr/src,/var/obj,}
                 may be used.  This is especially useful with
                 `MAKEOBJDIR'.
    
                 `.OBJDIR' may be modified in the makefile via the special
                 target `.OBJDIR'.  In all cases, make will chdir(2) to
                 the specified directory if it exists, and set `.OBJDIR'
                 and `PWD' to that directory before executing any targets.
    

    在所有情况下,如果指定目录存在,则将chdir(2)设置为指定目录,并将其设置为 .OBJDIR'

    相比之下 GNU make manual page OBJDIR

    解决方案是覆盖 通过伪目标的变量 .OBJDIR

    .OBJDIR: ./
    
    all:
        cd src && make
    clean:
        cd src && make clean
    

    另一种解决方案是在 cd 具有的目标 ${CURDIR} ,在 chdir 进入

    我不明白为什么 gmake 然而,他们的行为方式是一样的。对我来说,这感觉就像一个虫子。