Heredoc in a Makefile?

前端 未结 7 1068
半阙折子戏
半阙折子戏 2020-12-25 12:36

Is this possible at all and how?

Update: I need this because I create a file both from dynamic and static data.

Use case:

7条回答
  •  情深已故
    2020-12-25 13:17

    GNU Makefile can do things like the following. It is ugly, and I won't say you should do it, but I do in certain situations.

    .profile = \
    \#!/bin/sh.exe\n\
    \#\n\
    \# A MinGW equivalent for .bash_profile on Linux.  In MinGW/MSYS, the file\n\
    \# is actually named .profile, not .bash_profile.\n\
    \#\n\
    \# Get the aliases and functions\n\
    \#\n\
    if [ -f \$${HOME}/.bashrc ]\n\
    then\n\
      . \$${HOME}/.bashrc\n\
    fi\n\
    \n\
    export CVS_RSH="ssh"\n  
    #
    .profile:
            echo -e "$($(@))" | sed -e 's/^[ ]//' >$(@)
    

    make .profile creates a .profile file if one does not exist.

    This solution was used where the application will only use GNU Makefile in a POSIX shell environment. The project is not an open source project where platform compatibility is an issue.

    The goal was to create a Makefile that facilitates both setup and use of a particular kind of workspace. The Makefile brings along with it various simple resources without requiring things like another special archive, etc. It is, in a sense, a shell archive. A procedure can then say things like drop this Makefile in the folder to work in. Set up your workspace enter make workspace, then to do blah, enter make blah, etc.

    What can get tricky is figuring out what to shell quote. The above does the job and is close to the idea of specifying a here document in the Makefile. Whether it is a good idea for general use is a whole other issue.

提交回复
热议问题