abandoning GNU make pattern rules in favor of generated makefile targets

cat-town
Dan Buch 15 years ago
parent 70b9977d4c
commit 14db585c3b

@ -2,8 +2,6 @@
# the Adobe Flex "Geting Started" tutorial at: # the Adobe Flex "Geting Started" tutorial at:
# http://learn.adobe.com/wiki/display/Flex/Getting+Started # http://learn.adobe.com/wiki/display/Flex/Getting+Started
include rules.mk
# sets mxmlc and compc to their respective basenames # sets mxmlc and compc to their respective basenames
# if not overridden in command line like so: # if not overridden in command line like so:
# make MXMLC=/path/to/my/mxmlc # make MXMLC=/path/to/my/mxmlc
@ -11,20 +9,37 @@ MXMLC ?= mxmlc
COMPC ?= compc COMPC ?= compc
# define all target swf paths (which don't yet exist if # define all dependency mxml paths and their swf path targets
# they've never been built) # (which don't yet exist if they've never been built)
SWFS = $(patsubst %.mxml,%.swf,$(wildcard [0-9]*-*/*.mxml)) MXML = $(wildcard [0-9]*-*/*.mxml) $(wildcard custom-*/*.mxml)
SWFS += $(patsubst %.mxml,%.swf,$(wildcard custom-*/*.mxml)) SWFS = $(patsubst %.mxml,%.swf,$(MXML))
# glob up all component files as well, since changes to them # glob up all component files as well, since changes to them
# should also prompt rebuild # should also prompt rebuild
COMPONENTS = $(patsubst %.mxml,%.swf,$(wildcard [0-9]*-*/*.as)) COMPONENTS = $(wildcard [0-9]*-*/*.as) $(wildcard custom-*/*.as)
COMPONENTS += $(patsubst %.mxml,%.swf,$(wildcard custom-*/*.as)) export COMPONENTS
include rules.mk
all: $(SWFS)
include targets.mk
components:
@echo $(COMPONENTS)
mxml:
@echo $(MXML)
# build all expected swf and swc files swfs:
all: $(SWFS) $(COMPONENTS) @echo $(SWFS)
# remove all swf files in the tree # remove all swf files in the tree

@ -0,0 +1,70 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import re
import sys
import glob
from os.path import join as pathjoin
HERE = os.path.dirname(os.path.abspath(__file__))
AUTOGEN_WARNING = ('# ******** AUTOGENERATED by {0} ' +
('*' * 20)).format(os.path.basename(sys.argv[0]))
PATTERN_RULE_MXMLC = \
'$(MXMLC) {firstdep} -warnings -l+={parent_dir} -output {target}'
def main(sysargs=sys.argv[:]):
targets_mk = pathjoin(HERE, 'targets.mk')
os.chmod(targets_mk, 0600)
targetmaker = TargetMaker(outstream=open(targets_mk, 'wb'))
targetmaker.make()
os.chmod(targets_mk, 0444)
return 0
class TargetMaker(object):
_to_glob = (
pathjoin(HERE, '[0-9]*-*', '*.mxml'),
pathjoin(HERE, 'custom-*', '*.mxml'),
)
def __init__(self, outstream=sys.stdout):
self.outstream = outstream
self.targets = {}
def make(self):
for pattern in self._to_glob:
for mxml in glob.glob(pattern):
self._add_target_from_mxml(mxml)
self._write_out_targets()
def _add_target_from_mxml(self, mxml):
rel_mxml = os.path.relpath(mxml, HERE)
as_swf = re.sub('(.*)\.mxml$', '\\1.swf', rel_mxml)
self.targets[as_swf] = set([rel_mxml])
as3_pattern = re.sub('(.*)/(.*)\.mxml$', '\\1/*.as', rel_mxml)
for local_as3 in glob.glob(as3_pattern):
rel_as3 = os.path.relpath(local_as3, HERE)
self.targets[as_swf].add(rel_as3)
def _write_out_targets(self):
print(AUTOGEN_WARNING, file=self.outstream)
for target in sorted(self.targets.iterkeys()):
deps = list(reversed(sorted(list(self.targets[target]),
key=lambda d: os.path.splitext(d)[-1])))
print('{target}: {deps}'.format(target=target,
deps=' '.join(deps)), file=self.outstream)
print('\t' +
PATTERN_RULE_MXMLC.format(firstdep=deps[0],
parent_dir=os.path.dirname(deps[0]),
target=target) +
'\n\n', file=self.outstream)
if __name__ == '__main__':
sys.exit(main())
# vim:filetype=python

@ -0,0 +1,141 @@
# ******** AUTOGENERATED by mktargets.py ********************
01-flickr/FlickrRIA.swf: 01-flickr/FlickrRIA.mxml
$(MXMLC) 01-flickr/FlickrRIA.mxml -warnings -l+=01-flickr -output 01-flickr/FlickrRIA.swf
01-flickr/FlickrThumbnail.swf: 01-flickr/FlickrThumbnail.mxml
$(MXMLC) 01-flickr/FlickrThumbnail.mxml -warnings -l+=01-flickr -output 01-flickr/FlickrThumbnail.swf
02-shipping/PlainText.swf: 02-shipping/PlainText.mxml
$(MXMLC) 02-shipping/PlainText.mxml -warnings -l+=02-shipping -output 02-shipping/PlainText.swf
03a1-binding-and-modeling/YahooWeather.swf: 03a1-binding-and-modeling/YahooWeather.mxml
$(MXMLC) 03a1-binding-and-modeling/YahooWeather.mxml -warnings -l+=03a1-binding-and-modeling -output 03a1-binding-and-modeling/YahooWeather.swf
03a2-crud-dynamic/CRUDDynamic.swf: 03a2-crud-dynamic/CRUDDynamic.mxml 03a2-crud-dynamic/dyn-employees.as
$(MXMLC) 03a2-crud-dynamic/CRUDDynamic.mxml -warnings -l+=03a2-crud-dynamic -output 03a2-crud-dynamic/CRUDDynamic.swf
03a3-crud-static/CRUDStatic.swf: 03a3-crud-static/CRUDStatic.mxml 03a3-crud-static/static-employees.as
$(MXMLC) 03a3-crud-static/CRUDStatic.mxml -warnings -l+=03a3-crud-static -output 03a3-crud-static/CRUDStatic.swf
03a4-external-interface/Main.swf: 03a4-external-interface/Main.mxml
$(MXMLC) 03a4-external-interface/Main.mxml -warnings -l+=03a4-external-interface -output 03a4-external-interface/Main.swf
03a5-local-connections/BasicTaskReceiver.swf: 03a5-local-connections/BasicTaskReceiver.mxml
$(MXMLC) 03a5-local-connections/BasicTaskReceiver.mxml -warnings -l+=03a5-local-connections -output 03a5-local-connections/BasicTaskReceiver.swf
03a5-local-connections/TaskSender.swf: 03a5-local-connections/TaskSender.mxml
$(MXMLC) 03a5-local-connections/TaskSender.mxml -warnings -l+=03a5-local-connections -output 03a5-local-connections/TaskSender.swf
03a6-shared-objects/SharedObjectExample.swf: 03a6-shared-objects/SharedObjectExample.mxml
$(MXMLC) 03a6-shared-objects/SharedObjectExample.mxml -warnings -l+=03a6-shared-objects -output 03a6-shared-objects/SharedObjectExample.swf
03a7-validation-and-formatting/ValidatorsandFormattersExampleWithAreaCodeLookup.swf: 03a7-validation-and-formatting/ValidatorsandFormattersExampleWithAreaCodeLookup.mxml
$(MXMLC) 03a7-validation-and-formatting/ValidatorsandFormattersExampleWithAreaCodeLookup.mxml -warnings -l+=03a7-validation-and-formatting -output 03a7-validation-and-formatting/ValidatorsandFormattersExampleWithAreaCodeLookup.swf
03b-handling-events/TwitterTimeline.swf: 03b-handling-events/TwitterTimeline.mxml
$(MXMLC) 03b-handling-events/TwitterTimeline.mxml -warnings -l+=03b-handling-events -output 03b-handling-events/TwitterTimeline.swf
03b1-event-listeners/VBoxDemo.swf: 03b1-event-listeners/VBoxDemo.mxml
$(MXMLC) 03b1-event-listeners/VBoxDemo.mxml -warnings -l+=03b1-event-listeners -output 03b1-event-listeners/VBoxDemo.swf
03b2-event-propagation/DemoApplication.swf: 03b2-event-propagation/DemoApplication.mxml
$(MXMLC) 03b2-event-propagation/DemoApplication.mxml -warnings -l+=03b2-event-propagation -output 03b2-event-propagation/DemoApplication.swf
03b3-simple-ui-event/Example1.swf: 03b3-simple-ui-event/Example1.mxml
$(MXMLC) 03b3-simple-ui-event/Example1.mxml -warnings -l+=03b3-simple-ui-event -output 03b3-simple-ui-event/Example1.swf
03b3-simple-ui-event/Example2.swf: 03b3-simple-ui-event/Example2.mxml
$(MXMLC) 03b3-simple-ui-event/Example2.mxml -warnings -l+=03b3-simple-ui-event -output 03b3-simple-ui-event/Example2.swf
03c1-application-container/Demo.swf: 03c1-application-container/Demo.mxml
$(MXMLC) 03c1-application-container/Demo.mxml -warnings -l+=03c1-application-container -output 03c1-application-container/Demo.swf
03c2-box-model/HBoxExample.swf: 03c2-box-model/HBoxExample.mxml
$(MXMLC) 03c2-box-model/HBoxExample.mxml -warnings -l+=03c2-box-model -output 03c2-box-model/HBoxExample.swf
03c2-box-model/VBoxExample.swf: 03c2-box-model/VBoxExample.mxml
$(MXMLC) 03c2-box-model/VBoxExample.mxml -warnings -l+=03c2-box-model -output 03c2-box-model/VBoxExample.swf
03c2-box-model/VBoxHBoxCombo.swf: 03c2-box-model/VBoxHBoxCombo.mxml
$(MXMLC) 03c2-box-model/VBoxHBoxCombo.mxml -warnings -l+=03c2-box-model -output 03c2-box-model/VBoxHBoxCombo.swf
03c3-canvas-absolute/Example.swf: 03c3-canvas-absolute/Example.mxml
$(MXMLC) 03c3-canvas-absolute/Example.mxml -warnings -l+=03c3-canvas-absolute -output 03c3-canvas-absolute/Example.swf
03c4-canvas-relative/Photo.swf: 03c4-canvas-relative/Photo.mxml
$(MXMLC) 03c4-canvas-relative/Photo.mxml -warnings -l+=03c4-canvas-relative -output 03c4-canvas-relative/Photo.swf
03c5-combined-layout/Combined.swf: 03c5-combined-layout/Combined.mxml
$(MXMLC) 03c5-combined-layout/Combined.mxml -warnings -l+=03c5-combined-layout -output 03c5-combined-layout/Combined.swf
03c6-form/CommentForm.swf: 03c6-form/CommentForm.mxml
$(MXMLC) 03c6-form/CommentForm.mxml -warnings -l+=03c6-form -output 03c6-form/CommentForm.swf
03c7-mxml-vs-as3/WithAs3.swf: 03c7-mxml-vs-as3/WithAs3.mxml
$(MXMLC) 03c7-mxml-vs-as3/WithAs3.mxml -warnings -l+=03c7-mxml-vs-as3 -output 03c7-mxml-vs-as3/WithAs3.swf
03c7-mxml-vs-as3/WithMxml.swf: 03c7-mxml-vs-as3/WithMxml.mxml
$(MXMLC) 03c7-mxml-vs-as3/WithMxml.mxml -warnings -l+=03c7-mxml-vs-as3 -output 03c7-mxml-vs-as3/WithMxml.swf
03c8-panel/Photo.swf: 03c8-panel/Photo.mxml
$(MXMLC) 03c8-panel/Photo.mxml -warnings -l+=03c8-panel -output 03c8-panel/Photo.swf
03d1-datagrid/DataGridExample.swf: 03d1-datagrid/DataGridExample.mxml 03d1-datagrid/RequestParams.as 03d1-datagrid/DataGridApp.as
$(MXMLC) 03d1-datagrid/DataGridExample.mxml -warnings -l+=03d1-datagrid -output 03d1-datagrid/DataGridExample.swf
03d2-item-renderers/HBoxWeatherDisplay.swf: 03d2-item-renderers/HBoxWeatherDisplay.mxml 03d2-item-renderers/WeatherApp.as
$(MXMLC) 03d2-item-renderers/HBoxWeatherDisplay.mxml -warnings -l+=03d2-item-renderers -output 03d2-item-renderers/HBoxWeatherDisplay.swf
03d2-item-renderers/WeatherDisplay.swf: 03d2-item-renderers/WeatherDisplay.mxml 03d2-item-renderers/WeatherApp.as
$(MXMLC) 03d2-item-renderers/WeatherDisplay.mxml -warnings -l+=03d2-item-renderers -output 03d2-item-renderers/WeatherDisplay.swf
03d3-lists/HorizontalListControl.swf: 03d3-lists/HorizontalListControl.mxml
$(MXMLC) 03d3-lists/HorizontalListControl.mxml -warnings -l+=03d3-lists -output 03d3-lists/HorizontalListControl.swf
03d3-lists/ListControl.swf: 03d3-lists/ListControl.mxml
$(MXMLC) 03d3-lists/ListControl.mxml -warnings -l+=03d3-lists -output 03d3-lists/ListControl.swf
03d4-tilelist/TileListExample.swf: 03d4-tilelist/TileListExample.mxml
$(MXMLC) 03d4-tilelist/TileListExample.mxml -warnings -l+=03d4-tilelist -output 03d4-tilelist/TileListExample.swf
custom-03d1-datagrid/Snarf.swf: custom-03d1-datagrid/Snarf.mxml custom-03d1-datagrid/CustomApp.as
$(MXMLC) custom-03d1-datagrid/Snarf.mxml -warnings -l+=custom-03d1-datagrid -output custom-03d1-datagrid/Snarf.swf
custom-03d3-lists/ListControl.swf: custom-03d3-lists/ListControl.mxml custom-03d3-lists/ListApp.as
$(MXMLC) custom-03d3-lists/ListControl.mxml -warnings -l+=custom-03d3-lists -output custom-03d3-lists/ListControl.swf
Loading…
Cancel
Save