Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
SecretSquirrel
Minister of Gerbil Affairs
Topic Author
Posts: 2726
Joined: Tue Jan 01, 2002 7:00 pm
Location: North DFW suburb...
Contact:

Makefile madness...

Sat Oct 19, 2013 11:59 pm

I've been beating my head against a Make problem this evening. First, I am, by no means, a Make expert. However, I feel like there is a way to do this, I just haven't found it. So, here follows my problem.

I have a Makefile that is building items, in this case the final output is RPM files. There can be multiple platforms and for each platform, multiple architectures. The RPM contents and name may vary based on the platform and architecture. If make is invoked as "make ARCH=foo PLATFORM=bar", then no problem. BUT! What happens when it is invoked as "make PLATFORM=bar"? What I want is for it to iterate over all possible architectures and re-call itself with ARCH set.

At the top of the Makefile, I can do something like this:

ifndef ARCH
$(MAKECMDGOALS): $(ARCH_LIST)
$(ARCH_LIST):
     $(MAKE) ARCH=$@ $(MAKECMDGOALS)
else
export ARCH
ifndef PLATFORM
$(MAKECMDGOALS): $(PLATFORM_LIST)
$(PLATFORM_LIST):
     $(MAKE) PLATFORM=$@ $(MAKECMDGOALS)
else
export PLATFORM
endif
endif


That will make it recurse over the appropriate lists, however it doesn't short circuit the original target. So the target gets called appropriately for every combination of ARCH and PLATFORM, but the falls through the PLATFORM level recursion and gets called once for ever value of ARCH with PLATFORM undefined. In order to keep that from happening, I have to wrap all the targets in a big "ifneq ($(and $(ARCH), $(PLATFORM)), )" block which is a bit less that desirable though it does appear to be the only way to do it in a single Makefile.

Help?

--SS
 
morphine
TR Staff
Posts: 11600
Joined: Fri Dec 27, 2002 8:51 pm
Location: Portugal (that's next to Spain)

Re: Makefile madness...

Sun Oct 20, 2013 8:01 am

I don't know enough about Makefiles to know the exact answer, but perhaps a dirty hack would be doing what you described via a shell script that then calls "make ARCH=x PLATFORM=y".
There is a fixed amount of intelligence on the planet, and the population keeps growing :(
 
SecretSquirrel
Minister of Gerbil Affairs
Topic Author
Posts: 2726
Joined: Tue Jan 01, 2002 7:00 pm
Location: North DFW suburb...
Contact:

Re: Makefile madness...

Sun Oct 20, 2013 10:58 am

morphine wrote:
I don't know enough about Makefiles to know the exact answer, but perhaps a dirty hack would be doing what you described via a shell script that then calls "make ARCH=x PLATFORM=y".


That is actually how the top level gets called most of the time. The was mainly to cover the situation where something lower down in the tree that is shared across several platforms is updated and needs to be re-packaged for all platforms. For the time being I'm just wrapping the targets in the ifneq/endif block and moving on. Too much work, not enough time... :cry:
 
Flatland_Spider
Graphmaster Gerbil
Posts: 1324
Joined: Mon Sep 13, 2004 8:33 pm

Re: Makefile madness...

Mon Oct 21, 2013 3:54 pm

I found this, and thought it might help.

Multi-Architecture Builds Using GNU make
http://mad-scientist.net/make/multi-arch.html

I've never played with make, but I probably should.
 
MarkG509
Gerbil Elite
Posts: 744
Joined: Thu Feb 21, 2013 6:51 pm

Re: Makefile madness...

Mon Oct 21, 2013 6:10 pm

Multi-arch, multi-platform without a configure? If just "make", then I suggest you want to (cross-)compile all 'flavors', else you'll suffer bit-rot within a month.
 
notfred
Maximum Gerbil
Posts: 4610
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Makefile madness...

Mon Oct 21, 2013 7:57 pm

I think you want to build up ARCHLIST and PLATFORMLIST variables and then iterate over those in one shot. Default to the full list for each and allow the list to be overridden from the command line.
 
SecretSquirrel
Minister of Gerbil Affairs
Topic Author
Posts: 2726
Joined: Tue Jan 01, 2002 7:00 pm
Location: North DFW suburb...
Contact:

Re: Makefile madness...

Mon Oct 21, 2013 8:20 pm

notfred wrote:
I think you want to build up ARCHLIST and PLATFORMLIST variables and then iterate over those in one shot. Default to the full list for each and allow the list to be overridden from the command line.


That is effectively what I have done. At the top level, there is a defined set of architectures and platforms. The build iterates over each of the sub-builds for this list. The problem is that it makes perfect sense to build some of the sub-builds stand alone, as well as for individual architectures and platforms. This means that each sub build has to be able to iterate over the lists as well. That's fine. Easy enough to move the iteration from the top level to each sub build. The problem comes down to what happens when you execute any given Makefile. If PLATFORM and ARCH are not defined, or are defined as a list, then it needs to iterate. If they are defined or a single value then build for that value. Make doesn't have loops, so the the iteration has to be a recursive call of the same Makefile with ARCH and PLATFORM set to each value. Easy enough to do. Stopping the initial invocation from trying to build the target to, without PLATFORM and ARCH seems to be impossible without a big conditional in the Makefile. That's what I resorted to and it works fine, it's just kind of ugly.

--SS
 
Waco
Maximum Gerbil
Posts: 4850
Joined: Tue Jan 20, 2009 4:14 pm
Location: Los Alamos, NM

Re: Makefile madness...

Tue Oct 22, 2013 5:51 pm

This is why I love CMake. :P
Victory requires no explanation. Defeat allows none.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On