• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Write the actual Makefile.
2
3import os
4
5def makemakefile(outfp, makevars, files, target):
6    outfp.write("# Makefile generated by freeze.py script\n\n")
7
8    keys = sorted(makevars.keys())
9    for key in keys:
10        outfp.write("%s=%s\n" % (key, makevars[key]))
11    outfp.write("\nall: %s\n\n" % target)
12
13    deps = []
14    for i in range(len(files)):
15        file = files[i]
16        if file[-2:] == '.c':
17            base = os.path.basename(file)
18            dest = base[:-2] + '.o'
19            outfp.write("%s: %s\n" % (dest, file))
20            outfp.write("\t$(CC) $(PY_CFLAGS) $(PY_CPPFLAGS) -c %s\n" % file)
21            files[i] = dest
22            deps.append(dest)
23
24    outfp.write("\n%s: %s\n" % (target, ' '.join(deps)))
25    outfp.write("\t$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) %s -o %s $(LDLAST)\n" %
26                (' '.join(files), target))
27
28    outfp.write("\nclean:\n\t-rm -f *.o %s\n" % target)
29