# HG changeset patch # User Paul Boddie # Date 1485527237 -3600 # Node ID b99c11afb6f52a39d531c42bbcc596b69e5bab34 # Parent df30d1a4d19ab3d48fb986c7f0f6e9c5da68b962 Configure the Makefile using generated secondary Makefiles, replacing the debug-specific Makefile and permitting the selection of included source files. diff -r df30d1a4d19a -r b99c11afb6f5 generator.py --- a/generator.py Wed Jan 25 00:03:08 2017 +0100 +++ b/generator.py Fri Jan 27 15:27:17 2017 +0100 @@ -98,9 +98,10 @@ self.check_output() self.write_structures() - self.copy_templates(debug) + self.write_scripts(debug) + self.copy_templates() - def copy_templates(self, debug=False): + def copy_templates(self): "Copy template files to the generated output directory." @@ -108,20 +109,6 @@ for filename in listdir(templates): target = self.output - - # Handle debug resources. - - if filename.endswith("-debug"): - if debug: - target = join(self.output, filename[:-len("-debug")]) - else: - continue - - # Handle non-debug resources. - - if debug and exists(join(templates, "%s-debug" % filename)): - continue - pathname = join(templates, filename) # Copy files into the target directory. @@ -438,6 +425,34 @@ f_signatures.close() f_code.close() + def write_scripts(self, debug): + + "Write scripts used to build the program." + + f_native = open(join(self.output, "native.mk"), "w") + f_options = open(join(self.output, "options.mk"), "w") + try: + if debug: + print >>f_options, "CFLAGS = -g" + + # Identify native modules used by the program. + + native_modules = ["native/common.c"] + + for name in self.importer.modules.keys(): + parts = name.split(".", 1) + + # Identify source files to be built. + + if parts[0] == "native": + native_modules.append("native/%s.c" % parts[1]) + + print >>f_native, "SRC =", " ".join(native_modules) + + finally: + f_native.close() + f_options.close() + def make_literal_constant(self, f_decls, f_defs, n, constant): """ diff -r df30d1a4d19a -r b99c11afb6f5 templates/Makefile --- a/templates/Makefile Wed Jan 25 00:03:08 2017 +0100 +++ b/templates/Makefile Fri Jan 27 15:27:17 2017 +0100 @@ -1,7 +1,10 @@ -SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) +include native.mk +include options.mk + +SRC += exceptions.c main.c ops.c progops.c progtypes.c $(wildcard src/*.c) OBJ = $(SRC:.c=.o) -CFLAGS = -Wall -I. -finput-charset=UTF-8 -LDFLAGS = -lm -lgc +CFLAGS += -Wall -I. -finput-charset=UTF-8 +LDFLAGS += -lm -lgc ifdef ARCH CC := $(ARCH)-$(CC) diff -r df30d1a4d19a -r b99c11afb6f5 templates/Makefile-debug --- a/templates/Makefile-debug Wed Jan 25 00:03:08 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) -OBJ = $(SRC:.c=.o) -CFLAGS = -Wall -I. -finput-charset=UTF-8 -g -LDFLAGS = -lm -lgc - -ifdef ARCH -CC := $(ARCH)-$(CC) -endif - -all: main - -clean: - rm -f main $(OBJ) - -main: $(OBJ) - $(CC) $(LDFLAGS) $(OBJ) -o $@ - -.c.o: - $(CC) -c $(CFLAGS) $< -o $@