-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatch_exim_makefile.py
More file actions
executable file
·96 lines (77 loc) · 3.03 KB
/
Copy pathpatch_exim_makefile.py
File metadata and controls
executable file
·96 lines (77 loc) · 3.03 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
#!/usr/bin/env python2
"""
Attempt to figure out what options need to be added to the Exim
Makefile to embed a Python interpreter for your particular platform.
Most of the info seems to be available in the Python distutils.sysconfig
module, cross your fingers.
2002-10-19 Barry Pederson <bp@barryp.org>
"""
import os
import os.path
from distutils import sysconfig
SOURCE_FILE = 'expy_local_scan.c'
def patch_makefile(source_dir, build_dir):
makefile_name = os.path.join(build_dir, 'Local', 'Makefile')
makefile = open(makefile_name, 'r').readlines()
cfg = sysconfig.get_config_var
cflags = '-I%s %s' % (cfg('INCLUDEPY'), cfg('CFLAGSFORSHARED'))
extralibs = '%s -lpython%s' % (cfg('LDFLAGS'), cfg('VERSION'))
source = os.path.join('Local', SOURCE_FILE)
has_options = True
have_local_scan = True
#
# Look for existing CFLAGS and EXTRALIBS lines, and append info.
# Note if this has been done by setting cflags and extralibs to None
#
# Look for LOCAL_SCAN_SOURCE and LOCAL_SCAN_HAS_OPTIONS lines, replace
# if necessary.
#
for i in range(len(makefile)):
if makefile[i].startswith('CFLAGS=') and cflags:
makefile[i] = makefile[i].rstrip() + ' ' + cflags.strip() + '\n'
cflags = None
if makefile[i].startswith('EXTRALIBS=') and extralibs:
makefile[i] = makefile[i].rstrip() + ' ' + extralibs + '\n'
extralibs = None
if makefile[i].startswith('LOCAL_SCAN_SOURCE='):
makefile[i] = 'LOCAL_SCAN_SOURCE=' + source + '\n'
source = None
if makefile[i].startswith('LOCAL_SCAN_HAS_OPTIONS='):
makefile[i] = 'LOCAL_SCAN_HAS_OPTIONS=yes\n'
has_options = False
if makefile[i].startswith('HAVE_LOCAL_SCAN='):
makefile[i] = 'HAVE_LOCAL_SCAN=yes\n'
have_local_scan = False
# Didn't update/replace existing lines? append new ones
#
if cflags:
makefile.append('CFLAGS=%s\n' % cflags)
if extralibs:
makefile.append('EXTRALIBS=%s\n' % extralibs)
if source:
makefile.append('LOCAL_SCAN_SOURCE=%s\n' % source)
if has_options:
makefile.append('LOCAL_SCAN_HAS_OPTIONS=yes\n')
if have_local_scan:
makefile.append('HAVE_LOCAL_SCAN=yes\n')
#
# Write out updated makefile
#
makefile = ''.join(makefile)
open(makefile_name, 'w').write(makefile)
#
# Symlink in C sourcefile
#
os.symlink(os.path.join(source_dir, SOURCE_FILE), os.path.join(build_dir, 'Local', SOURCE_FILE))
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
print 'Attempt to patch Exim makefile to support Python local_scan'
print ' Usage: %s <build_dir>' % sys.argv[0]
print ''
print 'Suggested path for your local_scan module:'
print ' ', os.path.join(sysconfig.get_python_lib(), 'exim_local_scan.py')
sys.exit(1)
build_dir = sys.argv[1]
source_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
patch_makefile(source_dir, build_dir)