.
1 #!/usr/bin/python
2 """
3 Copyright (C) 2013 2014 Johan Mattsson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """
18
19 import os
20 import subprocess
21 import glob
22 import platform
23 from optparse import OptionParser
24 from scripts import config
25 from scripts import version
26 from scripts.run import run
27
28 def 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
37 def install (file, dir, mode):
38 f = getDest (file, dir)
39 print ("install: " + f)
40 run ('install -d ' + dest + prefix + dir)
41 run ('install -m ' + `mode` + ' ' + file + ' ' + dest + prefix + dir + '/')
42 installed.write (f + "\n")
43
44 def link (dir, file, linkname):
45 f = getDest (linkname, dir)
46 print ("install link: " + f)
47 run ('cd ' + dest + prefix + dir + ' && ln -sf ' + file + ' ' + linkname)
48 installed.write (f + "\n")
49
50 if not os.path.exists ("build/configured"):
51 print ("Project is not configured")
52 exit (1)
53
54 if not os.path.exists ("build/installed"):
55 print ("Project is not built")
56 exit (1)
57
58 parser = OptionParser()
59 parser.add_option ("-d", "--dest", dest="dest", help="install to this directory", metavar="DEST")
60 parser.add_option ("-m", "--nogzip", dest="nogzip", help="don't gzip manpages", default=False)
61 parser.add_option ("-n", "--manpages-directory", dest="mandir", help="put man pages in this directory under prefix")
62 parser.add_option ("-l", "--libdir", dest="libdir", help="path to directory for shared libraries (lib or lib64).")
63
64 (options, args) = parser.parse_args()
65
66 if not options.dest:
67 options.dest = ""
68
69 nogzip = options.nogzip
70
71 if not options.mandir:
72 mandir = "/man/man1"
73 else:
74 mandir = options.mandir
75
76 prefix = config.PREFIX
77 dest = options.dest
78
79 # create uninstall file
80 installed = open ('build/installed', 'w')
81 installed.write ('build/installed\n')
82
83 # install it:
84 for file in os.listdir('./icons'):
85 install ('icons/' + file, '/share/birdfont/icons', 644)
86
87 install ('resources/icons.bf', '/share/birdfont', 644)
88 install ('resources/default.theme', '/share/birdfont', 644)
89 install ('resources/key_bindings.xml', '/share/birdfont', 644)
90 install ('resources/roboto.bf', '/share/birdfont', 644)
91
92 install ('resources/linux/birdfont.desktop', '/share/applications', 644)
93 install ('resources/linux/128x128/birdfont.png', '/share/icons/hicolor/128x128/apps', 644)
94 install ('resources/linux/48x48/birdfont.png', '/share/icons/hicolor/48x48/apps', 644)
95
96 install ('resources/linux/birdfont.appdata.xml', '/share/appdata', 644)
97
98 if os.path.isfile ('build/bin/birdfont'):
99 install ('build/bin/birdfont', '/bin', 755)
100
101 install ('build/bin/birdfont-autotrace', '/bin', 755)
102 install ('build/bin/birdfont-export', '/bin', 755)
103 install ('build/bin/birdfont-import', '/bin', 755)
104
105 #library
106 if not options.libdir:
107
108 if platform.dist()[0] == 'Ubuntu' or platform.dist()[0] == 'Debian':
109 process = subprocess.Popen(['dpkg-architecture', '-qDEB_HOST_MULTIARCH'], stdout=subprocess.PIPE)
110 out, err = process.communicate()
111 libdir = '/lib/' + out.rstrip ('\n')
112 else:
113 p = platform.machine()
114 if p == 'i386' or p == 's390' or p == 'ppc' or p == 'armv7hl':
115 libdir = '/lib'
116 elif p == 'x86_64' or p == 's390x' or p == 'ppc64':
117 libdir = '/lib64'
118 else:
119 libdir = '/lib'
120 else:
121 libdir = options.libdir
122
123 if os.path.isfile ('build/bin/libbirdfont.so.' + version.SO_VERSION):
124 install ('build/bin/libbirdfont.so.' + version.SO_VERSION, libdir, 644)
125 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR)
126 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so')
127 elif os.path.isfile ('build/libbirdfont.so.' + version.SO_VERSION):
128 install ('build/libbirdfont.so.' + version.SO_VERSION, libdir, 644)
129 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR)
130 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so')
131 elif os.path.isfile ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib'):
132 install ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib', libdir, 644)
133 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib.' + version.SO_VERSION_MAJOR)
134 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib')
135 else:
136 print ("Can't find libbirdfont.")
137 exit (1)
138
139
140 if os.path.isfile ('build/bin/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION):
141 install ('build/bin/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, libdir, 644)
142 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION_MAJOR)
143 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so')
144 elif os.path.isfile ('build/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION):
145 install ('build/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, libdir, 644)
146 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION_MAJOR)
147 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so')
148 elif os.path.isfile ('build/bin/libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib'):
149 install ('build/bin/libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', libdir, 644)
150 link (libdir, 'libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', ' libbirdxml.dylib.' + version.LIBBIRDXML_SO_VERSION_MAJOR)
151 link (libdir, 'libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', ' libbirdxml.dylib')
152 else:
153 print ("Can't find libbirdxml.")
154
155
156 #manpages
157 if not nogzip:
158 install ('build/birdfont.1.gz', mandir, 644)
159 install ('build/birdfont-autotrace.1.gz', mandir, 644)
160 install ('build/birdfont-export.1.gz', mandir, 644)
161 install ('build/birdfont-import.1.gz', mandir, 644)
162 else:
163 install ('resources/linux/birdfont.1', mandir, 644)
164 install ('resources/linux/birdfont-autotrace.1', mandir, 644)
165 install ('resources/linux/birdfont-export.1', mandir, 644)
166 install ('resources/linux/birdfont-import.1', mandir, 644)
167
168 #translations
169 for lang_dir in glob.glob('build/locale/*'):
170 lc = lang_dir.replace ('build/locale/', "")
171 install ('build/locale/' + lc + '/LC_MESSAGES/birdfont.mo', '/share/locale/' + lc + '/LC_MESSAGES' , 644);
172
173 #file type
174 install ('resources/linux/birdfont.xml', '/share/mime/packages', 644)
175
176 installed.close ()
177