0

I'm writing a Makefile and these are the clean and cleanall targets

clean:
        $(RM) *.o

cleanall: clean
        $(RM) $(TARGETS)

I have to use this on both linux and MacOs. When I compile on mac, in the process some folders with a dSYM extension are created and so I need to delete them too.

Is there a way to make the cleanall target delete those folders, but only if called on a mac?

I was looking for something like an if then else option but I found nothing.

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
ninazzo
  • 547
  • 1
  • 6
  • 17
  • 2
    For the actions in Makefiles, you can use the usual shell commands. So, you could add a line to the `clean:` target - something with `if`/`then`/`fi` checking for OS type and removing things conditionally. (FYI: [Bash - Conditionals](https://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html), [SO: How to detect the OS from a Bash script?](https://stackoverflow.com/a/8597411/7478597)) – Scheff's Cat Jul 15 '20 at 09:53
  • 1
    Assuming $(RM) expands to `rm -rf` you can remove the dSYM folders on all platforms as rm with force flag does not report error on trying to remove non-existing files or directories. – Andreas Jul 15 '20 at 11:39
  • @Andreas it only expands to rm -f, gives error with a directory – ninazzo Jul 15 '20 at 13:42
  • Then, you should change the definition of `RM` to be `rm -rf` instead of `rm -f`. – MadScientist Jul 15 '20 at 18:19

0 Answers0