Bug 230492 - make: -C option doesn't work as explained in man page about value of ${.CURDIR} when logical and physical directory are different.
Summary: make: -C option doesn't work as explained in man page about value of ${.CURDI...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-10 01:39 UTC by Yasuhiro KIMURA
Modified: 2018-08-10 02:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yasuhiro KIMURA 2018-08-10 01:39:43 UTC
In the man page of make(1) '-C' options is explained as following.

----------------------------------------------------------------------
     -C directory
             Change to directory before reading the makefiles or doing
             anything else.  If multiple -C options are specified, each is
             interpreted relative to the previous one: -C / -C etc is
             equivalent to -C /etc.
----------------------------------------------------------------------

This means 'make -C /foo/bar/baz' works same as 'cd /foo/bar/baz; make'.

But there is an case that make doesn't behaves so. As explained in summary it is about value of ${.CURDIR} and happens when logical and physical directory are different.

Let me explain it by providing an example.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd1[2018]% pwd
/home/yasu/tmp
yasu@rolling-vm-freebsd1[2019]% ls -l
total 1
lrwxr-xr-x  1 yasu  user  3  8月 10 08:21 bar@ -> foo
drwxr-xr-x  2 yasu  user  3  8月 10 08:20 foo/
----------------------------------------------------------------------

/home/yasu/tmp/foo is real directory and /home/yasu/tmp/bar is symbolic link to it. So logical and physical expression of /home/yasu/tmp/bar is different.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd1[2020]% cd /home/yasu/tmp/bar
yasu@rolling-vm-freebsd1[2021]% /bin/pwd -L
/home/yasu/tmp/bar
yasu@rolling-vm-freebsd1[2022]% /bin/pwd -P
/home/yasu/tmp/foo
----------------------------------------------------------------------

And there is following Makefile under /home/yasu/tmp/bar.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd1[2023]% cat Makefile                                                                       ~/tmp/bar
all:
        @echo ${.CURDIR}
----------------------------------------------------------------------

It simply displays value of ${.CURDIR}.

Now let's execute make without any arguments. It causes following result.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd1[2024]% make                                                                               ~/tmp/bar
/home/yasu/tmp/foo
----------------------------------------------------------------------

Physical expression of current working directory is displayed.

Next, let's execute make with -C options and logical expression of current working directory. In this case it result as following.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd1[2025]% make -C /home/yasu/tmp/bar                                                         ~/tmp/bar
/home/yasu/tmp/bar
----------------------------------------------------------------------

If '-C' options works exactly as explained in man page, same value as previous execution, that is, physical expression of current working directory should be displayed. Actually, however, what is displayed is logical expression of current working directory. This means '-C' option doesn't work as explained in man page.

I confirmed it happens on both 11.2-RELEASE and 12.0-CURRENT (r337160).