[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 | |
---|
[281] | 6 | # Package Maintainers: should any of these options be omitted during package |
---|
| 7 | # build, instead relying on CFLAGS/LDFLAGS to specify them when appropriate? |
---|
[225] | 8 | cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -fvisibility=hidden' |
---|
[279] | 9 | cflags += ' -DREGFI_VERSION=\'"%s"\' ' % REGFI_VERSION |
---|
| 10 | cflags += os.environ.get('CFLAGS','-fPIE -pie -fstack-protector -D_FORTIFY_SOURCE=2') |
---|
[187] | 11 | |
---|
[279] | 12 | linkflags = "-shared -fPIC -Wl,-soname,libregfi.so.%s " % REGFI_VERSION |
---|
| 13 | linkflags += os.environ.get('LDFLAGS','-z relro -z now') |
---|
| 14 | |
---|
[281] | 15 | |
---|
[187] | 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 | |
---|
[273] | 22 | cc=os.environ.get('CC', 'gcc') |
---|
[269] | 23 | env = Environment(ENV=os.environ, |
---|
[273] | 24 | CC=cc, |
---|
[269] | 25 | CFLAGS=cflags, |
---|
[191] | 26 | CPPPATH=['include', '/usr/local/include'], |
---|
| 27 | LIBPATH=['lib', '/usr/local/lib'], |
---|
[195] | 28 | LIBS=['m', 'pthread', 'regfi', 'talloc']) |
---|
[191] | 29 | |
---|
[279] | 30 | |
---|
[187] | 31 | # Libraries |
---|
| 32 | libregfi_static = env.Library(lib_src) |
---|
[277] | 33 | libregfi = env.SharedLibrary(lib_src, LIBS=['m','pthread', 'talloc'], |
---|
[279] | 34 | LINKFLAGS=linkflags) |
---|
[187] | 35 | |
---|
[189] | 36 | |
---|
[187] | 37 | # Executables |
---|
[191] | 38 | reglookup = env.Program(['src/reglookup.c']) |
---|
| 39 | reglookup_recover = env.Program(['src/reglookup-recover.c']) |
---|
[187] | 40 | |
---|
[189] | 41 | |
---|
[187] | 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', |
---|
[189] | 48 | src_suffix = '.docbook') |
---|
[187] | 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 | |
---|
[189] | 55 | # Installation |
---|
[277] | 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') |
---|
[246] | 62 | |
---|
[280] | 63 | install_bin = [destdir + bindir, destdir + mandir] |
---|
| 64 | install_lib = [destdir + libdir, destdir + includedir + '/regfi'] |
---|
[212] | 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 | |
---|
[280] | 75 | install_pyregfi = [] |
---|
[212] | 76 | if sys.version_info[0] == 2: |
---|
[280] | 77 | install_pyregfi.append('pyregfi2-install.log') |
---|
[253] | 78 | env.Command('pyregfi2-install.log', ['python/pyregfi/__init__.py', |
---|
| 79 | 'python/pyregfi/structures.py', |
---|
| 80 | 'python/pyregfi/winsec.py'], |
---|
[279] | 81 | "python setup.py install --root=/%s | tee pyregfi2-install.log" % destdir) |
---|
[189] | 82 | |
---|
[212] | 83 | python_path = os.popen('which python3').read() |
---|
| 84 | if python_path != '': |
---|
[280] | 85 | install_pyregfi.append('pyregfi3-install.log') |
---|
[253] | 86 | env.Command('pyregfi3-install.log', ['python/pyregfi/__init__.py', |
---|
| 87 | 'python/pyregfi/structures.py', |
---|
| 88 | 'python/pyregfi/winsec.py'], |
---|
[279] | 89 | "python3 setup.py install --root=/%s | tee pyregfi3-install.log" % destdir) |
---|
[212] | 90 | |
---|
[281] | 91 | |
---|
[238] | 92 | # API documentation |
---|
| 93 | regfi_doc = env.Command('doc/devel/regfi/index.html', |
---|
| 94 | Glob('lib/*.c')+Glob('include/*.h')+['doc/devel/Doxyfile.regfi'], |
---|
| 95 | 'doxygen doc/devel/Doxyfile.regfi') |
---|
| 96 | pyregfi_doc = env.Command('doc/devel/pyregfi/index.html', |
---|
| 97 | Glob('python/pyregfi/*.py')+['doc/devel/Doxyfile.pyregfi', regfi_doc], |
---|
| 98 | 'doxygen doc/devel/Doxyfile.pyregfi') |
---|
[212] | 99 | |
---|
[280] | 100 | install_items = install_bin + install_lib + install_pyregfi |
---|
[238] | 101 | |
---|
[187] | 102 | # User Friendly Targets |
---|
| 103 | env.Alias('libregfi', libregfi) |
---|
| 104 | env.Alias('reglookup', reglookup) |
---|
| 105 | env.Alias('reglookup-recover', reglookup_recover) |
---|
| 106 | env.Alias('bin', [reglookup_recover, reglookup]) |
---|
| 107 | env.Alias('doc', [man_reglookup,man_reglookup_recover,man_reglookup_timeline]) |
---|
[238] | 108 | env.Alias('doc-devel', [regfi_doc, pyregfi_doc]) |
---|
[280] | 109 | env.Alias('install_bin', install_bin) |
---|
| 110 | env.Alias('install_lib', install_lib) |
---|
| 111 | env.Alias('install_pyregfi', install_pyregfi) |
---|
[212] | 112 | env.Alias('install', install_items) |
---|
[187] | 113 | |
---|
| 114 | Default('bin', libregfi) |
---|