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