1#!/usr/local/bin/python3.8 2""" Copyright (C) 2013 2014 2015 Johan Mattsson 3 4This program is free software: you can redistribute it and/or modify 5it under the terms of the GNU General Public License as published by 6the Free Software Foundation, either version 3 of the License, or 7(at your option) any later version. 8 9This program is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License 15along with this program. If not, see <http://www.gnu.org/licenses/>. 16""" 17 18import os 19import subprocess 20import glob 21import platform 22import sys 23from optparse import OptionParser 24from scripts import config 25from scripts import version 26from scripts.run import run 27 28def getDest (file, dir): 29 f = dest + prefix + dir + '/' 30 s = file.rfind ('/') 31 if s > -1: 32 f += file[s + 1:] 33 else: 34 f += file 35 return f 36 37def getDestRoot (file, dir): 38 f = dest + dir + '/' 39 s = file.rfind ('/') 40 if s > -1: 41 f += file[s + 1:] 42 else: 43 f += file 44 return f 45 46def install (file, dir, mode): 47 f = getDest (file, dir) 48 print ("install: " + f) 49 run ('install -d ' + dest + prefix + dir) 50 run ('install -m ' + str(mode) + ' ' + file + ' ' + dest + prefix + dir + '/') 51 installed.write (f + "\n") 52 53def install_root (file, dir, mode): 54 f = getDestRoot (file, dir) 55 print ("install: " + f) 56 run ('install -d ' + dest + dir) 57 run ('install -m ' + str(mode) + ' ' + file + ' ' + dest + dir + '/') 58 59def link (dir, file, linkname): 60 f = getDest (linkname, dir) 61 print ("install link: " + f) 62 run ('cd ' + dest + prefix + dir + ' && ln -sf ' + file + ' ' + linkname) 63 installed.write (f + "\n") 64 65if not os.path.exists ("build/configured"): 66 print ("Project is not configured") 67 exit (1) 68 69parser = OptionParser() 70parser.add_option ("-d", "--dest", dest="dest", help="install to this directory", metavar="DEST") 71parser.add_option ("-m", "--nogzip", dest="nogzip", help="don't gzip manpages", default=False) 72parser.add_option ("-n", "--manpages-directory", dest="mandir", help="put man pages in this directory under prefix") 73parser.add_option ("-l", "--libdir", dest="libdir", help="path to directory for shared libraries (lib or lib64).") 74parser.add_option ("-c", "--skip-command-line-tools", dest="nocli", help="don't install command line tools") 75parser.add_option ("-a", "--apport", dest="apport", help="install apport scripts", default=True) 76 77(options, args) = parser.parse_args() 78 79if not options.dest: 80 options.dest = "" 81 82if not options.nocli: 83 options.nocli = False 84 85nogzip = options.nogzip 86 87if not options.mandir: 88 mandir = "/man/man1" 89else: 90 mandir = options.mandir 91 92prefix = config.PREFIX 93dest = options.dest 94 95# create uninstall file 96installed = open ('build/installed', 'w') 97installed.write ('build/installed\n') 98 99# install it: 100install ('resources/icons.birdfont', '/share/birdfont', 644) 101install ('resources/bright.theme', '/share/birdfont', 644) 102install ('resources/dark.theme', '/share/birdfont', 644) 103install ('resources/high_contrast.theme', '/share/birdfont', 644) 104install ('resources/key_bindings.xml', '/share/birdfont', 644) 105install ('resources/linux/birdfont_window_icon.png', '/share/birdfont', 644) 106install ('resources/linux/birdfont.desktop', '/share/applications', 644) 107install ('resources/ucd.sqlite', '/share/birdfont', 644) 108install ('resources/codepages.sqlite', '/share/birdfont', 644) 109install ('resources/Roboto-Regular.ttf', '/share/birdfont', 644) 110 111install ('resources/linux/256x256/birdfont.png', '/share/icons/hicolor/256x256/apps', 644) 112install ('resources/linux/128x128/birdfont.png', '/share/icons/hicolor/128x128/apps', 644) 113install ('resources/linux/48x48/birdfont.png', '/share/icons/hicolor/48x48/apps', 644) 114 115install ('resources/linux/birdfont.appdata.xml', '/share/metainfo', 644) 116 117if os.path.isfile ('build/bin/birdfont'): 118 install ('build/bin/birdfont', '/bin', 755) 119 120if not options.nocli: 121 install ('build/bin/birdfont-autotrace', '/bin', 755) 122 install ('build/bin/birdfont-export', '/bin', 755) 123 install ('build/bin/birdfont-import', '/bin', 755) 124 125def is_debian(): 126 try: 127 version = platform.version() 128 print("OS Version: " + version) 129 130 if version.find("Ubuntu") > -1: 131 return True 132 133 if version.find("Debian") > -1: 134 return True 135 136 except: 137 return False 138 139 return False 140 141#library 142if sys.platform == 'darwin': 143 libdir = '/lib' 144elif not options.libdir: 145 if is_debian(): 146 process = subprocess.Popen(['dpkg-architecture', '-qDEB_HOST_MULTIARCH'], stdout=subprocess.PIPE) 147 out, err = process.communicate() 148 out = out.decode('ascii') 149 libdir = '/lib/' + out.rstrip ('\n') 150 else: 151 p = platform.machine() 152 if p == 'i386' or p == 's390' or p == 'ppc' or p == 'armv7hl': 153 libdir = '/lib' 154 elif p == 'x86_64' or p == 's390x' or p == 'ppc64': 155 libdir = '/lib' 156 else: 157 libdir = '/lib' 158else: 159 libdir = options.libdir 160 161if "openbsd" in sys.platform: 162 install ('build/bin/libbirdfont.so.' + '${LIBbirdfont_VERSION}', '/lib', 644) 163elif os.path.isfile ('build/bin/libbirdfont.so.' + version.SO_VERSION): 164 install ('build/bin/libbirdfont.so.' + version.SO_VERSION, libdir, 644) 165 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR) 166 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so') 167elif os.path.isfile ('build/libbirdfont.so.' + version.SO_VERSION): 168 install ('build/libbirdfont.so.' + version.SO_VERSION, libdir, 644) 169 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR) 170 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so') 171elif os.path.isfile ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib'): 172 install ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib', libdir, 644) 173 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib.' + version.SO_VERSION_MAJOR) 174 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib') 175else: 176 print ("Can't find libbirdfont.") 177 exit (1) 178 179if "openbsd" in sys.platform: 180 install ('build/bin/libbirdgems.so.' + '${LIBbirdgems_VERSION}', '/lib', 644) 181elif os.path.isfile ('build/bin/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION): 182 install ('build/bin/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, libdir, 644) 183 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION_MAJOR) 184 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so') 185elif os.path.isfile ('build/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION): 186 install ('build/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, libdir, 644) 187 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION_MAJOR) 188 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so') 189elif os.path.isfile ('build/bin/libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib'): 190 install ('build/bin/libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', libdir, 644) 191 link (libdir, 'libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', ' libbirdgems.dylib.' + version.LIBBIRDGEMS_SO_VERSION_MAJOR) 192 link (libdir, 'libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', ' libbirdgems.dylib') 193else: 194 print ("Can't find libbirdgems, version: " + version.LIBBIRDGEMS_SO_VERSION) 195 exit (1) 196 197 198#manpages 199 200if not nogzip: 201 install ('build/birdfont.1.gz', mandir, 644) 202 203 if not options.nocli: 204 install ('build/birdfont-autotrace.1.gz', mandir, 644) 205 install ('build/birdfont-export.1.gz', mandir, 644) 206 install ('build/birdfont-import.1.gz', mandir, 644) 207else: 208 install ('resources/linux/birdfont.1', mandir, 644) 209 210 if not options.nocli: 211 install ('resources/linux/birdfont-autotrace.1', mandir, 644) 212 install ('resources/linux/birdfont-export.1', mandir, 644) 213 install ('resources/linux/birdfont-import.1', mandir, 644) 214 215#translations 216for lang_dir in glob.glob('build/locale/*'): 217 lc = lang_dir.replace ('build/locale/', "") 218 install ('build/locale/' + lc + '/LC_MESSAGES/birdfont.mo', '/share/locale/' + lc + '/LC_MESSAGES' , 644); 219 220#file type 221install ('resources/linux/birdfont.xml', '/share/mime/packages', 644) 222 223#apport hooks 224if options.apport == "True": 225 install ('resources/birdfont.py', '/share/apport/package-hooks', 644) 226 install ('resources/source_birdfont.py', '/share/apport/package-hooks', 644) 227 install_root ('resources/birdfont-crashdb.conf', '/etc/apport/crashdb.conf.d', 644) 228 229installed.close () 230