"Fossies" - the Fresh Open Source Software Archive

Member "apr-1.7.0/build/gen-build.py" (17 Nov 2018, 6849 Bytes) of package /linux/www/apr-1.7.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "gen-build.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.6.5_vs_1.7.0.

    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 try:
   14   import configparser
   15 except ImportError:
   16   import ConfigParser as configparser
   17 import codecs
   18 import getopt
   19 import string
   20 import glob
   21 import re
   22 
   23 #import ezt
   24 
   25 #
   26 # legal platforms: aix, beos, netware, os2, os390, unix, win32
   27 # 'make' users: aix, beos, os2, os390, unix, win32 (mingw)
   28 #
   29 PLATFORMS = [ 'aix', 'beos', 'netware', 'os2', 'os390', 'unix', 'win32' ]
   30 MAKE_PLATFORMS = [
   31   ('unix', None),
   32   ('aix', 'unix'),
   33   ('beos', 'unix'),
   34   ('os2', 'unix'),
   35   ('os390', 'unix'),
   36   ('win32', 'unix'),
   37   ]
   38 # note: MAKE_PLATFORMS is an ordered set. we want to generate unix symbols
   39 #       first, so that the later platforms can reference them.
   40 
   41 
   42 def main():
   43   parser = configparser.ConfigParser()
   44   parser.read('build.conf')
   45 
   46   if parser.has_option('options', 'dsp'):
   47     dsp_file = parser.get('options', 'dsp')
   48   else:
   49     dsp_file = None
   50 
   51   headers = get_files(parser.get('options', 'headers'))
   52 
   53   # compute the relevant headers, along with the implied includes
   54   legal_deps = { }
   55   for fname in headers:
   56     legal_deps[os.path.basename(fname)] = fname
   57 
   58   h_deps = { }
   59   for fname in headers:
   60     h_deps[os.path.basename(fname)] = extract_deps(fname, legal_deps)
   61   resolve_deps(h_deps)
   62 
   63   f = open('build-outputs.mk', 'w')
   64   f.write('# DO NOT EDIT. AUTOMATICALLY GENERATED.\n\n')
   65 
   66   # write out the platform-independent files
   67   files = get_files(parser.get('options', 'paths'))
   68   objects, dirs = write_objects(f, legal_deps, h_deps, files)
   69   f.write('\nOBJECTS_all = %s\n\n' % " ".join(objects))
   70 
   71   # for each platform and each subdirectory holding platform-specific files,
   72   # write out their compilation rules, and an OBJECT_<subdir>_<plat> symbol.
   73   for platform, parent in MAKE_PLATFORMS:
   74 
   75     # record the object symbols to build for each platform
   76     group = [ '$(OBJECTS_all)' ]
   77 
   78     # If we're doing win32, we're going to look in the libapr.dsp file
   79     # for those files that we have to manually add to our list.
   80     inherit_parent = { }
   81     if platform == 'win32' and dsp_file:
   82       for line in open(dsp_file).readlines():
   83         if line[:7] != 'SOURCE=':
   84           continue
   85         if line[7:].find('unix') != -1:
   86           # skip the leading .\ and split it out
   87           inherit_files = line[9:].strip().split('\\')
   88           # change the .c to .lo
   89           assert inherit_files[-1][-2:] == '.c'
   90           inherit_files[-1] = inherit_files[-1][:-2] + '.lo'
   91           # replace the \\'s with /'s
   92           inherit_line = '/'.join(inherit_files)
   93           if inherit_files[0] not in inherit_parent:
   94             inherit_parent[inherit_files[0]] = []
   95           inherit_parent[inherit_files[0]].append(inherit_line)
   96 
   97     for subdir in parser.get('options', 'platform_dirs').split():
   98       path = '%s/%s' % (subdir, platform)
   99       if not os.path.exists(path):
  100         # this subdir doesn't have a subdir for this platform, so we'll
  101         # use the parent-platform's set of symbols
  102         if parent:
  103           group.append('$(OBJECTS_%s_%s)' % (subdir, parent))
  104         continue
  105 
  106       # remember that this directory has files/objects
  107       dirs[path] = None
  108 
  109       # write out the compilation lines for this subdir
  110       files = get_files(path + '/*.c')
  111       objects, _unused = write_objects(f, legal_deps, h_deps, files)
  112 
  113       if subdir in inherit_parent:
  114         objects = objects + inherit_parent[subdir]
  115 
  116       symname = 'OBJECTS_%s_%s' % (subdir, platform)
  117 
  118       objects.sort()
  119 
  120       # and write the symbol for the whole group
  121       f.write('\n%s = %s\n\n' % (symname, " ".join(objects)))
  122 
  123       # and include that symbol in the group
  124       group.append('$(%s)' % symname)
  125 
  126     group.sort()
  127 
  128     # write out a symbol which contains the necessary files
  129     f.write('OBJECTS_%s = %s\n\n' % (platform, " ".join(group)))
  130 
  131   f.write('HEADERS = $(top_srcdir)/%s\n\n' % ' $(top_srcdir)/'.join(headers))
  132   f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % " ".join(dirs.keys()))
  133 
  134   if parser.has_option('options', 'modules'):
  135     modules = parser.get('options', 'modules')
  136 
  137     for mod in modules.split():
  138       files = get_files(parser.get(mod, 'paths'))
  139       objects, _unused = write_objects(f, legal_deps, h_deps, files)
  140       flat_objects = " ".join(objects)
  141       f.write('OBJECTS_%s = %s\n' % (mod, flat_objects))
  142 
  143       if parser.has_option(mod, 'target'):
  144         target = parser.get(mod, 'target')
  145         f.write('MODULE_%s = %s\n' % (mod, target))
  146         f.write('%s: %s\n' % (target, flat_objects))
  147         f.write('\t$(LINK_MODULE) -o $@ $(OBJECTS_%s) $(LDADD_%s)\n' % (mod, mod))
  148 
  149       f.write('\n')
  150 
  151   # Build a list of all necessary directories in build tree
  152   alldirs = { }
  153   for dir in dirs.keys():
  154     d = dir
  155     while d:
  156       alldirs[d] = None
  157       d = os.path.dirname(d)
  158 
  159   # Sort so 'foo' is before 'foo/bar'
  160   keys = list(alldirs.keys())
  161   keys.sort()
  162   f.write('BUILD_DIRS = %s\n\n' % " ".join(keys))
  163 
  164   f.write('.make.dirs: $(srcdir)/build-outputs.mk\n' \
  165           '\t@for d in $(BUILD_DIRS); do test -d $$d || mkdir $$d; done\n' \
  166           '\t@echo timestamp > $@\n')
  167 
  168 
  169 def write_objects(f, legal_deps, h_deps, files):
  170   dirs = { }
  171   objects = [ ]
  172 
  173   for file in files:
  174     if file[-10:] == '/apr_app.c':
  175       continue
  176     assert file[-2:] == '.c'
  177     obj = file[:-2] + '.lo'
  178     objects.append(obj)
  179 
  180     dirs[os.path.dirname(file)] = None
  181 
  182     # what headers does this file include, along with the implied headers
  183     deps = extract_deps(file, legal_deps)
  184     for hdr in list(deps.keys()):
  185       deps.update(h_deps.get(hdr, {}))
  186 
  187     vals = list(deps.values())
  188     vals.sort()
  189     f.write('%s: %s .make.dirs %s\n' % (obj, file, " ".join(vals)))
  190 
  191   objects.sort()
  192 
  193   return objects, dirs
  194 
  195 
  196 def extract_deps(fname, legal_deps):
  197   "Extract the headers this file includes."
  198   deps = { }
  199   for line in codecs.open(fname, 'r', 'utf-8').readlines():
  200     if line[:8] != '#include':
  201       continue
  202     inc = _re_include.match(line).group(1)
  203     if inc in legal_deps.keys():
  204       deps[inc] = legal_deps[inc]
  205   return deps
  206 _re_include = re.compile('#include *["<](.*)[">]')
  207 
  208 
  209 def resolve_deps(header_deps):
  210   "Alter the provided dictionary to flatten includes-of-includes."
  211   altered = 1
  212   while altered:
  213     altered = 0
  214     for hdr, deps in header_deps.items():
  215       # print hdr, deps
  216       start = len(deps)
  217       for dep in list(deps.keys()):
  218         deps.update(header_deps.get(dep, {}))
  219       if len(deps) != start:
  220         altered = 1
  221 
  222 def clean_path(path):
  223     return path.replace("\\", "/")
  224 
  225 def get_files(patterns):
  226   files = [ ]
  227   for pat in patterns.split():
  228     files.extend(map(clean_path, glob.glob(pat)))
  229   files.sort()
  230   return files
  231 
  232 
  233 if __name__ == '__main__':
  234   main()