Skip to content

Commit

Permalink
meson: de-duplicate binaries using hard links
Browse files Browse the repository at this point in the history
  • Loading branch information
floppym committed May 29, 2024
1 parent 3d30b6f commit 3307bc8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 29 deletions.
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project('OpenRC', 'c',
'prefix=/usr',
'warning_level=3',
],
meson_version : '>=0.53.2')
meson_version : '>=0.57.0')

cc = meson.get_compiler('c')
fs = import('fs')
Expand Down Expand Up @@ -201,6 +201,8 @@ init_d_conf_data.set('SYSCONFDIR', get_option('sysconfdir'))
dl_dep = cc.find_library('dl', required: false)
util_dep = cc.find_library('util', required: false)

install_hardlinks = files('tools' / 'meson_install_hardlinks.sh')

subdir('bash-completion')
subdir('conf.d')
subdir('etc')
Expand Down
23 changes: 16 additions & 7 deletions src/einfo/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
einfo_execs = [
'einfon',
'einfo',
'ewarnn',
'ewarn',
'eerrorn',
Expand All @@ -22,11 +21,21 @@ einfo_execs = [
'veoutdent',
]

einfo = executable('einfo',
['einfo.c', version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)

foreach exec: einfo_execs
executable(exec,
['einfo.c', version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)
custom_target(exec,
build_by_default: true,
command: ['ln', '-fn', einfo, '@OUTPUT@'],
output: exec)
endforeach

meson.add_install_script(install_hardlinks,
rc_bindir,
'einfo',
einfo_execs)
23 changes: 16 additions & 7 deletions src/mark_service/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mark_service_execs = [
'mark_service_starting',
'mark_service_started',
'mark_service_stopping',
'mark_service_stopped',
Expand All @@ -10,11 +9,21 @@ mark_service_execs = [
'mark_service_crashed',
]

mark_service = executable('mark_service_starting',
['mark_service.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo,librc],
install: true,
install_dir: rc_sbindir)

foreach exec : mark_service_execs
executable(exec,
['mark_service.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo,librc],
install: true,
install_dir: rc_sbindir)
custom_target(exec,
build_by_default: true,
command: ['ln', '-fn', mark_service, '@OUTPUT@'],
output: exec)
endforeach

meson.add_install_script(install_hardlinks,
rc_sbindir,
'mark_service_starting',
mark_service_execs)
23 changes: 16 additions & 7 deletions src/service/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
service_execs = [
'service_starting',
'service_started',
'service_stopping',
'service_stopped',
Expand All @@ -10,11 +9,21 @@ service_execs = [
'service_crashed',
]

service = executable('service_starting',
['service.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)

foreach exec : service_execs
executable(exec,
['service.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)
custom_target(exec,
build_by_default: true,
command: ['ln', '-fn', service, '@OUTPUT@'],
output: exec)
endforeach

meson.add_install_script(install_hardlinks,
rc_bindir,
'service_starting',
service_execs)
23 changes: 16 additions & 7 deletions src/value/meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
value_execs = [
'service_get_value',
'service_set_value',
'get_options',
'save_options',
]

value = executable('service_get_value',
['value.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)

foreach exec : value_execs
executable(exec,
['value.c', misc_c, version_h],
include_directories: [incdir, einfo_incdir, rc_incdir],
link_with: [libeinfo, librc],
install: true,
install_dir: rc_bindir)
custom_target(exec,
build_by_default: true,
command: ['ln', '-fn', value, '@OUTPUT@'],
output: exec)
endforeach

meson.add_install_script(install_hardlinks,
rc_bindir,
'service_get_value',
value_execs)
8 changes: 8 additions & 0 deletions tools/meson_install_hardlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
dir=$1
target=$2
shift 2
for linkname; do
ln -fn "${DESTDIR}${dir}/${target}" "${DESTDIR}${dir}/${linkname}"
done

0 comments on commit 3307bc8

Please sign in to comment.