in reply to Re^5: dmake and bash on Win?
in thread let Makefile.PL to do the Readme file for me -- new target?

> I am not convinced my example contains "shell" code.

I was referring to

skip "rm -rf cover_db"

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^7: dmake and bash on Win?
by pryrt (Abbot) on Jan 21, 2021 at 18:03 UTC
    I was referring to skip "rm -rf cover_db"

    Okay, that comes from my distro's Makefile.PL lines 124-129:

    # addition to realclean: also delete coverage database, if testcover w +as run realclean :: $(NOECHO) ( $(TEST_D) cover_db && $(RM_RF) cover_db ) || $(ECHO) r +ealclean:: skip "rm -rf cover_db" $(NOECHO) ( $(TEST_F) LICENSE.pod && $(RM_RF) LICENSE.pod ) || $(E +CHO) realclean:: LICENSE.pod intermediary $(NOECHO) ( $(TEST_F) README.pod && $(RM_RF) README.pod ) || $(ECH +O) realclean:: README.pod intermediary $(NOECHO) ( $(TEST_F) MYMETA.json.lock && $(RM_RF) MYMETA.json.loc +k ) || $(ECHO) realclean:: MYMETA.json.lock temp file

    It is using a variety of macros:

    • the $(NOECHO) macro from MakeMaker, which on cmd.exe prefixes the command with "@" so it won't print the command line first.
    • my $(TEST_D) macro, defined on lines 109-110, which is inspired by the MakeMaker macro $(TEST_F) for testing the existing of a file. When I looked at the Makefile for $(TEST_F) implementation on my system, I saw it used ExtUtils::Command from the ExtUtils::MakeMaker distro, which as described makes versions of common UNIX commands from makefiles, and makes them available to the Makefile, for doing a common linux/bash idiom in non-linux/non-bash shells. I took that inspiration for the $(TEST_D) macro, which tests for directory existence using the same module/idiom
    • the $(RM_RF) is a MakeMaker-defined macro, which again can use ExtUtils::Command for its implementation on systems that don't know rm -rf, and may just expand to rm -rf on systems that do know it
    • The || works on both Windows and Linux for only running the second command if the first command fails, and && for only running the second if the first passes. I don't know how portable it is beyond those (I have never run a rule with the || or && syntax on any system other than Windows or Linux -- I do my development mostly on Windows with occasionally running things on Linux, so that's where I run my custom makefile targets; CI and the CPAN smoketesters run my Makefiles on a variety of other systems, but those just run the standard targets for the make/test sequence).
    • $(ECHO) resolves to a ExtUtils::Command call on my system.

    By using the macro variables that MakeMaker defines in the Makefile instead of literally using common UNIX-style commands, you can write rules that are much less dependent upon the system you are on, the availability of bash, etc., and will work cross-platform but will still look and behave like the linux commands that many are used to using.

    Again, I recommend looking through the Makefile that perl Makefile.PL generates in your build environment; using that, you can see what macros are available to you, and how they are implemented on your system.

      Are you saying that the literal "rm -rf cover_db" is never executed and just used as comment or message?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Are you saying that the literal "rm -rf cover_db" is never executed and just used as comment or message?

        Yes, that is what I am saying.

        When the Makefile runs the command $(ECHO) realclean:: skip "rm -rf cover_db", it effectively prints all the arguments after the $(ECHO) as text to the console/terminal/equivalent. I am just using that as a debug print to tell me that it didn't delete cover_db (probably because it didn't exist).