• 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 = makevars.keys()
9    keys.sort()
10    for key in keys:
11        outfp.write("%s=%s\n" % (key, makevars[key]))
12    outfp.write("\nall: %s\n\n" % target)
13
14    deps = []
15    for i in range(len(files)):
16        file = files[i]
17        if file[-2:] == '.c':
18            base = os.path.basename(file)
19            dest = base[:-2] + '.o'
20            outfp.write("%s: %s\n" % (dest, file))
21            outfp.write("\t$(CC) $(CFLAGS) $(CPPFLAGS) -c %s\n" % file)
22            files[i] = dest
23            deps.append(dest)
24
25    outfp.write("\n%s: %s\n" % (target, ' '.join(deps)))
26    outfp.write("\t$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) %s -o %s $(LDLAST)\n" %
27                (' '.join(files), target))
28
29    outfp.write("\nclean:\n\t-rm -f *.o %s\n" % target)
30