1 | import sys
|
---|
2 | import os
|
---|
3 | sys.dont_write_bytecode = True
|
---|
4 | from regfi_version import REGFI_VERSION
|
---|
5 |
|
---|
6 | # Package Maintainers: should any of these options be omitted during package
|
---|
7 | # build, instead relying on CFLAGS/LDFLAGS to specify them when appropriate?
|
---|
8 | cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -fvisibility=hidden'
|
---|
9 | cflags += ' -DREGFI_VERSION=\'"%s"\' ' % REGFI_VERSION
|
---|
10 | cflags += os.environ.get('CFLAGS','-fPIE -pie -fstack-protector -D_FORTIFY_SOURCE=2')
|
---|
11 |
|
---|
12 | linkflags = "-shared -fPIC -Wl,-soname,libregfi.so.%s " % REGFI_VERSION
|
---|
13 | linkflags += os.environ.get('LDFLAGS','-z relro -z now')
|
---|
14 |
|
---|
15 |
|
---|
16 | lib_src = ['lib/regfi.c',
|
---|
17 | 'lib/winsec.c',
|
---|
18 | 'lib/range_list.c',
|
---|
19 | 'lib/lru_cache.c',
|
---|
20 | 'lib/void_stack.c']
|
---|
21 |
|
---|
22 | cc=os.environ.get('CC', 'gcc')
|
---|
23 | env = Environment(ENV=os.environ,
|
---|
24 | CC=cc,
|
---|
25 | CFLAGS=cflags,
|
---|
26 | CPPPATH=['include', '/usr/local/include'],
|
---|
27 | LIBPATH=['lib', '/usr/local/lib'],
|
---|
28 | LIBS=['m', 'pthread', 'regfi', 'talloc'])
|
---|
29 |
|
---|
30 |
|
---|
31 | # Libraries
|
---|
32 | libregfi_static = env.Library(lib_src)
|
---|
33 | libregfi = env.SharedLibrary(lib_src, LIBS=['m','pthread', 'talloc'],
|
---|
34 | LINKFLAGS=linkflags)
|
---|
35 |
|
---|
36 |
|
---|
37 | # Executables
|
---|
38 | reglookup = env.Program(['src/reglookup.c'])
|
---|
39 | reglookup_recover = env.Program(['src/reglookup-recover.c'])
|
---|
40 |
|
---|
41 |
|
---|
42 | # Documentation
|
---|
43 | # This only needs to be run during the release/packaging process
|
---|
44 | man_fixup = "|sed 's/.SH DESCRIPTION/\\n.SH DESCRIPTION/'"
|
---|
45 | man_builder = Builder(action='docbook2x-man --to-stdout $SOURCE'
|
---|
46 | + man_fixup + '| gzip -9 > $TARGET',
|
---|
47 | suffix = '.gz',
|
---|
48 | src_suffix = '.docbook')
|
---|
49 | env['BUILDERS']['ManPage'] = man_builder
|
---|
50 |
|
---|
51 | man_reglookup = env.ManPage('doc/reglookup.1.docbook')
|
---|
52 | man_reglookup_recover = env.ManPage('doc/reglookup-recover.1.docbook')
|
---|
53 | man_reglookup_timeline = env.ManPage('doc/reglookup-timeline.1.docbook')
|
---|
54 |
|
---|
55 | # Installation
|
---|
56 | prefix = os.environ.get('PREFIX','/usr/local')+'/'
|
---|
57 | destdir = os.environ.get('DESTDIR','')
|
---|
58 | bindir = os.environ.get('BINDIR', prefix + 'bin')
|
---|
59 | libdir = os.environ.get('LIBDIR', prefix + 'lib')
|
---|
60 | includedir = os.environ.get('INCLUDEDIR', prefix + 'include')
|
---|
61 | mandir = os.environ.get('MANDIR', prefix + 'man')
|
---|
62 |
|
---|
63 | install_bin = [destdir + bindir, destdir + mandir]
|
---|
64 | install_lib = [destdir + libdir, destdir + includedir + '/regfi']
|
---|
65 |
|
---|
66 | env.Install(destdir+bindir, [reglookup, reglookup_recover, 'bin/reglookup-timeline'])
|
---|
67 | libinstall = env.Install(destdir+libdir, [libregfi, libregfi_static])
|
---|
68 | env.Install(destdir+includedir+'/regfi', Glob('include/*.h'))
|
---|
69 | env.Install(destdir+mandir+'/man1', [man_reglookup, man_reglookup_recover,
|
---|
70 | man_reglookup_timeline])
|
---|
71 |
|
---|
72 | if os.getuid() == 0 and destdir == '':
|
---|
73 | env.AddPostAction(libinstall, 'ldconfig')
|
---|
74 |
|
---|
75 | # Package Maintainers: Do you need more control over these next two sections?
|
---|
76 | install_pyregfi = []
|
---|
77 | if sys.version_info[0] == 2:
|
---|
78 | install_pyregfi.append('pyregfi2-install.log')
|
---|
79 | env.Command('pyregfi2-install.log', ['python/pyregfi/__init__.py',
|
---|
80 | 'python/pyregfi/structures.py',
|
---|
81 | 'python/pyregfi/winsec.py'],
|
---|
82 | "python setup.py install --root=/%s | tee pyregfi2-install.log" % destdir)
|
---|
83 |
|
---|
84 | python_path = os.popen('which python3').read()
|
---|
85 | if python_path != '':
|
---|
86 | install_pyregfi.append('pyregfi3-install.log')
|
---|
87 | env.Command('pyregfi3-install.log', ['python/pyregfi/__init__.py',
|
---|
88 | 'python/pyregfi/structures.py',
|
---|
89 | 'python/pyregfi/winsec.py'],
|
---|
90 | "python3 setup.py install --root=/%s | tee pyregfi3-install.log" % destdir)
|
---|
91 |
|
---|
92 |
|
---|
93 | # API documentation
|
---|
94 | regfi_doc = env.Command('doc/devel/regfi/index.html',
|
---|
95 | Glob('lib/*.c')+Glob('include/*.h')+['doc/devel/Doxyfile.regfi'],
|
---|
96 | 'doxygen doc/devel/Doxyfile.regfi')
|
---|
97 | pyregfi_doc = env.Command('doc/devel/pyregfi/index.html',
|
---|
98 | Glob('python/pyregfi/*.py')+['doc/devel/Doxyfile.pyregfi', regfi_doc],
|
---|
99 | 'doxygen doc/devel/Doxyfile.pyregfi')
|
---|
100 |
|
---|
101 | install_items = install_bin + install_lib + install_pyregfi
|
---|
102 |
|
---|
103 | # User Friendly Targets
|
---|
104 | env.Alias('libregfi', libregfi)
|
---|
105 | env.Alias('reglookup', reglookup)
|
---|
106 | env.Alias('reglookup-recover', reglookup_recover)
|
---|
107 | env.Alias('bin', [reglookup_recover, reglookup])
|
---|
108 | env.Alias('doc', [man_reglookup,man_reglookup_recover,man_reglookup_timeline])
|
---|
109 | env.Alias('doc-devel', [regfi_doc, pyregfi_doc])
|
---|
110 | env.Alias('install_bin', install_bin)
|
---|
111 | env.Alias('install_lib', install_lib)
|
---|
112 | env.Alias('install_pyregfi', install_pyregfi)
|
---|
113 | env.Alias('install', install_items)
|
---|
114 |
|
---|
115 | Default('bin', libregfi)
|
---|