Other Makefile not seeing my files

I have this issue with make that is driving me nuts. I have a directory with files Makefile2 and main.c, but the makefile doesn't see main.c:
Code:
t14s% cd PCG
t14s% ls -l Makefile2 main.c
-rw-r--r--  1 yousef  yousef    24 Jul 23 01:59 Makefile2
-rw-r--r--  1 yousef  yousef  3198 Jul 22 08:18 main.c
t14s% cat Makefile2
default:
    ls -l main.c
t14s% make -f Makefile2
ls -l main.c
ls: main.c: No such file or directory
*** Error code 1

Stop.
make: stopped in /usr/home/yousef/PCG
t14s% ls -l main.c
-rw-r--r--  1 yousef  yousef  3198 Jul 22 08:18 main.c
t14s%

Am I missing something here?
 
If the current directory contains a directory called obj, then BSD make will cd into it first before executing any of the recipes / rules. To test; use the following:

Code:
default:
    pwd
    ls -l main.c

Obviously if make is now running commands from an unexpected directory, your current rules are likely to break.
 
A good way to learn about such things is to use ktrace and look at kdump output. For example, try "ktrace -di make -f Makefile2". Then do "kdump | grep -C 1 NAMI | less" -- this will show all the syscalls used that use a path. Ignore all syscalls that fail (the line after NAMI with be something like "<pid> <cmdname> RET <syscallname> -1 errno <err num> <error text>"). Particularly look for "chdir" syscalls. As kpedersen said, you likely have an "obj" subdir or may be "obj.amd64" or "obj.amd64-amd64" if on a x86-64 machine.
 
Any chance there are funny or invisible characters in the file name main.c or in the Makefile2? E.g. a space as in "main.c "? Try `ls -B` to force printing non-printable characters as octal bytes.
Try `od -bc Makefile2` looking for funnies.
 
If the current directory contains a directory called obj, then BSD make will cd into it first before executing any of the recipes / rules. To test; use the following:

Code:
default:
    pwd
    ls -l main.c

Obviously if make is now running commands from an unexpected directory, your current rules are likely to break.
Thanks kpedersen, that was it!

Also, thanks bakul for the ktrace/kdump tips.
 
Back
Top