1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import os,shutil,sys,platform |
---|
6 | from waflib import TaskGen,Task,Build,Options,Utils,Errors |
---|
7 | from waflib.TaskGen import taskgen_method,feature,after_method,before_method |
---|
8 | app_info=''' |
---|
9 | <?xml version="1.0" encoding="UTF-8"?> |
---|
10 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> |
---|
11 | <plist version="0.9"> |
---|
12 | <dict> |
---|
13 | <key>CFBundlePackageType</key> |
---|
14 | <string>APPL</string> |
---|
15 | <key>CFBundleGetInfoString</key> |
---|
16 | <string>Created by Waf</string> |
---|
17 | <key>CFBundleSignature</key> |
---|
18 | <string>????</string> |
---|
19 | <key>NOTE</key> |
---|
20 | <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string> |
---|
21 | <key>CFBundleExecutable</key> |
---|
22 | <string>%s</string> |
---|
23 | </dict> |
---|
24 | </plist> |
---|
25 | ''' |
---|
26 | @feature('c','cxx') |
---|
27 | def set_macosx_deployment_target(self): |
---|
28 | if self.env['MACOSX_DEPLOYMENT_TARGET']: |
---|
29 | os.environ['MACOSX_DEPLOYMENT_TARGET']=self.env['MACOSX_DEPLOYMENT_TARGET'] |
---|
30 | elif'MACOSX_DEPLOYMENT_TARGET'not in os.environ: |
---|
31 | if Utils.unversioned_sys_platform()=='darwin': |
---|
32 | os.environ['MACOSX_DEPLOYMENT_TARGET']='.'.join(platform.mac_ver()[0].split('.')[:2]) |
---|
33 | @taskgen_method |
---|
34 | def create_bundle_dirs(self,name,out): |
---|
35 | bld=self.bld |
---|
36 | dir=out.parent.find_or_declare(name) |
---|
37 | dir.mkdir() |
---|
38 | macos=dir.find_or_declare(['Contents','MacOS']) |
---|
39 | macos.mkdir() |
---|
40 | return dir |
---|
41 | def bundle_name_for_output(out): |
---|
42 | name=out.name |
---|
43 | k=name.rfind('.') |
---|
44 | if k>=0: |
---|
45 | name=name[:k]+'.app' |
---|
46 | else: |
---|
47 | name=name+'.app' |
---|
48 | return name |
---|
49 | @feature('cprogram','cxxprogram') |
---|
50 | @after_method('apply_link') |
---|
51 | def create_task_macapp(self): |
---|
52 | if self.env['MACAPP']or getattr(self,'mac_app',False): |
---|
53 | out=self.link_task.outputs[0] |
---|
54 | name=bundle_name_for_output(out) |
---|
55 | dir=self.create_bundle_dirs(name,out) |
---|
56 | n1=dir.find_or_declare(['Contents','MacOS',out.name]) |
---|
57 | self.apptask=self.create_task('macapp',self.link_task.outputs,n1) |
---|
58 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Contents/MacOS/'%name |
---|
59 | self.bld.install_files(inst_to,n1,chmod=Utils.O755) |
---|
60 | if getattr(self,'mac_resources',None): |
---|
61 | res_dir=n1.parent.parent.make_node('Resources') |
---|
62 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Resources'%name |
---|
63 | for x in self.to_list(self.mac_resources): |
---|
64 | node=self.path.find_node(x) |
---|
65 | if not node: |
---|
66 | raise Errors.WafError('Missing mac_resource %r in %r'%(x,self)) |
---|
67 | parent=node.parent |
---|
68 | if os.path.isdir(node.abspath()): |
---|
69 | nodes=node.ant_glob('**') |
---|
70 | else: |
---|
71 | nodes=[node] |
---|
72 | for node in nodes: |
---|
73 | rel=node.path_from(parent) |
---|
74 | tsk=self.create_task('macapp',node,res_dir.make_node(rel)) |
---|
75 | self.bld.install_as(inst_to+'/%s'%rel,node) |
---|
76 | if getattr(self.bld,'is_install',None): |
---|
77 | self.install_task.hasrun=Task.SKIP_ME |
---|
78 | @feature('cprogram','cxxprogram') |
---|
79 | @after_method('apply_link') |
---|
80 | def create_task_macplist(self): |
---|
81 | if self.env['MACAPP']or getattr(self,'mac_app',False): |
---|
82 | out=self.link_task.outputs[0] |
---|
83 | name=bundle_name_for_output(out) |
---|
84 | dir=self.create_bundle_dirs(name,out) |
---|
85 | n1=dir.find_or_declare(['Contents','Info.plist']) |
---|
86 | self.plisttask=plisttask=self.create_task('macplist',[],n1) |
---|
87 | if getattr(self,'mac_plist',False): |
---|
88 | node=self.path.find_resource(self.mac_plist) |
---|
89 | if node: |
---|
90 | plisttask.inputs.append(node) |
---|
91 | else: |
---|
92 | plisttask.code=self.mac_plist |
---|
93 | else: |
---|
94 | plisttask.code=app_info%self.link_task.outputs[0].name |
---|
95 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Contents/'%name |
---|
96 | self.bld.install_files(inst_to,n1) |
---|
97 | @feature('cshlib','cxxshlib') |
---|
98 | @before_method('apply_link','propagate_uselib_vars') |
---|
99 | def apply_bundle(self): |
---|
100 | if self.env['MACBUNDLE']or getattr(self,'mac_bundle',False): |
---|
101 | self.env['LINKFLAGS_cshlib']=self.env['LINKFLAGS_cxxshlib']=[] |
---|
102 | self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['macbundle_PATTERN'] |
---|
103 | use=self.use=self.to_list(getattr(self,'use',[])) |
---|
104 | if not'MACBUNDLE'in use: |
---|
105 | use.append('MACBUNDLE') |
---|
106 | app_dirs=['Contents','Contents/MacOS','Contents/Resources'] |
---|
107 | class macapp(Task.Task): |
---|
108 | color='PINK' |
---|
109 | def run(self): |
---|
110 | self.outputs[0].parent.mkdir() |
---|
111 | shutil.copy2(self.inputs[0].srcpath(),self.outputs[0].abspath()) |
---|
112 | class macplist(Task.Task): |
---|
113 | color='PINK' |
---|
114 | ext_in=['.bin'] |
---|
115 | def run(self): |
---|
116 | if getattr(self,'code',None): |
---|
117 | txt=self.code |
---|
118 | else: |
---|
119 | txt=self.inputs[0].read() |
---|
120 | self.outputs[0].write(txt) |
---|