Thread: Strange makefile bug

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617

    Strange makefile bug

    Here's my output, see if you can spot the problem:
    Code:
    make --no-print-directory DEBUG=1 rebuild
    wildcard ../../../../* =  ../../../../argv.c ../../../../bin ../../../../include ../../../../mak ../../../../makefile ../../../../README.md ../../../../src ../../../../test
    wildcard ../../../../mak/* =  ../../../../mak/caninc.mak ../../../../mak/common.mak ../../../../mak/makefile ../../../../mak/system.mak
    cd ../../ && make  --no-print-directory -- DEBUG=1 clean
    makefile:3: ../../../../mak/common.mak: No such file or directory
    make[1]: *** No rule to make target '../../../../mak/common.mak'.  Stop.
    make: *** [makefile:29: clean] Error 2
    Compilation failed.
    The code that produces it:
    Code:
    TOP_DIR?=../../../../
    MAK_DIR:=$(TOP_DIR)mak/
    $(info wildcard $(TOP_DIR)* =  $(wildcard $(TOP_DIR)*))
    $(info wildcard $(MAK_DIR)* =  $(wildcard $(MAK_DIR)*))
    include $(MAK_DIR)common.mak
    Edit: never mind I spotted the issue, didn't realise TOP_DIR was corrupting the expected directory in the child make process (did think it strange that a cd ../../ showed up despite the error)

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617
    Found another bug that confounds me, not even sure if the bug is mine or make's, here's my makefile:
    Code:
    MAKECMDGOALS?=info
    MAKECMDGOALS:=$(filter-out build%,$(MAKECMDGOALS))
    
    $(if $(filter w,$(MAKEFLAGS)),$(error Why!?))
    $(if $(filter w,$(MAKECMDGOALS)),$(error Why!?))
    
    export _DEBUG
    export MAKEFLAGS
    
    %.all:
    	$(MAKE) DIR=src/basic -f gnu.mak $*
    	$(MAKE) DIR=src/extra -f gnu.mak $*
    	$(MAKE) DIR=src/extra/viewfx/glfw -f gnu.mak $*
    	$(MAKE) DIR=src/extra/viewfx/opengl -f gnu.mak $*
    
    $(MAKECMDGOALS):
    	$(MAKE) -f gnu.mak $@
    Somehow the blasted thing loops onto itself (despite being clearly directed to a different file) and even appends/inserts "w --" into MAKEFLAGS, any ideas how to put an end to that?

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617
    Turns out that w comes from make inserting an implied flag, if it's implied it shouldn't need to be inserted in the 1st place, anyways I also found out that the file flag doesn't do as any normal developer would expect and stop make from looking for default files, no instead it serves as a fallback location for any undefined goals, that completely defeats the purpose of a file flag, I've now had to add a define guard to my makefile to stop it re-using stuff it's not even supposed to be looking at in child processes.

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    843
    Quote Originally Posted by awsdert View Post
    Turns out that w comes from make inserting an implied flag, if it's implied it shouldn't need to be inserted in the 1st place
    The -w flag is only for printing the directory that a child call to make is entering/leaving, which is pretty much expected behavior.

    anyways I also found out that the file flag doesn't do as any normal developer would expect and stop make from looking for default files, no instead it serves as a fallback location for any undefined goals, that completely defeats the purpose of a file flag
    Really? What version of make are you using that doesn't simply use the -f flag only as the makefile to use and falls back on a default makefile?

    Code:
    $ cat makefile
    all:
    	echo makefile
    $ cat asdfasdf
    asdfasdf:
    	echo asdfasdf
    $ make -f asdfasdf all
    make: *** No rule to make target 'all'.  Stop.
    Clearly my version of make only reads the file "asdfasdf" and doesn't even look at the default "makefile" file. That's standard, expected behavior.

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617
    Quote Originally Posted by christop View Post
    The -w flag is only for printing the directory that a child call to make is entering/leaving, which is pretty much expected behavior.
    You're missing the point, if the parent make defaults to assuming the flag is set the the child process should be doing the same, there should be no adding the flag directly unless it is directly seen in the arguments given to make in the 1st place, it's perfectly possible for make to distinguish between an implied flag and an explicit flag simply by comparing the pointer obtained for the flag string to the default string's pointer, something like this:
    Code:
    ...
    char const *_arg_w = "-w", *arg_w = _arg_w;
    ...
    arg_w = argv[i];
    ...
    if ( arg_w != _arg_w )
       add_arg( &args, &size, arg_w );
    ...
    Either way the child process still needs to check it's arguments so why make makefiles harder to use than they should be?

    Quote Originally Posted by christop View Post
    Really? What version of make are you using that doesn't simply use the -f flag only as the makefile to use and falls back on a default makefile?

    Code:
    $ cat makefile
    all:
    	echo makefile
    $ cat asdfasdf
    asdfasdf:
    	echo asdfasdf
    $ make -f asdfasdf all
    make: *** No rule to make target 'all'.  Stop.
    Clearly my version of make only reads the file "asdfasdf" and doesn't even look at the default "makefile" file. That's standard, expected behavior.
    That's what I thought too, but results did not follow that expectation, as for what version of make I have, this is what "make -v" gav e me:
    Code:
    GNU Make 4.3
    Built for x86_64-pc-linux-gnu
    Copyright (C) 1988-2020 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange error when compile C program using makefile
    By digioleg54 in forum C Programming
    Replies: 3
    Last Post: 01-03-2018, 02:01 PM
  2. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  3. regarding makefile
    By cnu_sree in forum Linux Programming
    Replies: 1
    Last Post: 07-25-2007, 03:47 AM
  4. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM
  5. strange strange functions
    By threahdead in forum C Programming
    Replies: 4
    Last Post: 10-13-2002, 05:31 PM

Tags for this Thread