如何从make目标手动调用另一个目标? [英] How to manually call another target from a make target?

查看:100
本文介绍了如何从make目标手动调用另一个目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个这样的文件:

I would like to have a makefile like this:

cudaLib :
    # Create shared library with nvcc

ocelotLib :
    # Create shared library for gpuocelot

build-cuda : cudaLib
    make build

build-ocelot : ocelotLib
    make build

build :
    # build and link with the shared library

*Lib任务创建一个库,该库可直接在设备或gpuocelot上直接运行cuda.

I.e. the *Lib tasks create a library that runs cuda directly on the device, or on gpuocelot respectively.

对于这两个构建任务,我需要运行相同的构建步骤,只是创建库有所不同.

For both build tasks I need to run the same build steps, only creating the library differs.

是否可以直接运行make?

Is there an alternative to running make directly?

make build

需要某种职位吗?

推荐答案

正如您所写,build目标将需要做一些不同的事情,具体取决于您是刚刚完成了豹猫还是cuda建造.这就是说您必须以​​某种方式参数化build的另一种方式.我建议使用单独的构建目标(非常像您已经拥有的)以及相关联的变量.像这样:

As you have written it, the build target will need to do something different depending on whether you have just done an ocelot or cuda build. That's another way of saying you have to parameterise build in some way. I suggest separate build targets (much like you already have), with associated variables. Something like:

build-cuda: cudaLib
build-ocelot: ocelotLib

build-cuda build-ocelot:
    shell commands
    which invoke ${opts-$@}

在命令行上键入make build-cuda(例如).首先构建cudaLib,然后执行build-cuda的配方.它在调用外壳程序之前扩展宏.在这种情况下,$@build-cuda,因此首先将${opts-$@}扩展为${opts-build-cuda}. Make现在继续展开${opts-build-cuda}.您将在makefile中的其他位置定义opts-build-cuda(当然还有它的姐妹opts-build-ocelot).

On the command-line you type make build-cuda (say). Make first builds cudaLib, then it carries out the recipe for build-cuda. It expands the macros before calling the shell. $@ in this case is build-cuda, thus ${opts-$@} is first expanded to ${opts-build-cuda}. Make now goes on to expand ${opts-build-cuda}. You will have defined opts-build-cuda (and of course its sister opts-build-ocelot) elsewhere in the makefile.

P.S.自build-cuda等. al.不是真实文件,最好告诉这个(.PHONY: build-cuda).

P.S. Since build-cuda et. al. are not real files, you had better tell make this (.PHONY: build-cuda).

这篇关于如何从make目标手动调用另一个目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆