diff options
author | yenatch <yenatch@gmail.com> | 2013-12-06 22:40:46 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2013-12-07 20:01:50 -0500 |
commit | 120ba9664992cada4781e4d524304e4499e9083f (patch) | |
tree | 93dbfcf49a5835d5708c6b6a58c608e60297d773 | |
parent | bacc4594c0772dab004e4f97e21529a523918a89 (diff) |
handle preprocessing in one python procress; export asm labels
instead of running a process for each file, one process handles all files
rgbasm requires label EXPORT definitions for cross-object compiling. this is handled by globals.asm
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 31 | ||||
-rw-r--r-- | preprocessor.py | 30 | ||||
-rw-r--r-- | prequeue.py | 29 |
4 files changed, 74 insertions, 19 deletions
@@ -1,3 +1,6 @@ +# global label defs are generated +globals.asm + # precompiled python *.pyc @@ -4,6 +4,8 @@ PYTHON := python .SECONDEXPANSION: +TEXTQUEUE := + RED_OBJS := pokered.o BLUE_OBJS := pokeblue.o @@ -13,9 +15,11 @@ ROMS := pokered.gbc pokeblue.gbc # generate dependencies for each object $(shell $(foreach obj, $(OBJS), \ - $(eval $(obj:.o=)_DEPENDENCIES := $(shell $(PYTHON) extras/pokemontools/scan_includes.py $(obj:.o=.asm))) \ + $(eval $(obj:.o=)_DEPENDENCIES := $(shell $(PYTHON) extras/pokemontools/scan_includes.py $(obj:.o=.asm) | sed s/globals.asm//g)) \ +)) +$(shell $(foreach obj, $(OBJS), \ + $(eval ALL_DEPENDENCIES := $(ALL_DEPENDENCIES) $($(obj:.o=)_DEPENDENCIES)) \ )) - all: $(ROMS) red: pokered.gbc @@ -27,6 +31,7 @@ redrle: extras/redtools/redrle.c clean: rm -f $(ROMS) rm -f $(OBJS) + rm -f globals.asm find -iname '*.tx' -delete rm -f redrle @@ -35,20 +40,26 @@ baserom.gbc: ; @echo "Wait! Need baserom.gbc first. Check README and INSTALL for details." && false %.asm: ; - .asm.tx: - $(PYTHON) preprocessor.py < $< > $@ + $(eval TEXTQUEUE := $(TEXTQUEUE) $<) + @rm -f $@ + +globals.asm: $(ALL_DEPENDENCIES:.asm=.tx) $(OBJS:.o=.tx) + @touch $@ + @$(PYTHON) prequeue.py $(TEXTQUEUE) +globals.tx: globals.asm + @cp $< $@ -$(OBJS): $$*.tx $$(patsubst %.asm, %.tx, $$($$*_DEPENDENCIES)) - rgbasm -o $@ $(@:.o=.tx) +$(OBJS): $$*.tx $$($$*_DEPENDENCIES$:.asm=.tx) + rgbasm -o $@ $*.tx -pokered.gbc: $(RED_OBJS) - rgblink -n $*.sym -m $*.map -o $@ $^ +pokered.gbc: globals.tx $(RED_OBJS) + rgblink -n $*.sym -m $*.map -o $@ $(RED_OBJS) rgbfix -jsv -k 01 -l 0x33 -m 0x13 -p 0 -r 03 -t "POKEMON RED" $@ cmp baserom.gbc $@ -pokeblue.gbc: $(BLUE_OBJS) - rgblink -n $*.sym -m $*.map -o $@ $^ +pokeblue.gbc: globals.tx $(BLUE_OBJS) + rgblink -n $*.sym -m $*.map -o $@ $(BLUE_OBJS) rgbfix -jsv -k 01 -l 0x33 -m 0x13 -p 0 -r 03 -t "POKEMON BLUE" $@ cmp blue.gbc $@ diff --git a/preprocessor.py b/preprocessor.py index 294e9ccb..317a2fe6 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -1,10 +1,17 @@ # -*- coding: utf-8 -*- import extras.pokemontools.preprocessor as preprocessor + import extras.pokemontools.configuration as configuration +config = configuration.Config() import sys +from extras.pokemontools.crystal import ( + callchannel, + loopchannel, +) + chars = { "ガ": 0x05, "ギ": 0x06, @@ -260,14 +267,19 @@ chars = { "9": 0xFF, } -preprocessor.chars = chars +def load_pokered_macros(): + macros = [callchannel, loopchannel] + return macros -from extras.pokemontools.crystal import ( - callchannel, - loopchannel, -) +def setup_processor(): + preprocessor.chars = chars + macros = load_pokered_macros() + processor = preprocessor.Preprocessor(config, macros) + return processor -config = configuration.Config() -macros = [callchannel, loopchannel] -processor = preprocessor.Preprocessor(config, macros) -processor.preprocess() +def main(): + processor = setup_processor() + processor.preprocess() + +if __name__ == '__main__': + main() diff --git a/prequeue.py b/prequeue.py new file mode 100644 index 00000000..6ad16d2c --- /dev/null +++ b/prequeue.py @@ -0,0 +1,29 @@ +# coding: utf-8 +""" +Starting a new python process to preprocess each source file creates too much +overhead. Instead, a list of files to preprocess is fed into a script run from +a single process. +""" + +import os +import sys + +import preprocessor + +def main(): + processor = preprocessor.setup_processor() + + for source in sys.argv[1:]: + dest = os.path.splitext(source)[0] + '.tx' + + stdout = sys.stdout + + sys.stdin = open(source, 'r') + sys.stdout = open(dest, 'w') + + processor.preprocess() + + sys.stdout = stdout + +if __name__ == '__main__': + main() |