Hello people of the internet,
Firstly I must apologize as I am relatively new to makefiles, so I may be doing this in a very unorthodox way.
I am trying to create a makefile that will
-loop through each subdirectory of a specified directory
-check the directory is the specified directory or one of the subdirectories
-run the directory's through tree and then generate an image of the tree using convert with the filepath removed.
At this point, I'm getting absolutely lost and have no idea where these issues are coming from. The whole idea is to make this code project agnostic. I have a hard coded version that works fine with all of the directories and subdirectories specified manually.
I have tried two methods so far.
Method 1
PROJECT_DIR = ../hub/hub/
SUB_DIRECTORIES = $(shell find $(PROJECT_DIR) -maxdepth 1 -type d -exec echo {} \;)
SUB_DIRECTORIES_FORMATTED = $(SUB_DIRECTORIES) | sed 's|..\/hub\/hub\/||g' | sed 's/\s\+/|/g'
all:
@echo $(SUB_DIRECTORIES)
for $(directory) in $(SUB_DIRECTORIES); do \
if test $$directory = $(PROJECT_DIR); then \
echo "Generating root.png" && tree -P '*.py' -I '__pycache__|.c' $(directory) | convert -size 364x422 label:@- ./source/root.png; \
else \
"Generating $(subst $(PROJECT_DIR),,$(directory)) png" && tree -P '*.py' -I '__pycache__|.c' $(directory) | convert -size 364x422 label:@- ./source/$(subst $(PROJECT_DIR),,$(directory)).png; \
fi \
done
With this method, the subst isn't working thus resulting in these errors: Method 1 errors
Method 2
PROJECT_DIR = ../hub/hub/
SUB_DIRECTORIES =: $(shell find $(PROJECT_DIR) -maxdepth 1 -type d -exec echo {} \;)
SUB_DIRECTORIES_FORMATTED = $(SUB_DIRECTORIES) | sed 's|..\/hub\/hub\/||g' | sed 's/\s\+/|/g'
all:
@$(foreach file, $(wildcard $(SUB_DIRECTORIES)/), \
$(if $(filter $(file), $(PROJECT_DIR)), \
$(shell tree -P '*.py' -I '__pycache__|.c' $(file) | convert -size 364x422 label:@- ./source/root.png;), \
$(shell tree -P '*.py' -I '__pycache__|.c' $(file) | convert -size 364x422 label:@- ./source/$(subst $(PROJECT_DIR),,$(file)).png;) \
) \
);
This method causes another error: method 2 errors
thank you for your comments.
The issue was coming from the added "" after $(SUB_DIRECTORIES) and the semi-colon at the end. It's relieving to know that I was not far off from the solution. I was able to get it to work with Method 2 using the following code. :
PROJECT_DIR = ../hub/hub/
SUB_DIRECTORIES = $(shell find $(PROJECT_DIR) -maxdepth 1 -type d -exec echo {} \;)
SUB_DIRECTORIES_FORMATTED = $(SUB_DIRECTORIES) | sed 's|..\/hub\/hub\/||g' | sed 's/\s\+/|/g'
all:
$(foreach file, $(wildcard $(SUB_DIRECTORIES)), \
$(if $(filter $(file), $(PROJECT_DIR)), \
$(shell tree -P '*.py' -I '__pycache__|.c' $(file) | convert -size 1280x1024 label:@- ./source/root.png), \
$(shell tree -P '*.py' -I '__pycache__|.c' $(file) | convert -size 1280x1024 label:@- ./source/$(subst $(PROJECT_DIR),,$(file)).png) \
) \
)