Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to @Jonathan Wakely to provide me some starting ideas for this solution.</p> <p>There are probably a lot of thing that may be improved, but it work.</p> <p>Requirment summary:</p> <ul> <li>Makefiles should be standalone</li> <li>The main makefile should include sub-makefiles</li> <li>No conflicts or path problem shouls appear.</li> </ul> <p>A simple solution is to call recursively makefiles:</p> <ul> <li>Create a "normal" script for leaf makefiles</li> <li>Using an <strong>empty target</strong> allow to execute always make calls for example "sub-make:" without any requirment after ":"</li> <li>Use the "<strong>-C</strong>" parameter to set the root directory for the make call.</li> <li>Create the final linking with binaries created by sub-makefiles.</li> </ul> <p>Example for the main makefile:</p> <pre><code>#all make recursive calls sub-make: make -C Vector3D make -C Color #final linking CPP = g++ FLAGS = $(CXXINCS) -Wall -O0 all: main main: main.o Vector3D/Vector3D.o Color/Color.o $(CPP) main.o Vector3D/Vector3D.o Color/Color.o -o main main.o: main.cpp $(CPP) -c main.cpp -o main.o $(FLAGS) </code></pre> <p>There is probably a better way to provide *.o binaries to the linker without writting all full path, but that is another problem.</p> <p>Creating the clean target. For leaf makefiles, there si no special considerations to take, but for the main makefile, it must call sub-clean rules.</p> <pre><code>clean: make -C Vector3D clean make -C Color clean rm -f *.o main </code></pre> <p><strong>EDITING:</strong></p> <p>Here is the makefile structure I have done, for if it may be useful to anyone.</p> <p>To work, All classes must be in is own folder with:</p> <ul> <li>.hpp header</li> <li>.cpp code</li> <li>main.cpp for testing</li> <li>Required classes (LIBS) directory are specified with "$(LIBSPATH)LibName" in relation to this makefile.</li> </ul> <p>Makefile</p> <pre><code>#Following configuration may be set with a parameter: # e.g: make FLAGS="-Wall -O0" FLAGS = $(CXXINCS) -Wall -O0 #Configurable variables EXEC = main CLASS = World LIBS = Color Vector3D Triangle LIBSPATH = ../ #Static content CPP = g++ OBJS = $(foreach dir, $(LIBS), $(LIBSPATH)$(dir)/$(dir)) all: $(EXEC) clean: rm -f *.o $(EXEC) $(foreach dir,$(LIBS),make clean --no-print-directory -C $(LIBSPATH)$(dir);) $(EXEC): $(CLASS).o $(EXEC).o $(OBJS:=.o) $(CPP) $(CLASS).o $(OBJS:=.o) $(EXEC).o -o $(EXEC) $(EXEC).o: $(EXEC).cpp $(CPP) -c $(EXEC).cpp -o $(EXEC).o $(CXXFLAGS) $(CLASS).o: $(CLASS).cpp $(CLASS).hpp $(CPP) -c $(CLASS).cpp -o $(CLASS).o $(CXXFLAGS) $(OBJS:=.o): $(OBJS:=.cpp) $(OBJS:=.hpp) make --no-print-directory -C $(LIBSPATH)$(strip $(foreach dir,$(LIBS),$(if $(findstring $(dir),$@),$(dir)))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload