[lug] OT: More Makefile

D. Stimits stimits at idcomm.com
Mon Apr 29 13:27:10 MDT 2002


Given the constraint that I can use make facilities, and gnu g++
facilities, plus bash scripting, is there a good way to conditionally
include another Makefile in a project? Given some secondary file like
"Makefile.second", I can add this in "Makefile" (the main Makefile):
include Makefile.second

In a bash script, I could do this to read another bash script:
source OtherScript.sh

Inside of a Makefile, I can add this as part of a target:

mytarget:
	@echo ""
	@if [ -f Makefile.second ]; then \
		echo "Have Makefile.second."; \
		...do stuff depending on Makefile.second...
	else \
		echo "Missing Makefile.second."; \
	fi

As far as the "include Makefile.second" goes, I can do it before
mytarget, but if I place it inside of the bash scripting portion, it
assumes the command is bash, so "include" does not work. I could use the
bash "source" command, but then I can't use Makefile syntax and
functionality. What is a good modular way to conditionally include a
second Makefile inside of a main Makefile if and only if the second
Makefile is present?

Please note, I cannot use autoconf or special tools for this, I don't
own the code.

D. Stimits, stimits at idcomm.com



More information about the LUG mailing list