[283] | 1 | #-*- mode: Python;-*-
|
---|
| 2 |
|
---|
[211] | 3 | import sys
|
---|
[212] | 4 | import os
|
---|
[234] | 5 | sys.dont_write_bytecode = True
|
---|
[232] | 6 | from regfi_version import REGFI_VERSION
|
---|
[283] | 7 | ABI_VERSION=REGFI_VERSION.rsplit('.',1)[0]
|
---|
[211] | 8 |
|
---|
[283] | 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?
|
---|
[225] | 11 | cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -fvisibility=hidden'
|
---|
[279] | 12 | cflags += ' -DREGFI_VERSION=\'"%s"\' ' % REGFI_VERSION
|
---|
| 13 | cflags += os.environ.get('CFLAGS','-fPIE -pie -fstack-protector -D_FORTIFY_SOURCE=2')
|
---|
[187] | 14 |
|
---|
[283] | 15 | linkflags = "-fPIC " + os.environ.get('LDFLAGS',"-Wl,-z,relro,-z,now")
|
---|
[279] | 16 |
|
---|
[187] | 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 |
|
---|
[273] | 23 | cc=os.environ.get('CC', 'gcc')
|
---|
[269] | 24 | env = Environment(ENV=os.environ,
|
---|
[273] | 25 | CC=cc,
|
---|
[269] | 26 | CFLAGS=cflags,
|
---|
[283] | 27 | LINKFLAGS=linkflags,
|
---|
[191] | 28 | CPPPATH=['include', '/usr/local/include'],
|
---|
| 29 | LIBPATH=['lib', '/usr/local/lib'],
|
---|
[195] | 30 | LIBS=['m', 'pthread', 'regfi', 'talloc'])
|
---|
[191] | 31 |
|
---|
[279] | 32 |
|
---|
[187] | 33 | # Libraries
|
---|
| 34 | libregfi_static = env.Library(lib_src)
|
---|
[277] | 35 | libregfi = env.SharedLibrary(lib_src, LIBS=['m','pthread', 'talloc'],
|
---|
[283] | 36 | SHLIBVERSION=ABI_VERSION)
|
---|
[187] | 37 |
|
---|
[189] | 38 |
|
---|
[187] | 39 | # Executables
|
---|
[191] | 40 | reglookup = env.Program(['src/reglookup.c'])
|
---|
| 41 | reglookup_recover = env.Program(['src/reglookup-recover.c'])
|
---|
[187] | 42 |
|
---|
[189] | 43 |
|
---|
[187] | 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',
|
---|
[189] | 50 | src_suffix = '.docbook')
|
---|
[187] | 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 |
|
---|
[189] | 57 | # Installation
|
---|
[277] | 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')
|
---|
[246] | 64 |
|
---|
[280] | 65 | install_bin = [destdir + bindir, destdir + mandir]
|
---|
| 66 | install_lib = [destdir + libdir, destdir + includedir + '/regfi']
|
---|
[212] | 67 |
|
---|
[277] | 68 | env.Install(destdir+bindir, [reglookup, reglookup_recover, 'bin/reglookup-timeline'])
|
---|
[283] | 69 | libinstall = env.InstallVersionedLib(destdir+libdir, [libregfi, libregfi_static], SHLIBVERSION=ABI_VERSION)
|
---|
[277] | 70 | env.Install(destdir+includedir+'/regfi', Glob('include/*.h'))
|
---|
| 71 | env.Install(destdir+mandir+'/man1', [man_reglookup, man_reglookup_recover,
|
---|
| 72 | man_reglookup_timeline])
|
---|
[279] | 73 |
|
---|
| 74 | if os.getuid() == 0 and destdir == '':
|
---|
[277] | 75 | env.AddPostAction(libinstall, 'ldconfig')
|
---|
| 76 |
|
---|
[280] | 77 | install_pyregfi = []
|
---|
[212] | 78 | if sys.version_info[0] == 2:
|
---|
[280] | 79 | install_pyregfi.append('pyregfi2-install.log')
|
---|
[253] | 80 | env.Command('pyregfi2-install.log', ['python/pyregfi/__init__.py',
|
---|
| 81 | 'python/pyregfi/structures.py',
|
---|
| 82 | 'python/pyregfi/winsec.py'],
|
---|
[279] | 83 | "python setup.py install --root=/%s | tee pyregfi2-install.log" % destdir)
|
---|
[189] | 84 |
|
---|
[212] | 85 | python_path = os.popen('which python3').read()
|
---|
| 86 | if python_path != '':
|
---|
[280] | 87 | install_pyregfi.append('pyregfi3-install.log')
|
---|
[253] | 88 | env.Command('pyregfi3-install.log', ['python/pyregfi/__init__.py',
|
---|
| 89 | 'python/pyregfi/structures.py',
|
---|
| 90 | 'python/pyregfi/winsec.py'],
|
---|
[279] | 91 | "python3 setup.py install --root=/%s | tee pyregfi3-install.log" % destdir)
|
---|
[212] | 92 |
|
---|
[281] | 93 |
|
---|
[238] | 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')
|
---|
[212] | 101 |
|
---|
[280] | 102 | install_items = install_bin + install_lib + install_pyregfi
|
---|
[238] | 103 |
|
---|
[187] | 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])
|
---|
[238] | 110 | env.Alias('doc-devel', [regfi_doc, pyregfi_doc])
|
---|
[280] | 111 | env.Alias('install_bin', install_bin)
|
---|
| 112 | env.Alias('install_lib', install_lib)
|
---|
| 113 | env.Alias('install_pyregfi', install_pyregfi)
|
---|
[212] | 114 | env.Alias('install', install_items)
|
---|
[187] | 115 |
|
---|
| 116 | Default('bin', libregfi)
|
---|