I'm using Bash on Ubuntu and GNU Make 4.2.1.
I'm trying to write a Makefile that would perform simple operations on some data (.TXT files) I have. My different .TXT files are stored in 3 directories data/dir1 , data/dir2 and data/dir3.
For example, I would like to be able to type make count_dir1 or make count_dir2 or make count_dir3 in order to get the total number of lines withing a directory.
Without using a Makefile, I know how to do so when let's say my current directory is data/dir1 :
find . -name '*.TXT*' -type f | xargs wc -l
I get the number of lines of each file and the grand total which is exactly what I want.
Now, as for now, my targets basically look like that:
count_dir1: /home/data/dir1 @cd /home/data/dir1 &&\ find . -name '*.TXT*' -type f | xargs wc -l count_dir2: /home/data/dir2 @cd /home/data/dir2 &&\ find . -name '*.TXT*' -type f | xargs wc -l count_dir3: /home/data/dir3 @cd /home/data/dir3 &&\ find . -name '*.TXT*' -type f | xargs wc -l
So, everything works, but obviously, having three targets when I'm sure one would suffice is not efficient, but I don't know how to do so. I assume I would have to define some variables like:
dirs = /home/data/dir1 /home/data/dir2 /home/data/dir3
but then I'm not sure how to achieve my goal and from what I have read, I don't feel like it's a very good option to introduce variables that way.
Thank you in advance ! :)