Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have make build from one directory if the source file exists, otherwise build from another?

Tags:

makefile

I'm working on modifying a huge recursive makefile project that has 6000+ source files. All of which are clearcase controlled. Since I don't want to copy the whole source tree, I'm trying to create a new project only containing the modified source files and thus pull the source from the original tree if they don't exist in my modified tree.

Dir Structure

I have already modified the makefile in ModDir to check if each folder exists locally and execute make in that folder if it does. Otherwise it executes make in the sourceDir. My issue lies in the subdir makefiles.

Each subdir makefile contains a list of all of the source files needed for that module. I need to find a way to build the file locally if it exists, else build the file from SourceDir/subdir.

I.e. in my image, the Dir1 makefile needs to build F1 from ModDir/Dir1/F1, and build the other files from SourceDir/Dir1/F2-F3.

I tried to use VPATH to tell make to locate the source files in both locations (ModDir first of course) which works beautifully. However, since make assumes the object files are in the ModDir, it can't find any of the object files built in SourceDir.

I also tried making a pre-build rule to modify the make file list with bash, but I don't know if that's even possible.

How do I use make to build from one directory if the source file exists (ModDir), otherwise build from another (SourceDir)?

like image 714
SPARCpenguin Avatar asked Nov 12 '22 06:11

SPARCpenguin


1 Answers

The easiest way will be to put your "if ... then ... else" logic in an external bash or batch (whichever OS you use) script and swap makefiles before calling make

like image 176
David Jashi Avatar answered Jan 04 '23 01:01

David Jashi