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