在Unix中,我可以在一个目录中运行'make'而不先cd到那个目录吗?
这是我的Makefile:
REBAR=./rebar
REBAR_COMPILE=$(REBAR) get-deps compile
all: compile
compile:
$(REBAR_COMPILE)
test:
$(REBAR_COMPILE) skip_deps=true eunit
clean:
-rm -rf deps ebin priv doc/*
docs:
$(REBAR_COMPILE) doc
ifeq ($(wildcard dialyzer/sqlite3.plt),)
static:
$(REBAR_COMPILE) build_plt analyze
else
static:
$(REBAR_COMPILE) analyze
endif
Run Code Online (Sandbox Code Playgroud)
我可以make compile多次运行并获得
aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make compile
./rebar get-deps compile
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)
Run Code Online (Sandbox Code Playgroud)
但是,出于某种原因,跑步make test总是给出
aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make test
make: `test' is up to date.
Run Code Online (Sandbox Code Playgroud)
即使文件没有编译.问题是,为什么?
直接运行相同的命令:
aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ ./rebar get-deps compile skip_deps=true eunit
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)
Compiled src/sqlite3_lib.erl …Run Code Online (Sandbox Code Playgroud) 我需要有条件地执行一些make规则,只要安装的Python大于某个版本(比如2.5).
我以为我可以做一些像执行:
python -c 'import sys; print int(sys.version_info >= (2,5))'
Run Code Online (Sandbox Code Playgroud)
然后在ifeqmake语句中使用输出(如果正常则为"1",否则为"0").
在一个简单的bash shell脚本中,它只是:
MY_VAR=`python -c 'import sys; print int(sys.version_info >= (2,5))'`
Run Code Online (Sandbox Code Playgroud)
但这在Makefile中不起作用.
有什么建议?我可以使用任何其他合理的解决方法来实现这一目标.
我经常发现Bash语法非常有用,例如像diff <(sort file1) <(sort file2).中的进程替换.
是否可以在Makefile中使用此类Bash命令?我在考虑这样的事情:
file-differences:
diff <(sort file1) <(sort file2) > $@
Run Code Online (Sandbox Code Playgroud)
在我的GNU Make 3.80中,这会产生错误,因为它使用shell而不是bash执行命令.
在我的GNUmakefile中,我希望有一个使用临时目录的规则.例如:
out.tar: TMP := $(shell mktemp -d)
echo hi $(TMP)/hi.txt
tar -C $(TMP) cf $@ .
rm -rf $(TMP)
Run Code Online (Sandbox Code Playgroud)
如上所述,上述规则在解析规则时创建临时目录.这意味着,即使我没有直接创建.tar,也会创建许多临时目录.我想避免我的/ tmp被未使用的临时目录弄乱.
是否有办法使该变量仅在触发规则时定义,而不是在定义时定义?
我的主要想法是将mktemp和tar转储到shell脚本中,但这看起来有点难看.
我在app特定目录中有几个Makefile,如下所示:
/project1/apps/app_typeA/Makefile
/project1/apps/app_typeB/Makefile
/project1/apps/app_typeC/Makefile
Run Code Online (Sandbox Code Playgroud)
每个Makefile在此路径中包含一个.inc文件:
/project1/apps/app_rules.inc
Run Code Online (Sandbox Code Playgroud)
在app_rules.inc里面我正在设置我希望在构建时放置二进制文件的目的地.我希望所有二进制文件都在各自的app_type路径中:
/project1/bin/app_typeA/
Run Code Online (Sandbox Code Playgroud)
我尝试过使用$(CURDIR),像这样:
OUTPUT_PATH = /project1/bin/$(CURDIR)
Run Code Online (Sandbox Code Playgroud)
但相反,我把二进制文件埋在整个路径名中,如下所示:( 注意冗余)
/project1/bin/projects/users/bob/project1/apps/app_typeA
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能获得执行的"当前目录",这样我才能知道app_typeX为了将二进制文件放在各自的类型文件夹中?
我已经使用了rake(一个Ruby make程序),它有一个选项来获取所有可用目标的列表,例如
> rake --tasks
rake db:charset # retrieve the charset for your data...
rake db:collation # retrieve the collation for your da...
rake db:create # Creates the databases defined in y...
rake db:drop # Drops the database for your curren...
...
Run Code Online (Sandbox Code Playgroud)
但似乎没有选择在GNU make中执行此操作.
显然,代码几乎就在那里,截至2007年 - http://www.mail-archive.com/help-make@gnu.org/msg06434.html.
无论如何,我几乎没有从makefile中提取目标,你可以将其包含在makefile中.
list:
@grep '^[^#[:space:]].*:' Makefile
Run Code Online (Sandbox Code Playgroud)
它将为您提供已定义目标的列表.这只是一个开始 - 例如,它不会过滤掉依赖项.
> make list
list:
copy:
run:
plot:
turnin:
Run Code Online (Sandbox Code Playgroud) 我的项目有以下makefile,我想为发布和调试版本配置它.在我的代码中,我有很多#ifdef DEBUG宏,所以这只是设置这个宏并将-g3 -gdwarf2标志添加到编译器的问题.我怎样才能做到这一点?
$(CC) = g++ -g3 -gdwarf2
$(cc) = gcc -g3 -gdwarf2
all: executable
executable: CommandParser.tab.o CommandParser.yy.o Command.o
g++ -g -o output CommandParser.yy.o CommandParser.tab.o Command.o -lfl
CommandParser.yy.o: CommandParser.l
flex -o CommandParser.yy.c CommandParser.l
gcc -g -c CommandParser.yy.c
CommandParser.tab.o: CommandParser.y
bison -d CommandParser.y
g++ -g -c CommandParser.tab.c
Command.o: Command.cpp
g++ -g -c Command.cpp
clean:
rm -f CommandParser.tab.* CommandParser.yy.* output *.o
Run Code Online (Sandbox Code Playgroud)
只是为了澄清,当我说发布/调试版本时,我希望能够只键入make并获得发布版本或make debug获得调试版本,而无需手动注释掉makefile中的内容.
快速提问:什么是编译器标志,允许g ++生成自身的多个实例,以便更快地编译大型项目(例如,一次为多核CPU提供4个源文件)?
非常感谢.
大多数linux应用程序都使用以
make
make install clean
Run Code Online (Sandbox Code Playgroud)
据我所知,make将构建目标的名称作为参数.所以install是一个目标是复制一些文件,之后clean是一个目标即删除临时文件.
但是make如果没有指定参数,会构建什么目标(例如我的例子中的第一个命令)?