~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/build/gen-build.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# USAGE: gen-build.py TYPE
 
4
#
 
5
# where TYPE is one of: make, dsp, vcproj
 
6
#
 
7
# It reads build.conf from the current directory, and produces its output
 
8
# into the current directory.
 
9
#
 
10
 
 
11
 
 
12
import os
 
13
import ConfigParser
 
14
import getopt
 
15
import string
 
16
import glob
 
17
import re
 
18
 
 
19
#import ezt
 
20
 
 
21
#
 
22
# legal platforms: aix, beos, netware, os2, os390, unix, win32
 
23
# 'make' users: aix, beos, os2, os390, unix
 
24
#
 
25
PLATFORMS = [ 'aix', 'beos', 'netware', 'os2', 'os390', 'unix', 'win32' ]
 
26
MAKE_PLATFORMS = [
 
27
  ('unix', None),
 
28
  ('aix', 'unix'),
 
29
  ('beos', 'unix'),
 
30
  ('os2', 'unix'),
 
31
  ('os390', 'unix'),
 
32
  ]
 
33
# note: MAKE_PLATFORMS is an ordered set. we want to generate unix symbols
 
34
#       first, so that the later platforms can reference them.
 
35
 
 
36
 
 
37
def main():
 
38
  parser = ConfigParser.ConfigParser()
 
39
  parser.read('build.conf')
 
40
 
 
41
  headers = get_files(parser.get('options', 'headers'))
 
42
 
 
43
  # compute the relevant headers, along with the implied includes
 
44
  legal_deps = { }
 
45
  for fname in headers:
 
46
    legal_deps[os.path.basename(fname)] = fname
 
47
 
 
48
  h_deps = { }
 
49
  for fname in headers:
 
50
    h_deps[os.path.basename(fname)] = extract_deps(fname, legal_deps)
 
51
  resolve_deps(h_deps)
 
52
 
 
53
  f = open('build-outputs.mk', 'w')
 
54
  f.write('# DO NOT EDIT. AUTOMATICALLY GENERATED.\n\n')
 
55
 
 
56
  # write out the platform-independent files
 
57
  files = get_files(parser.get('options', 'paths'))
 
58
  objects, dirs = write_objects(f, legal_deps, h_deps, files)
 
59
  f.write('\nOBJECTS_all = %s\n\n' % string.join(objects))
 
60
 
 
61
  # for each platform and each subdirectory holding platform-specific files,
 
62
  # write out their compilation rules, and an OBJECT_<subdir>_<plat> symbol.
 
63
  for platform, parent in MAKE_PLATFORMS:
 
64
 
 
65
    # record the object symbols to build for each platform
 
66
    group = [ '$(OBJECTS_all)' ]
 
67
 
 
68
    for subdir in string.split(parser.get('options', 'platform_dirs')):
 
69
      path = '%s/%s' % (subdir, platform)
 
70
      if not os.path.exists(path):
 
71
        # this subdir doesn't have a subdir for this platform, so we'll
 
72
        # use the parent-platform's set of symbols
 
73
        if parent:
 
74
          group.append('$(OBJECTS_%s_%s)' % (subdir, parent))
 
75
        continue
 
76
 
 
77
      # remember that this directory has files/objects
 
78
      dirs[path] = None
 
79
 
 
80
      # write out the compilation lines for this subdir
 
81
      files = get_files(path + '/*.c')
 
82
      objects, _unused = write_objects(f, legal_deps, h_deps, files)
 
83
 
 
84
      symname = 'OBJECTS_%s_%s' % (subdir, platform)
 
85
 
 
86
      # and write the symbol for the whole group
 
87
      f.write('\n%s = %s\n\n' % (symname, string.join(objects)))
 
88
 
 
89
      # and include that symbol in the group
 
90
      group.append('$(%s)' % symname)
 
91
 
 
92
    # write out a symbol which contains the necessary files
 
93
    f.write('OBJECTS_%s = %s\n\n' % (platform, string.join(group)))
 
94
 
 
95
  f.write('HEADERS = $(top_srcdir)/%s\n\n' % string.join(headers, ' $(top_srcdir)/'))
 
96
  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % string.join(dirs.keys()))
 
97
 
 
98
  # Build a list of all necessary directories in build tree
 
99
  alldirs = { }
 
100
  for dir in dirs.keys():
 
101
    d = dir
 
102
    while d:
 
103
      alldirs[d] = None
 
104
      d = os.path.dirname(d)
 
105
 
 
106
  # Sort so 'foo' is before 'foo/bar'
 
107
  keys = alldirs.keys()
 
108
  keys.sort()
 
109
  f.write('BUILD_DIRS = %s\n\n' % string.join(keys))
 
110
 
 
111
  f.write('.make.dirs: $(srcdir)/build-outputs.mk\n' \
 
112
          '\t@for d in $(BUILD_DIRS); do test -d $$d || mkdir $$d; done\n' \
 
113
          '\t@echo timestamp > $@\n')
 
114
 
 
115
 
 
116
def write_objects(f, legal_deps, h_deps, files):
 
117
  dirs = { }
 
118
  objects = [ ]
 
119
 
 
120
  for file in files:
 
121
    assert file[-2:] == '.c'
 
122
    obj = file[:-2] + '.lo'
 
123
    objects.append(obj)
 
124
 
 
125
    dirs[os.path.dirname(file)] = None
 
126
 
 
127
    # what headers does this file include, along with the implied headers
 
128
    deps = extract_deps(file, legal_deps)
 
129
    for hdr in deps.keys():
 
130
      deps.update(h_deps.get(hdr, {}))
 
131
 
 
132
    f.write('%s: %s .make.dirs %s\n' % (obj, file, string.join(deps.values())))
 
133
 
 
134
  return objects, dirs
 
135
 
 
136
 
 
137
def extract_deps(fname, legal_deps):
 
138
  "Extract the headers this file includes."
 
139
  deps = { }
 
140
  for line in open(fname).readlines():
 
141
    if line[:8] != '#include':
 
142
      continue
 
143
    inc = _re_include.match(line).group(1)
 
144
    if inc in legal_deps.keys():
 
145
      deps[inc] = legal_deps[inc]
 
146
  return deps
 
147
_re_include = re.compile('#include *["<](.*)[">]')
 
148
 
 
149
 
 
150
def resolve_deps(header_deps):
 
151
  "Alter the provided dictionary to flatten includes-of-includes."
 
152
  altered = 1
 
153
  while altered:
 
154
    altered = 0
 
155
    for hdr, deps in header_deps.items():
 
156
      # print hdr, deps
 
157
      start = len(deps)
 
158
      for dep in deps.keys():
 
159
        deps.update(header_deps.get(dep, {}))
 
160
      if len(deps) != start:
 
161
        altered = 1
 
162
 
 
163
 
 
164
def get_files(patterns):
 
165
  files = [ ]
 
166
  for pat in string.split(patterns):
 
167
    files.extend(glob.glob(pat))
 
168
  return files
 
169
 
 
170
 
 
171
if __name__ == '__main__':
 
172
  main()