Tuesday, June 3, 2008

Stopping make delete intermediate files

I wanted a makefile to compile mxml (Adobe flex, aka Flash 9) files into swf files and play them automatically. In other words I wanted to just type "make test2" and it would compile test2.mxml into test2.swf, then open test2.swf in the flashplayer.
The hardest part was that, with the automatic rules, make insisted on deleting the "intermediate" file. But in this case the intermediate file was the swf itself. There is a ".PRECIOUS" rule that appears designed for this purpose that made no difference. After much trial, error and banging my head against the keyboard until it bled, it seems setting ".SECONDARY" to blank was the solution. Here is the full makefile (saved in a file called Makefile, in the same directory as my mxml files):



% : %.swf
flashplayer $<

%.swf: %.mxml
$(MXMLC) $<

This makefile is generically useful for when you want to compile and run something; especially when experimenting with lots of small individual files.


Unknown said...

THANK. YOU. thankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyou

I've been banging my forehead on my keyboard for a day trying to figure out why make was deleting files. It seems stupid that it defaults to deleting files that the user might want.

Anonymous said...

the .PRECIOUS rule is not for keeping files that would be deleted because they are intermediate files, but for keeping fiels that would be deleted because make is killed.

ane example of precious files could be large files downloaded using wget -c that you don't want to keep -- if you kill make, wget will continue, but if the process is complete, the downloaded file will be gone again.

Unknown said...

Hi Matt, great to hear it helped you (I've only just noticed your comment - again I cry out, "How do tell blogger to email me all comments on my blog??")

Thanks Anon for the advice; I'll bear that in mind in case I ever find I have that problem.

Anonymous said...

A big thank you for this one !

Base16 said...

Lifesaver !!!

Anonymous said...

Thanks. :)

Anonymous said...

You just healed a very painful issue.
Thank you very much.

Anonymous said...

same here : thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou !!! from Okinawa, Japan

Anonymous said...

What they said ^
Thank you many times over!

Anonymous said...

THANK YOU. This is very counterintuitive and I'm glad you took the time to post it and save me and others a good deal of trouble.

Doublehp said...

I think that using those special targets without depends is accepted, but is likely to have many side effects. See, this guy is clearly stating that any build failure MUST be followed by a make clean, because broken temp files are kept:


The issue I had was that I could not use a generic %.foo to cover all my targets ... This did not work:
.PRECIOUS: %.foo

I had to list targets explicitely:

.PRECIOUS: A/%.foo B/%.foo

Also, before using .PRECIOUS:, consider .SECONDARY and .INTERMEDIATE