5
import TaskGen,Task,Build,Options
6
from TaskGen import taskgen,feature,after,before
7
from Logs import error,debug
8
def create_task_macapp(self):
9
if self.type=='program'and self.link_task:
10
apptask=self.create_task('macapp',self.env)
11
apptask.set_inputs(self.link_task.outputs)
12
apptask.set_outputs(self.link_task.outputs[0].change_ext('.app'))
14
def apply_link_osx(self):
15
if self.env['MACAPP']or getattr(self,'mac_app',False):
16
self.create_task_macapp()
17
name=self.link_task.outputs[0].name
18
if self.vnum:name=name.replace('.dylib','.%s.dylib'%self.vnum)
19
path=os.path.join(self.env['PREFIX'],lib,name)
20
path='-install_name %s'%path
21
self.env.append_value('LINKFLAGS',path)
22
def apply_bundle(self):
23
if not'shlib'in self.features:return
24
if self.env['MACBUNDLE']or getattr(self,'mac_bundle',False):
25
self.env['shlib_PATTERN']='%s.bundle'
26
uselib=self.to_list(self.uselib)
27
if not'MACBUNDLE'in uselib:uselib.append('MACBUNDLE')
28
def apply_bundle_remove_dynamiclib(self):
29
if not'shlib'in self.features:return
30
if self.env['MACBUNDLE']or getattr(self,'mac_bundle',False):
31
self.env["LINKFLAGS"].remove("-dynamiclib")
32
self.env.append_value("LINKFLAGS","-bundle")
33
app_dirs=['Contents',os.path.join('Contents','MacOS'),os.path.join('Contents','Resources')]
35
<?xml version="1.0" encoding="UTF-8"?>
36
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
39
<key>CFBundlePackageType</key>
41
<key>CFBundleGetInfoString</key>
42
<string>Created by Waf</string>
43
<key>CFBundleSignature</key>
46
<string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
47
<key>CFBundleExecutable</key>
56
for p in task.outputs:
57
srcfile=p.srcpath(env)
58
debug('osx: creating directories')
61
[os.makedirs(os.path.join(srcfile,d))for d in app_dirs]
62
except(OSError,IOError):
64
srcprg=task.inputs[i].srcpath(env)
65
dst=os.path.join(srcfile,'Contents','MacOS')
66
debug('osx: copy %s to %s'%(srcprg,dst))
67
shutil.copy(srcprg,dst)
68
debug('osx: generate Info.plist')
69
f=file(os.path.join(srcfile,"Contents","Info.plist"),"w")
70
f.write(app_info%os.path.basename(srcprg))
74
def install_shlib(task):
75
nums=task.vnum.split('.')
76
path=self.install_path
77
libname=task.outputs[0].name
78
name3=libname.replace('.dylib','.%s.dylib'%task.vnum)
79
name2=libname.replace('.dylib','.%s.dylib'%nums[0])
81
filename=task.outputs[0].abspath(task.env)
83
bld.install_as(path+name3,filename,env=task.env)
84
bld.symlink_as(path+name2,name3)
85
bld.symlink_as(path+name1,name3)
86
def install_target_osx_cshlib(self):
87
if not Options.is_install:return
88
if getattr(self,'vnum','')and sys.platform!='win32':
89
self.link_task.install=install_shlib
90
Task.task_type_from_func('macapp',vars=[],func=app_build,after="cxx_link cc_link ar_link_static")
92
taskgen(create_task_macapp)
93
taskgen(apply_link_osx)
94
after('apply_link')(apply_link_osx)
95
feature('cc','cxx')(apply_link_osx)
97
before('apply_link')(apply_bundle)
98
before('apply_lib_vars')(apply_bundle)
99
feature('cc','cxx')(apply_bundle)
100
taskgen(apply_bundle_remove_dynamiclib)
101
after('apply_link')(apply_bundle_remove_dynamiclib)
102
feature('cc','cxx')(apply_bundle_remove_dynamiclib)
103
taskgen(install_target_osx_cshlib)
104
feature('osx')(install_target_osx_cshlib)
105
after('install_target_cshlib')(install_target_osx_cshlib)