# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software# # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # EnsureSConsVersion(1, 2, 0) import re from os.path import join as pjoin opts = Variables('build.py') def read_version(prefix, path): version_re = re.compile("(.*)%s_(?PMAJOR|MINOR|PATCH)_VERSION(\s+)(?P\d)(.*)" % prefix) versions = {} fp = open(path, 'rb') for line in fp.readlines(): m = version_re.match(line) if m: versions[m.group('id')] = int(m.group('num')) fp.close() return (versions['MAJOR'], versions['MINOR'], versions['PATCH']) orthrus_major, orthrus_minor, orthrus_patch = read_version('ORTHRUS', 'include/orthrus_version.h') opts.Add(PathVariable('PREFIX', 'Prefix of where to install', '/usr/local', validator=PathVariable.PathAccept)) opts.Add(PathVariable('DESTDIR', 'Prefix for packaging purposes', '/', validator=PathVariable.PathAccept)) opts.Add(PathVariable('APR', 'Path to apr-1-config', '/usr/local/bin/apr-1-config')) opts.Add(PathVariable('APRUTIL', 'Path apu-1-config', '/usr/local/bin/apu-1-config')) env = Environment(options=opts) env.ParseConfig(env['APR'] + ' --cflags --cppflags --includes --libs --ldflags --link-ld') env.ParseConfig(env['APRUTIL'] + ' --includes --ldflags --libs --link-ld') env.AppendUnique(CPPPATH = ["include"]) lib = env.SharedLibrary(target='orthrus-%d' % (orthrus_major), source = ['src/core.c', 'src/error.c', 'src/hex.c', 'src/words.c', 'src/md4.c', 'src/md5.c', 'src/sha1.c', 'src/userdb.c']) headers = env.Glob('include/*.h') conf = env.Configure(config_h='include/private/config.h') conf.CheckCHeader("security/pam_modules.h") conf.CheckCHeader("pam/pam_modules.h") conf.CheckCHeader("security/pam_appl.h") conf.CheckCHeader("pam/pam_appl.h") conf.Finish() appenv = env.Clone() appenv.AppendUnique(LIBS=lib) if appenv['PLATFORM'] != 'darwin': if 0: # TOOD: Figure out if OS supports origin/relative rpaths appenv.Append(LINKFLAGS = Split('-z origin')) appenv.Append(RPATH = env.Literal(pjoin('\\$$ORIGIN', os.pardir, 'lib'))) else: appenv.Append(RPATH = [pjoin(env['PREFIX'], 'lib')]) tests = appenv.Program(target='orthrustest', source = ['src/tests/orthrustest.c']) ortcalc = appenv.Program(target='ortcalc', source = ['src/ui/ortcalc/ortcalc.c']) pamenv = appenv.Clone() pamenv.AppendUnique(LIBS='pam') pamorthrus = pamenv.LoadableModule(target = "pam_orthrus.so", source = ['src/ui/pam/pam_orthrus.c'], SHLIBPREFIX='') install = [] def edit_path(env, obj): if env['PLATFORM'] == 'darwin': env.AddPostAction(obj, "install_name_tool -change 'liborthrus-%d.dylib' '%s/liborthrus-%d.dylib' %s" % (orthrus_major, pjoin(env['PREFIX'], 'lib'), orthrus_major, obj[0].get_abspath())) return obj install.extend(edit_path(env, env.Install(pjoin(env['DESTDIR'], env['PREFIX'], 'bin'), ortcalc))) install.extend(env.Install(pjoin(env['DESTDIR'], env['PREFIX'], 'lib'), lib)) # # TODO: Figure out a better test, how do you know if it uses 'pam' or 'security' # for the directory name. if env['PLATFORM'] == 'darwin': install.extend(edit_path(env, env.Install(pjoin(env['DESTDIR'], env['PREFIX'], 'lib', 'pam'), pamorthrus))) else: install.extend(env.Install(pjoin(env['DESTDIR'], env['PREFIX'], 'lib', 'security'), pamorthrus)) install.extend(env.Install(pjoin(env['DESTDIR'], env['PREFIX'], 'include', "orthrus-%d" % (orthrus_major)), headers)) targets = [lib, pamorthrus, ortcalc, tests] env.Alias('install', install) env.Default(targets)