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

StackMasher

Well-Known Member
Member
Joined
Nov 29, 2016
Messages
136
Reaction score
65
Trophies
0
Age
23
XP
410
Country
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,
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
 
And I want %/ to be always ran. .PHONY doesn't seem to work, what else could I try?

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
 

Site & Scene News

Popular threads in this forum