1# Copyright (C) 2010, 2011, 2018 Olga Yakovleva <yakovleva.o.v@gmail.com> 2 3# This program is free software: you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation, either version 3 of the License, or 6# (at your option) any later version. 7 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16import sys 17import os.path 18import os 19from SCons.Script import * 20 21def exists(env): 22 if env["PLATFORM"]=="win32": 23 return False 24 else: 25 return True 26 27def Install(env,src,instpath,instname=None,sysdir=True,mode=0o644,shlib=False): 28 destpath=env.subst("$DESTDIR"+instpath) 29 env.Alias("install",destpath) 30 if instname: 31 inst=env.InstallAs(os.path.join(destpath,instname),src) 32 else: 33 if shlib: 34 inst=env.InstallVersionedLib(destpath,src) 35 else: 36 inst=env.Install(destpath,src) 37 env.AddPostAction(inst,Chmod("$TARGET",mode)) 38 return inst 39 40def InstallProgram(env,src): 41 return Install(env,src,"$bindir",mode=0o755) 42 43def InstallData(env,src,dest=None): 44 if dest: 45 inst=Install(env,src,os.path.join("$datadir","$package_name",dest)) 46 else: 47 inst=Install(env,src,os.path.join("$datadir","$package_name")) 48 env.Clean("install",env.subst("$DESTDIR$datadir/$package_name")) 49 return inst 50 51def InstallConfig(env,src,dest=None): 52 if dest: 53 inst=Install(env,src,os.path.join("$sysconfdir","$package_name",dest)) 54 else: 55 inst=Install(env,src,os.path.join("$sysconfdir","$package_name")) 56 env.Clean("install",env.subst("$DESTDIR$sysconfdir/$package_name")) 57 return inst 58 59def InstallStaticLibrary(env,src): 60 return Install(env,src,"$libdir") 61 62def InstallSharedLibrary(env,src): 63 return Install(env,src,"$libdir",shlib=True,mode=0o755) 64 65def InstallLibrary(env,src): 66 if env.IsLibraryShared(): 67 return InstallSharedLibrary(env,src) 68 else: 69 return InstallStaticLibrary(env,src) 70 71def InstallHeader(env,src): 72 return Install(env,src,"$includedir") 73 74def InstallServiceFile(env,src): 75 service_file=env.Substfile(src,SUBST_DICT={"@bindir@":"$bindir"}) 76 return Install(env,service_file,"$servicedir") 77 78def generate(env): 79 env.AddMethod(InstallProgram) 80 env.AddMethod(InstallData) 81 env.AddMethod(InstallConfig) 82 env.AddMethod(InstallLibrary) 83 env.AddMethod(InstallHeader) 84 env.AddMethod(InstallServiceFile) 85