1.1 --- a/generator.py Wed Jan 25 00:03:08 2017 +0100
1.2 +++ b/generator.py Fri Jan 27 15:27:17 2017 +0100
1.3 @@ -98,9 +98,10 @@
1.4
1.5 self.check_output()
1.6 self.write_structures()
1.7 - self.copy_templates(debug)
1.8 + self.write_scripts(debug)
1.9 + self.copy_templates()
1.10
1.11 - def copy_templates(self, debug=False):
1.12 + def copy_templates(self):
1.13
1.14 "Copy template files to the generated output directory."
1.15
1.16 @@ -108,20 +109,6 @@
1.17
1.18 for filename in listdir(templates):
1.19 target = self.output
1.20 -
1.21 - # Handle debug resources.
1.22 -
1.23 - if filename.endswith("-debug"):
1.24 - if debug:
1.25 - target = join(self.output, filename[:-len("-debug")])
1.26 - else:
1.27 - continue
1.28 -
1.29 - # Handle non-debug resources.
1.30 -
1.31 - if debug and exists(join(templates, "%s-debug" % filename)):
1.32 - continue
1.33 -
1.34 pathname = join(templates, filename)
1.35
1.36 # Copy files into the target directory.
1.37 @@ -438,6 +425,34 @@
1.38 f_signatures.close()
1.39 f_code.close()
1.40
1.41 + def write_scripts(self, debug):
1.42 +
1.43 + "Write scripts used to build the program."
1.44 +
1.45 + f_native = open(join(self.output, "native.mk"), "w")
1.46 + f_options = open(join(self.output, "options.mk"), "w")
1.47 + try:
1.48 + if debug:
1.49 + print >>f_options, "CFLAGS = -g"
1.50 +
1.51 + # Identify native modules used by the program.
1.52 +
1.53 + native_modules = ["native/common.c"]
1.54 +
1.55 + for name in self.importer.modules.keys():
1.56 + parts = name.split(".", 1)
1.57 +
1.58 + # Identify source files to be built.
1.59 +
1.60 + if parts[0] == "native":
1.61 + native_modules.append("native/%s.c" % parts[1])
1.62 +
1.63 + print >>f_native, "SRC =", " ".join(native_modules)
1.64 +
1.65 + finally:
1.66 + f_native.close()
1.67 + f_options.close()
1.68 +
1.69 def make_literal_constant(self, f_decls, f_defs, n, constant):
1.70
1.71 """
2.1 --- a/templates/Makefile Wed Jan 25 00:03:08 2017 +0100
2.2 +++ b/templates/Makefile Fri Jan 27 15:27:17 2017 +0100
2.3 @@ -1,7 +1,10 @@
2.4 -SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c)
2.5 +include native.mk
2.6 +include options.mk
2.7 +
2.8 +SRC += exceptions.c main.c ops.c progops.c progtypes.c $(wildcard src/*.c)
2.9 OBJ = $(SRC:.c=.o)
2.10 -CFLAGS = -Wall -I. -finput-charset=UTF-8
2.11 -LDFLAGS = -lm -lgc
2.12 +CFLAGS += -Wall -I. -finput-charset=UTF-8
2.13 +LDFLAGS += -lm -lgc
2.14
2.15 ifdef ARCH
2.16 CC := $(ARCH)-$(CC)
3.1 --- a/templates/Makefile-debug Wed Jan 25 00:03:08 2017 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,19 +0,0 @@
3.4 -SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c)
3.5 -OBJ = $(SRC:.c=.o)
3.6 -CFLAGS = -Wall -I. -finput-charset=UTF-8 -g
3.7 -LDFLAGS = -lm -lgc
3.8 -
3.9 -ifdef ARCH
3.10 -CC := $(ARCH)-$(CC)
3.11 -endif
3.12 -
3.13 -all: main
3.14 -
3.15 -clean:
3.16 - rm -f main $(OBJ)
3.17 -
3.18 -main: $(OBJ)
3.19 - $(CC) $(LDFLAGS) $(OBJ) -o $@
3.20 -
3.21 -.c.o:
3.22 - $(CC) -c $(CFLAGS) $< -o $@