0

I was given a Makefile for an assignment that gives me a make clean command. With the way the repository is set up, it deletes everything in the /bin and /out folders, except for a file called .gitignore. This is what the command looks like:

clean:
    find out/ ! -name .gitignore -type f -delete && \
    find bin/ ! -name .gitignore -type f -delete

Now that I'm doing my project, I need to store things in a folder called /bin/fonts and /bin/word_lists. I'm trying to modify the command so that it ignores these two files. The only problem is, I don't know what language these commands are written in, so I don't even know where to start looking at the syntax. Could somebody point me in the right direction? I tried something like this:

clean:
    find out/ ! -name .gitignore -type f -delete && \
    find bin/ ! -name .gitignore ! -name fonts/FreeSans.ttf -type f -delete

But it still deletes everything in fonts, and even if it did work the way I wanted, that doesn't really solve the problem of saving every single font in the folder.

I also tried this:

clean:
    find out/ ! -name .gitignore -type f -delete && \
    find ./bin -mindepth 1 ! -name .gitignore ! -regex '^./fonts/\(/.*\)?' ! -regex '^./word_lists/\(/.*\)?' -delete

following this post, but it instead deleted everything INCLUDING the folders bin/fonts as well as bin/word_lists.

Any help would be greatly appreciated!

Alex Peniz
  • 483
  • 5
  • 14
  • Make recipes are written in POSIX shell syntax. However, a shell script is fundamentally a way to run other programs. In this case the program being run is `find`. So you should look up the documentation for the `find` program, either on the internet (try something like `unix find`) or on your system (run `man find`). – MadScientist May 24 '21 at 13:06
  • Personally I strongly recommend you do _NOT_ put stuff you want to keep as subdirectories of `bin`. Why not put them somewhere else? That would make your life a lot simpler. – MadScientist May 24 '21 at 13:07

1 Answers1

1

-name does not examine the full file path, it only matches against the file name (so -name FreeSans.ttf would match, but match this file name in any directory).

The predicate you are looking for is called -path but then you need to specify a pattern for the entire path.

clean:
    find out/ bin/ ! -name .gitignore ! -path 'bin/fonts/*
 ! -path 'bin/word_lists/*' -type f -delete

(Notice also how I condensed the find to traverse two directories at the same time. I assume you mean bin not /bin; perhaps see also Difference between ./ and ~/)

tripleee
  • 175,061
  • 34
  • 275
  • 318