How do you force a target to be always ran? (GNU Make)

Discussion in 'Computer Programming, Emulation, and Game Modding' started by StackMasher, Mar 26, 2017.

  1. StackMasher
    OP

    StackMasher GBAtemp Regular

    Member
    116
    55
    Nov 29, 2016
    I've written this makefile:
    Code:
    PATHS := ${shell echo */ | grep -v "*/"}
    OBJ := ${subst cpp,o,${shell echo *.cpp | grep -v "*.cpp"}}
    
    .PHONY: build
    build : $(PATHS)
       @echo ═════════════════════════════════════════
       @echo [*] Linking  
       @echo ═════════════════════════════════════════
       mkdir -p build
       -mv ${shell find src -type f -name "*.o"} build
       $(CXX) $(CXXFLAGS) ${shell echo build/*.o} -lSDL2 -lSDL2_image -o NewSuperTux
    
    .PHONY: subdirectory
    subdirectory : $(PATHS) $(OBJ)
       rm makefile
       @echo ------- Finished $*/ -------
    
    .PHONY: clean
    clean :
       @echo ═════════════════════════════════════════
       @echo [*] Cleaning up  
       @echo ═════════════════════════════════════════
       rm -rf build
    
    %/ :
       @echo ═════════════════════════════════════════
       @echo [!] Entering subdirectory $*/
       @echo ═════════════════════════════════════════
       cp makefile $*/
       cd $* && make subdirectory
    
    %.o : %.cpp
       @echo ═════════════════════════════════════════
       @echo [*] Compiling $^
       @echo ═════════════════════════════════════════
       $(CXX) $(CXXFLAGS) -c $^
    
    And I want %/ to be always ran. .PHONY doesn't seem to work, what else could I try?
     
    Last edited by StackMasher, Mar 26, 2017
  2. StackMasher
    OP

    StackMasher GBAtemp Regular

    Member
    116
    55
    Nov 29, 2016
    I'm using a phony target called "FORCE" that I put as one of %/'s dependencies, and it works now. Apparently this subdirectory crap is something makefiles are not good at so I'm pretty proud of what I've accomplished today, even if I wasted several hours doing it. Basically the makefile:
    • Creates of a copy of itself in any source directories
    • Each copy compiles the source files into a hidden folder ".build", and repeats the first step
    • The root makefile (which the user invoked) links all these object files together
    You can find the complete makefile here: https://github.com/RealPipeline/NewSuperTux/blob/master/makefile
     
  3. th3_r3v

    th3_r3v Newbie

    Newcomer
    8
    1
    Apr 6, 2017
    United States
    I just came across this article thinking about an easy way to complete this, (in Linux). I got the idea from a malware I had in my kernel so libs... write ur program in C lang and writes a dependency into a known ELF 'start-up'. Make it a lone subroutine with noops. Hope it gives you some inspiration.

    http://stackoverflow.com/questions/4827618/compiling-c-file-with-assembler-file-dependencies