#25 $CURDIR incompatible with gnumake

本文讨论了在使用makepp和gnumake时遇到的CURDIR不一致问题,通过详细分析和逐步排查,最终确定了问题原因并提供了解决方案。主要涉及makepp和gnumake的工作原理及CURDIR变量的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#25 $CURDIR incompatible with gnumake

Status: closed-invalid

Owner: nobody

Labels: None

Priority: 5

Updated: 2012-02-16

Created: 2011-12-13

Creator: Credzba

Private: No

I noticed that the release notes for 1.14 says that CURDIR is now compatible, but in my testing with 1.15 and 2.0rc makepp returns the current file directory (if its included, then the directory of the include) while gnumake always returns the original makefile location.

gnu documentation at http://www.gnu.org/s/hello/manual/make/Recursion.html states:
For your convenience, when GNU make starts (after it has processed any -C options) it sets the variable CURDIR to the pathname of the current working directory. This value is never touched by make again: in particular note that if you include files from other directories the value of CURDIR does not change. The value has the same precedence it would have if it were set in the makefile (by default, an environment variable CURDIR will not override this value). Note that setting this variable has no impact on the operation of make (it does not cause make to change its working directory, for example).

makepp documentation at http://makepp.sourceforge.net/2.0/makepp_variables.html#curdir states:
CURDIR
The directory in which the current Makefile resides.

Discussion

  • Daniel Pfeiffer
    Daniel Pfeiffer
    2011-12-13

    I can't reproduce this. Given /tmp/abc/Makeppfile with:

    &echo bef $(CURDIR)
    include toto
    &echo aft $(CURDIR)

    and /tmp/toto with:

    &echo inc $(CURDIR)

    mpp prints:

    bef /tmp/abc
    inc /tmp/abc
    aft /tmp/abc

    Can you please attach some simple files that reproduce your case?

    regards -- Daniel

     

    Link

    •  
  • Credzba
    Credzba
    2011-12-14

    I tried your test, and it worked just as it did for you, then I retried my production code, and it had the same problem ! So.. just need to shrink the problem.

    Here is what I found ..

    setup your files slightly different:
    abc/Makefile (will include ../toto/Makefile.inc)

    move your toto to
    ../toto/Makefile.inc (so it will get included properly)
    create a ../toto/Makefile (this is the root problem)

    Now when you makepp in abc directory, you will see it loads the Makefile in toto directory just before it loads toto/Makefile.inc, and Makefile.inc will now have the CURDIR of ITS toto/Makefile, not the original Makefile.

    Perhaps this is a feature of makepp, and I can turn it off ?

     

    Link

    •  
  • Daniel Pfeiffer
    Daniel Pfeiffer
    2011-12-14

    I still don't get it. I set it up as you write, with an echo in the new file too, and I get:

    makepp: Loading makefile `/tmp/abc/Makefile'
    bef /tmp/abc
    makepp: Loading makefile `/tmp/toto/Makefile'
    toto/mf /tmp/toto
    inc /tmp/abc <-- still right
    aft /tmp/abc

    The way you describe it, loading the extra makefile doesn't seem to be your problem. But just in case, be aware that makepp will check if it needs to (re)create an include file. As it does not have a rule for toto/Makefile.inc yet, it will try to load a makefile in its directory to see if that produces a rule. It does not here, so loading the makefile has no effect (at least in my setup, where it does nothing except echo).

    So please try to narrow down your problem to a small tarball that reproduces what you mean!

    regards -- Daniel

     

    Link

    •  
  • Credzba
    Credzba
    2011-12-15

    The problem is the Makefile in toto has an include for Makefile.inc as well, and since it gets loaded Makefile.inc gets loaded with an invalid directory (in my case).

    I think I can work around the problem by moving Makefile out of the include directory or tell it not to try to find a rule for Makefile.inc (if that is possible).

    here are sample executions with make and makepp:
    % makepp
    makepp: Loading makefile `/c/users/desktop/maketest/main/makefile'
    CURDIR in main is /c/users/desktop/maketest/main
    makepp: Loading makefile `/c/users/desktop/maketest/secondary/makefile'
    Makefile from secondary loaded
    CURDIR in secondary is /c/users/desktop/maketest/secondary
    CURDIR in secondary is /c/users/desktop/maketest/main
    CURDIR in main after include is /c/users/desktop/maketest/main
    makepp: Entering directory `/c/users/desktop/maketest/main'
    Main Target all
    makepp: 0 files updated and 1 phony target built

    09:22 PM ~/makeTest/main
    % make
    CURDIR in main is /c/Users/desktop/makeTest/main
    CURDIR in secondary is /c/Users/desktop/makeTest/main
    CURDIR in main after include is /c/Users/desktop/makeTest/main
    Main Target all

     

    Link

    •  
  • Daniel Pfeiffer
    Daniel Pfeiffer
    2011-12-16

    Ok, now it's clear: you have a misconception here. Makefile.inc is not a makefile in its own right. It does not have its own value of CURDIR. Instead you must think of it, as though it were copy pasted literally instead of the include statements, just like #include in C.

    The difference to gmake is that mpp is more thorough in that it loads secondary/Makefile too. This gives you an extra output, which is correct from that makefile. You can verify this with mpp --dont-build ../secondary which is essentially like gmake.

     

    Link

    •  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值