Skip to content

Commit

Permalink
fix(build/embed): include all Emacs C sources and related files in th…
Browse files Browse the repository at this point in the history
…e Emacs.app bundle

Changelog files from the `src` directory are however excluded. They're
6.7MB, span 1985 to 2015, and are not very relevant for inclusion within
the Emacs.app bundle.

Resolves #40
  • Loading branch information
jimeh committed Nov 28, 2024
1 parent 41953a8 commit 4c987ba
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions build-emacs-for-macos
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ class Build

patches.each { |patch| apply_patch(patch, target) }

# Keep a copy of src after patches have been applied. This will be used to
# embed C sources into the output Emacs.app bundle.
cmd('cp', '-a', File.join(target, 'src'), File.join(target, 'src.orig'))

target
end

Expand Down Expand Up @@ -1211,16 +1215,18 @@ class CSourcesEmbedder < AbstractEmbedder
def embed
info 'Bundling C source files into Emacs.app for documentation purposes...'

orig_src_dir = File.join(source_dir, 'src.orig')
src_dir = File.join(source_dir, 'src')
target_dir = File.join(resources_dir, 'src')
debug "Copying *.c and *.h files from '#{src_dir}' " \
"to: #{relative_path(target_dir)}"

Dir[File.join(src_dir, '**', '*.{c,h}')].each do |f|
rel = f[src_dir.size + 1..-1]
target = File.join(target_dir, rel)
FileUtils.mkdir_p(File.dirname(target))
cmd('cp', '-pRL', f, target)
debug "Copying Emacs C sources to #{relative_app_path(target_dir)}"

if File.exist?(orig_src_dir)
copy_sources(orig_src_dir, target_dir)
else
copy_sources(
src_dir, target_dir, File.join('**', '*.{awk,c,cc,h,in,m,mk}')
)
end

if File.exist?(site_start_el_file) &&
Expand All @@ -1235,6 +1241,18 @@ class CSourcesEmbedder < AbstractEmbedder

private

def copy_sources(src_dir, target_dir, pattern = File.join('**', '*'))
Dir[File.join(src_dir, pattern)].each do |f|
next if File.directory?(f) ||
File.basename(f).downcase.start_with?('changelog')

rel = relative_path(src_dir, f)
target = File.join(target_dir, rel)
FileUtils.mkdir_p(File.dirname(target))
run_cmd('cp', '-pRL', f, target)
end
end

def site_start_el_file
@site_start_el_file ||= File.join(resources_dir, 'lisp', 'site-start.el')
end
Expand All @@ -1260,10 +1278,9 @@ class LibEmbedder < AbstractEmbedder
binary ||= bin

FileUtils.cd(File.dirname(app)) do
rel_path = Pathname.new(lib_dir).relative_path_from(
Pathname.new(File.dirname(binary))
).to_s
rpath = File.join('@executable_path', rel_path)
rpath = File.join(
'@executable_path', relative_path(File.dirname(binary), lib_dir)
)

copy, relink = build_bundle_plan(binary)

Expand Down

0 comments on commit 4c987ba

Please sign in to comment.