-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdist_config.py
More file actions
141 lines (131 loc) · 4.62 KB
/
Copy pathdist_config.py
File metadata and controls
141 lines (131 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os
import subprocess
import sys
package = 'libtranscript'
srcdirs = [ 'src', 'src.util' ]
excludesrc = '/(Makefile|TODO.*|SciTE.*|run\.sh|test\.c|aliases_full\.txt)$'
auxsources = [ 'src/generic_fallbacks.[ch]', 'src/tables/*.c' ]
auxfiles = [ 'doc/doxygen.conf', 'doc/DoxygenLayout.xml', 'doc/main_doc.h', 'doc/motivation.txt', 'doc/motivation.html' ]
extrabuilddirs = [ 'doc' ]
versioninfo = '1:0:0'
def prebuild(mkdist):
subprocess.call(['./ucm/generate_ltc.sh', '-r', '-n'])
def get_replacements(mkdist):
libversion = versioninfo.split(':', 2)[0]
# Generating the rules for the modules is somewhat hard, because they
# are also autogenerated in the Makefile. However, I don't want to
# duplicate the logic to generate them, because that makes updating them
# harder. So we extract them from the Makefile here.
# First find the MODULES := line. This will tell us the names of the
# modules to build
rules = subprocess.check_output(['make', '-C', 'src', '-p', '-n'])
rules = rules.split('\n')
for rule in rules:
if rule.startswith('MODULES '):
# Line starts with MODULES :=, so only take parts 2 and further
modules = rule.split()[2:]
break
# Then, for each module, find the modules/<module>.la rule. That will tell
# us which objects to build for each module. For each such rule, we
# generate a linker rule, which combines all the objects into the desired
# module target.
# The original Makefile has an order only target for the library. We use
# the | to find the split point for the objects.
module_rules = []
for module in modules:
search_for = 'modules/' + module + '.la:'
for rule in rules:
if rule.startswith(search_for):
break
if not rule.startswith(search_for):
print >>sys.stderr, 'Could not find rule for module %s' % module
module_objects = rule[len(search_for):rule.find('|')].replace('.objects', 'src').split()
module_rules.append('src/' + search_for + ' '.join(module_objects) + ' src/libtranscript.la')
module_rules.append(' $(SILENTLDLT) $(LIBTOOL) $(SILENCELT) --mode=link --tag=CC $(CC) -shared -module -avoid-version -shrext .ltc ' +
'$(CFLAGS) $(LDFLAGS) -o $@ %s $(LDLIBS) -rpath $(libdir)/transcript%s' % (' '.join(module_objects), libversion))
return [
{
'tag': '<VERSION>',
'replacement': mkdist.version
},
{
'tag': '^#define TRANSCRIPT_VERSION .*',
'replacement': '#define TRANSCRIPT_VERSION ' + mkdist.get_version_bin(),
'files': [ 'src/transcript.h' ],
'regex': True
},
{
'tag': '<OBJECTS>',
'replacement': " ".join(mkdist.sources_to_objects(mkdist.include_by_regex(mkdist.sources, '^src/[^/]+$'), '\.c$', '.lo')),
'files': [ 'mk/libtranscript.in' ]
},
{
'tag': '<TABLES>',
'replacement': " ".join(mkdist.sources_to_objects(mkdist.include_by_regex(mkdist.sources, '^src/tables/'), '\.c$', '.la')),
'files': [ 'mk/libtranscript.in' ]
},
{
'tag': '<MODULES>',
'replacement': " ".join([ 'src/modules/%s.la' % module for module in modules ]),
'files': [ 'mk/libtranscript.in' ]
},
{
'tag': '<MODULE_RULES>',
'replacement': '\n'.join(module_rules),
'files': [ 'mk/libtranscript.in' ]
},
{
'tag': '<OBJECTS>',
'replacement': " ".join(mkdist.sources_to_objects(mkdist.include_by_regex(mkdist.sources, '^src\.util/linkltc/'), '\.c$', '.o')),
'files': [ 'mk/linkltc.in' ]
},
{
'tag': '<OBJECTS>',
'replacement': " ".join(mkdist.sources_to_objects(mkdist.include_by_regex(mkdist.sources, '^src\.util/ucm2ltc/'), '\.cc?$', '.o')),
'files': [ 'mk/ucm2ltc.in' ]
},
{
'tag': '<VERSIONINFO>',
'replacement': versioninfo,
'files': [ 'mk/libtranscript.in' ]
},
{
'tag': '<LIBVERSION>',
'replacement': libversion,
'files': [ 'Makefile.in', 'mk/*.in' ]
},
{
'tag': '.objects/',
'replacement': '',
'files': [ 'src.util/ucm2ltc/ucmparser.cc' ]
}
]
def finalize(mkdist):
links = []
proc = subprocess.Popen(['make', '-C', 'src', 'LINKLTC_VERBOSE=-v'], stderr=subprocess.PIPE)
for line in proc.stderr:
parts = line.split()
if len(parts) != 3:
continue
if parts[1] != '->':
continue
if parts[0] == parts[2]:
continue
links.append(parts)
if not links:
sys.exit('Could not generate list of links (check output of make -C src LINKLTC_VERBOSE=-v)')
if proc.wait() != 0:
sys.exit('Generating links produced non-zero exit code')
script_path = os.path.join(mkdist.topdir, 'install_links.sh')
with open(script_path, 'w+') as script:
script.write('''\
#!/bin/sh
if [ $# -ne 1 ]
then
exit 1
fi
''')
for link in links:
script.write('ln -s {0} "$1/{1}"\n'.format(link[2], link[0]))
os.chmod(script_path, 0755)
os.symlink('.', os.path.join(mkdist.topdir, 'src', 'transcript'))