@@ -409,6 +409,10 @@ class Build
409409
410410 patches . each { |patch | apply_patch ( patch , target ) }
411411
412+ # Keep a copy of src after patches have been applied. This will be used to
413+ # embed C sources into the output Emacs.app bundle.
414+ cmd ( 'cp' , '-a' , File . join ( target , 'src' ) , File . join ( target , 'src.orig' ) )
415+
412416 target
413417 end
414418
@@ -1136,8 +1140,12 @@ class AbstractEmbedder
11361140 @app = app
11371141 end
11381142
1139- def relative_path ( path )
1140- Pathname . new ( path ) . relative_path_from ( Pathname . new ( app ) ) . to_s
1143+ def relative_path ( base , path )
1144+ Pathname . new ( path ) . relative_path_from ( Pathname . new ( base ) ) . to_s
1145+ end
1146+
1147+ def relative_app_path ( path )
1148+ relative_path ( app , path )
11411149 end
11421150
11431151 def invocation_dir
@@ -1207,30 +1215,44 @@ class CSourcesEmbedder < AbstractEmbedder
12071215 def embed
12081216 info 'Bundling C source files into Emacs.app for documentation purposes...'
12091217
1218+ orig_src_dir = File . join ( source_dir , 'src.orig' )
12101219 src_dir = File . join ( source_dir , 'src' )
12111220 target_dir = File . join ( resources_dir , 'src' )
1212- debug "Copying *.c and *.h files from '#{ src_dir } ' " \
1213- "to: #{ relative_path ( target_dir ) } "
12141221
1215- Dir [ File . join ( src_dir , '**' , '*.{c,h}' ) ] . each do |f |
1216- rel = f [ src_dir . size + 1 ..-1 ]
1217- target = File . join ( target_dir , rel )
1218- FileUtils . mkdir_p ( File . dirname ( target ) )
1219- cmd ( 'cp' , '-pRL' , f , target )
1222+ debug "Copying Emacs C sources to #{ relative_app_path ( target_dir ) } "
1223+
1224+ if File . exist? ( orig_src_dir )
1225+ copy_sources ( orig_src_dir , target_dir )
1226+ else
1227+ copy_sources (
1228+ src_dir , target_dir , File . join ( '**' , '*.{awk,c,cc,h,in,m,mk}' )
1229+ )
12201230 end
12211231
12221232 if File . exist? ( site_start_el_file ) &&
12231233 File . read ( site_start_el_file ) . include? ( PATH_PATCH )
12241234 return
12251235 end
12261236
1227- debug "Patching '#{ relative_path ( site_start_el_file ) } ' to allow Emacs to " \
1228- 'find bundled C sources'
1237+ debug "Patching '#{ relative_app_path ( site_start_el_file ) } ' to allow " \
1238+ 'Emacs to find bundled C sources'
12291239 File . open ( site_start_el_file , 'a' ) { |f | f . puts ( "\n #{ PATH_PATCH } " ) }
12301240 end
12311241
12321242 private
12331243
1244+ def copy_sources ( src_dir , target_dir , pattern = File . join ( '**' , '*' ) )
1245+ Dir [ File . join ( src_dir , pattern ) ] . each do |f |
1246+ next if File . directory? ( f ) ||
1247+ File . basename ( f ) . downcase . start_with? ( 'changelog' )
1248+
1249+ rel = relative_path ( src_dir , f )
1250+ target = File . join ( target_dir , rel )
1251+ FileUtils . mkdir_p ( File . dirname ( target ) )
1252+ run_cmd ( 'cp' , '-pRL' , f , target )
1253+ end
1254+ end
1255+
12341256 def site_start_el_file
12351257 @site_start_el_file ||= File . join ( resources_dir , 'lisp' , 'site-start.el' )
12361258 end
@@ -1256,10 +1278,9 @@ class LibEmbedder < AbstractEmbedder
12561278 binary ||= bin
12571279
12581280 FileUtils . cd ( File . dirname ( app ) ) do
1259- rel_path = Pathname . new ( lib_dir ) . relative_path_from (
1260- Pathname . new ( File . dirname ( binary ) )
1261- ) . to_s
1262- rpath = File . join ( '@executable_path' , rel_path )
1281+ rpath = File . join (
1282+ '@executable_path' , relative_path ( File . dirname ( binary ) , lib_dir )
1283+ )
12631284
12641285 copy , relink = build_bundle_plan ( binary )
12651286
@@ -1300,7 +1321,7 @@ class LibEmbedder < AbstractEmbedder
13001321
13011322 return if mf . rpaths . include? ( rpath )
13021323
1303- debug "Setting rpath for '#{ relative_path ( macho_file ) } ' to: #{ rpath } "
1324+ debug "Setting rpath for '#{ relative_app_path ( macho_file ) } ' to: #{ rpath } "
13041325 mf . add_rpath ( rpath )
13051326 while_writable ( macho_file ) { mf . write! }
13061327 end
@@ -1330,7 +1351,7 @@ class LibEmbedder < AbstractEmbedder
13301351
13311352 if macho_file . start_with? ( app )
13321353 debug 'Calculating bundling instructions for: ' \
1333- "#{ relative_path ( macho_file ) } "
1354+ "#{ relative_app_path ( macho_file ) } "
13341355 else
13351356 debug "Calculating bundling instructions for: #{ macho_file } "
13361357 end
@@ -1413,7 +1434,8 @@ class LibEmbedder < AbstractEmbedder
14131434
14141435 next if File . exist? ( target )
14151436
1416- debug "Copying '#{ source } ' to: '#{ relative_path ( target ) } ' ('#{ dylib_id } ')"
1437+ debug "Copying '#{ source } ' to: " \
1438+ "'#{ relative_app_path ( target ) } ' ('#{ dylib_id } ')"
14171439 FileUtils . mkdir_p ( File . dirname ( target ) )
14181440 cmd ( 'cp' , '-pRL' , source , target )
14191441
@@ -1434,7 +1456,7 @@ class LibEmbedder < AbstractEmbedder
14341456
14351457 relink_files = relink . group_by { |r | r [ :target_file ] }
14361458 relink_files . each do |target_file , relinks |
1437- debug "Changing linked dylibs in: '#{ relative_path ( target_file ) } '"
1459+ debug "Changing linked dylibs in: '#{ relative_app_path ( target_file ) } '"
14381460 mf = MachO . open ( target_file )
14391461 changed = false
14401462
@@ -1556,7 +1578,7 @@ class GccLibEmbedder < AbstractEmbedder
15561578 rpaths = mf . rpaths . reject { |r | r == '@loader_path' }
15571579 next if rpaths . none?
15581580
1559- debug "Tidying up rpaths from: #{ relative_path ( file_path ) } "
1581+ debug "Tidying up rpaths from: #{ relative_app_path ( file_path ) } "
15601582 rpaths . each { |r | mf . delete_rpath ( r ) }
15611583 mf . write!
15621584 end
@@ -1586,10 +1608,6 @@ class GccLibEmbedder < AbstractEmbedder
15861608 gcc_info . darwin_lib_dir
15871609 end
15881610
1589- def relative_dir ( path , root )
1590- Pathname . new ( path ) . relative_path_from ( Pathname . new ( root ) ) . to_s
1591- end
1592-
15931611 def site_start_el_file
15941612 @site_start_el_file ||= File . join ( resources_dir , 'lisp' , 'site-start.el' )
15951613 end
@@ -1676,17 +1694,17 @@ class GccInfo
16761694
16771695 def app_bundle_target_lib_dir
16781696 @app_bundle_target_lib_dir ||=
1679- relative_dir (
1680- File . join ( embedder . lib_dir , target_lib_dir ) ,
1681- embedder . invocation_dir
1697+ relative_path (
1698+ embedder . invocation_dir ,
1699+ File . join ( embedder . lib_dir , target_lib_dir )
16821700 )
16831701 end
16841702
16851703 def app_bundle_target_darwin_lib_dir
16861704 @app_bundle_target_darwin_lib_dir ||=
1687- relative_dir (
1688- File . join ( embedder . lib_dir , sanitized_target_darwin_lib_dir ) ,
1689- embedder . invocation_dir
1705+ relative_path (
1706+ embedder . invocation_dir ,
1707+ File . join ( embedder . lib_dir , sanitized_target_darwin_lib_dir )
16901708 )
16911709 end
16921710
@@ -1761,8 +1779,8 @@ class GccInfo
17611779 @embedder ||= AbstractEmbedder . new ( Dir . mktmpdir ( %w[ Emacs .app ] ) )
17621780 end
17631781
1764- def relative_dir ( path , root )
1765- Pathname . new ( path ) . relative_path_from ( Pathname . new ( root ) ) . to_s
1782+ def relative_path ( base , path )
1783+ Pathname . new ( path ) . relative_path_from ( Pathname . new ( base ) ) . to_s
17661784 end
17671785end
17681786
0 commit comments