简体   繁体   English

从makefile调用shell脚本?

[英]Calling a shell script from a makefile?

I have a custom shell script to make twitter bootstrap from source and then move the files to my node.js app's /lib file: 我有一个自定义的shell脚本,可以从源代码进行twitter引导,然后将文件移动到我的node.js应用程序的/ lib文件中:

rm -r bootstrap
make bootstrap
mv -f bootstrap/css/* ../../lib/public/css
mv -f bootstrap/img/* ../../lib/public/img
mv -f bootstrap/js/* ../../lib/public/js

Running this from the shell works just fine using ./make_bootstrap.sh 使用./make_bootstrap.sh从shell运行此程序就可以了

Now I've created a Makefile for my full app (mainly compiling coffeescript and easy test initialization) and want to have a command that executes this custom shell script to build bootstrap. 现在,我为完整的应用程序创建了一个Makefile(主要是编译coffeescript和简单的测试初始化​​),并希望有一个执行该自定义shell脚本的命令来构建引导程序。 Here is my makefile 这是我的makefile

REPORTER = spec

all: build

build:
    @./node_modules/coffee-script/bin/coffee \
        -c \
        -o lib src

bootstrap:
    @./src/bootstrap \
        ./make_bootstrap.sh

clean:
    rm -rf lib
    mkdir lib

watch:
    @./node_modules/coffee-script/bin/coffee \
        -o lib \
        -cw src

test:
    @./node_modules/mocha/bin/mocha \
        --reporter $(REPORTER) \
        test/*.coffee

.PHONY: build bootstrap clean watch test

with the relevant command being 'make bootstrap'. 相关命令是“ make bootstrap”。 However when I run make bootstrap from the command line all I get is this error: 但是,当我从命令行运行make bootstrap时,得到的只是这个错误:

make: ./src/bootstrap: Permission denied
make: *** [bootstrap] Error 1

Originally I had assumed that it was a permission error but even setting all permissions on files (chmod 777) results in nothing. 最初,我以为这是一个权限错误,但是即使对文件(chmod 777)设置所有权限也不会产生任何结果。 Files I have given full permissions at this point include the root Makefile, my custom shell script in the bootstrap folder and the makefile within the bootstrap folder itself. 此时我已获得完全许可的文件包括根Makefile,bootstrap文件夹中的自定义shell脚本以及bootstrap文件夹本身内的makefile。

EDIT: 编辑:

Based on the comments I have refactored to this 根据评论,我将其重构为

bootstrap:
    rm -r src/bootstrap/bootstrap
    $(MAKE) -C ./src/bootstrap bootstrap
    mv -f src/bootstrap/bootstrap/css/* lib/public/css
    mv -f src/bootstrap/bootstrap/img/* lib/public/img
    mv -f src/bootstrap/bootstrap/js/* lib/public/js

This duplicates the functionality of the shell script I had before (moving files for my custom project) and still uses the standard makefile that Twitter Bootstrap ships with. 这复制了我以前拥有的shell脚本的功能(正在为我的自定义项目移动文件),并且仍然使用Twitter Bootstrap附带的标准makefile。 Much cleaner... I'm going to live the original answer below so people can see the evolution and refactor. 更清洁...我将使用下面的原始答案,以便人们可以看到演变和重构。

OLD ANSWER 老答案

Ok thank you guys in the comments for pointing my in the right direction. 好的,谢谢你们在评论中指出我的正确方向。 This solution works: 此解决方案有效:

bootstrap:
    cd ./src/bootstrap; \
        ./make_bootstrap.sh

What happens is it executes the change directory (in a sub process so it doesn't affect where I run make from) and then executes the custom script. 发生的事情是它执行更改目录(在一个子过程中,因此它不会影响我从哪里运行make),然后执行自定义脚本。 It seems as if I probably shouldn't be using something like this in a makefile since it feels 'dirty'; 似乎我可能不应该在makefile中使用这样的东西,因为它感觉很“脏”。 perhaps a more clean way to do it would be to invoke the LESS compiler myself and mimic the makefile provided by bootstrap. 也许更干净的方法是自己调用LESS编译器并模拟引导程序提供的makefile。 I'm using this for a tiny personal project though so it does the job. 我将其用于一个很小的个人项目,因此可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM