From af1a266670d040d2f4083ff309d732d648afba2a Mon Sep 17 00:00:00 2001 From: Angelos Mouzakitis Date: Tue, 10 Oct 2023 14:33:42 +0000 Subject: Add submodule dependency files Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec --- .../linuxlike/14 static dynamic linkage/main.c | 7 +++++ .../14 static dynamic linkage/meson.build | 36 ++++++++++++++++++++++ .../14 static dynamic linkage/verify_static.py | 29 +++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 meson/test cases/linuxlike/14 static dynamic linkage/main.c create mode 100644 meson/test cases/linuxlike/14 static dynamic linkage/meson.build create mode 100755 meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py (limited to 'meson/test cases/linuxlike/14 static dynamic linkage') diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/main.c b/meson/test cases/linuxlike/14 static dynamic linkage/main.c new file mode 100644 index 000000000..09d1509bb --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/main.c @@ -0,0 +1,7 @@ +#include "stdio.h" +#include "zlib.h" + +int main(void) { + printf("%s\n", zlibVersion()); + return 0; +} diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/meson.build b/meson/test cases/linuxlike/14 static dynamic linkage/meson.build new file mode 100644 index 000000000..fb0e3537a --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/meson.build @@ -0,0 +1,36 @@ +project('static dynamic', 'c') + +# Solaris does not ship static libraries +if host_machine.system() == 'sunos' + has_static = false +else + has_static = true +endif + +cc = meson.get_compiler('c') + +z_default = cc.find_library('z') +if has_static + z_static = cc.find_library('z', static: true) +endif +z_dynamic = cc.find_library('z', static: false) + +exe_default = executable('main_default', 'main.c', dependencies: [z_default]) +if has_static + exe_static = executable('main_static', 'main.c', dependencies: [z_static]) +endif +exe_dynamic = executable('main_dynamic', 'main.c', dependencies: [z_dynamic]) + +test('test default', exe_default) +if has_static + test('test static', exe_static) +endif +test('test dynamic', exe_dynamic) + +if has_static + test('verify static linking', find_program('verify_static.py'), + args: ['--platform=' + host_machine.system(), exe_static.full_path()]) +endif +test('verify dynamic linking', find_program('verify_static.py'), + args: ['--platform=' + host_machine.system(), exe_dynamic.full_path()], + should_fail: true) diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py b/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py new file mode 100755 index 000000000..8d16d48c9 --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Test script that checks if zlib was statically linked to executable""" +import subprocess +import sys + +def handle_common(path): + """Handle the common case.""" + output = subprocess.check_output(['nm', path]).decode('utf-8') + if 'T zlibVersion' in output: + return 0 + return 1 + +def handle_cygwin(path): + """Handle the Cygwin case.""" + output = subprocess.check_output(['nm', path]).decode('utf-8') + if (('I __imp_zlibVersion' in output) or ('D __imp_zlibVersion' in output)): + return 1 + return 0 + +def main(): + """Main function""" + if len(sys.argv) > 2 and sys.argv[1] == '--platform=cygwin': + return handle_cygwin(sys.argv[2]) + else: + return handle_common(sys.argv[2]) + + +if __name__ == '__main__': + sys.exit(main()) -- cgit 1.2.3-korg