简体   繁体   English

使用makefile作为依赖项的Makefile目标

[英]Makefile target with makefile as dependency

I am currently working on a project where I have a couple applications in a parent folder that need to be rebuilt whenever the libraries contained in child folders are updated. 我目前正在开发一个项目,我在父文件夹中有几个应用程序需要在子文件夹中包含的库更新时重建。 The apps in the parent folder are built with a makefile, and the libraries are built with a separate makefile in the respective folder. 父文件夹中的应用程序使用makefile构建,并且库在相应的文件夹中使用单独的makefile构建。 This looks something like : 这看起来像:

  • ParentDir ParentDir
    • app1 APP1
    • app2 APP2
    • Makefile Makefile文件
      • libdir1 libdir1
        • Makefile Makefile文件
      • libdir2 libdir2
        • Makefile Makefile文件

I'm currently doing something like this for my makefile in the parent dir 我正在为父目录中的makefile做这样的事情

all : app1 app2

libs = libdir1/lib1.a libdir2/lib2.a
.PHONY : $(libs)


$(all) : $(libs)
    #do stuff to make the apps

libdir1/lib1.a : 
    $(MAKE) -c libdir1


libdir2/lib2.a : 
    $(MAKE) -c libdir2

My problem is, I don't want the apps in the parent dir's makefile to rebuild unless one of the makefiles it "depends" on are updated. 我的问题是,我不希望父目录的makefile中的应用程序重建,除非它“依赖”的其中一个makefile被更新。 I know that the reason this is happening currently is that I have my libs declared as PHONY ( so they always rebuild ), but that was the only way I could figure out to actually call the children makefiles. 我知道目前发生这种情况的原因是我将我的libs声明为PHONY(所以他们总是重建),但这是我能想出实际调用子makefile的唯一方法。

So, what I want is for each app to build only when either of the libdirs makefile's would actually do something, and to call each libdir's makefile that would "do something" before building the app. 所以,我想要的是每个应用程序仅在libdirs makefile中的任何一个实际执行某些操作时构建,并且在构建应用程序之前调用每个libdir的makefile以“做某事”。

Thanks for your help in advance. 感谢您的帮助。

You should make a dummy dependency for the libraries so that their Makefiles are always processed. 您应该为库创建一个虚拟依赖项,以便始终处理它们的Makefile。 Here is a good example and explanation: http://owen.sj.ca.us/~rk/howto/slides/make/slides/makerecurs.html 这是一个很好的例子和解释: http//owen.sj.ca.us/~rk/howto/slides/make/slides/makerecurs.html

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

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