How do I write the 'cd' command in a makefile?

后端 未结 6 474
时光取名叫无心
时光取名叫无心 2020-11-29 14:53

For example, I have something like this in my makefile:

all:
     cd some_directory

But when I typed make I saw only \'cd some

6条回答
  •  长情又很酷
    2020-11-29 15:25

    Starting from GNU make 3.82 (July 2010), you can use the .ONESHELL special target to run all recipe lines in a single instantiation of the shell (bold emphasis mine):

    • New special target: .ONESHELL instructs make to invoke a single instance of the shell and provide it with the entire recipe, regardless of how many lines it contains.
    .ONESHELL: # Only applies to all target
    all:
        cd ~/some_dir
        pwd # Prints ~/some_dir if cd succeeded
    
    another_rule:
        cd ~/some_dir
        pwd # Oops, prints ~
    

提交回复
热议问题