[5accd22] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[aa18ac0] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[5accd22] | 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
| 8 | <sect1 id="ch-system-multiarch-wrapper" role="wrap">
|
---|
| 9 | <?dbhtml filename="multiarch_wrapper.html"?>
|
---|
| 10 |
|
---|
[72ed305] | 11 | <title>Creating a Multiarch Wrapper</title>
|
---|
[5accd22] | 12 |
|
---|
| 13 | <indexterm zone="ch-system-multiarch-wrapper">
|
---|
[8ab693a] | 14 | <primary sortas="a-Multiarch Wrapper">Multiarch Wrapper</primary>
|
---|
[5accd22] | 15 | </indexterm>
|
---|
| 16 |
|
---|
| 17 | <sect2 role="package">
|
---|
| 18 | <title/>
|
---|
| 19 |
|
---|
| 20 | <para>The Multiarch Wrapper is used to wrap certain binaries that have
|
---|
| 21 | hardcoded paths to libraries or are architecture specific.</para>
|
---|
| 22 |
|
---|
| 23 | </sect2>
|
---|
| 24 |
|
---|
| 25 | <sect2 role="installation">
|
---|
| 26 | <title>Installation of The Multiarch Wrapper</title>
|
---|
| 27 |
|
---|
| 28 | <para os="a">Create the source file:</para>
|
---|
| 29 |
|
---|
| 30 | <screen os="b"><userinput>cat > multiarch_wrapper.c << "EOF"
|
---|
[d4a75ad] | 31 | #define _GNU_SOURCE
|
---|
| 32 |
|
---|
[5accd22] | 33 | #include <errno.h>
|
---|
[d4a75ad] | 34 | #include <stdio.h>
|
---|
| 35 | #include <stdlib.h>
|
---|
| 36 | #include <sys/types.h>
|
---|
| 37 | #include <sys/wait.h>
|
---|
| 38 | #include <unistd.h>
|
---|
[5accd22] | 39 |
|
---|
[d4a75ad] | 40 | #ifndef DEF_SUFFIX
|
---|
| 41 | # define DEF_SUFFIX "64"
|
---|
[5accd22] | 42 | #endif
|
---|
| 43 |
|
---|
[5fb43ca] | 44 | int main(int argc, char **argv)
|
---|
[5accd22] | 45 | {
|
---|
[5fb43ca] | 46 | char *filename;
|
---|
[d4a75ad] | 47 | char *suffix;
|
---|
| 48 |
|
---|
| 49 | if(!(suffix = getenv("USE_ARCH")))
|
---|
| 50 | if(!(suffix = getenv("BUILDENV")))
|
---|
| 51 | suffix = DEF_SUFFIX;
|
---|
| 52 |
|
---|
| 53 | if (asprintf(&filename, "%s-%s", argv[0], suffix) < 0) {
|
---|
| 54 | perror(argv[0]);
|
---|
| 55 | return -1;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | int status = EXIT_FAILURE;
|
---|
| 59 | pid_t pid = fork();
|
---|
| 60 |
|
---|
| 61 | if (pid == 0) {
|
---|
| 62 | execvp(filename, argv);
|
---|
| 63 | perror(filename);
|
---|
| 64 | } else if (pid < 0) {
|
---|
[7949a91] | 65 | perror(argv[0]);
|
---|
[d4a75ad] | 66 | } else {
|
---|
| 67 | if (waitpid(pid, &status, 0) != pid) {
|
---|
| 68 | status = EXIT_FAILURE;
|
---|
[7949a91] | 69 | perror(argv[0]);
|
---|
| 70 | } else {
|
---|
| 71 | status = WEXITSTATUS(status);
|
---|
[d4a75ad] | 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[5accd22] | 75 | free(filename);
|
---|
[d4a75ad] | 76 |
|
---|
| 77 | return status;
|
---|
[5accd22] | 78 | }
|
---|
[d4a75ad] | 79 |
|
---|
[5accd22] | 80 | EOF</userinput></screen>
|
---|
| 81 |
|
---|
| 82 | <para os="c">Compile and Install the Multiarch Wrapper:</para>
|
---|
| 83 |
|
---|
| 84 | <screen os="d"><userinput>gcc ${BUILD64} multiarch_wrapper.c -o /usr/bin/multiarch_wrapper</userinput></screen>
|
---|
| 85 |
|
---|
| 86 | <para os="e">This multiarch wrapper is going to be used later on in the book
|
---|
[a7fa075] | 87 | with Perl. It will also be very useful outside of the base CLFS system.</para>
|
---|
[5accd22] | 88 |
|
---|
[a7fa075] | 89 | <para os="f">Create a testcase:</para>
|
---|
[5accd22] | 90 |
|
---|
| 91 | <screen os="g"><userinput>echo 'echo "32bit Version"' > test-32
|
---|
| 92 | echo 'echo "64bit Version"' > test-64
|
---|
| 93 | chmod 755 test-32 test-64
|
---|
| 94 | ln -sv /usr/bin/multiarch_wrapper test</userinput></screen>
|
---|
| 95 |
|
---|
[a7fa075] | 96 | <para os="h">Test the wrapper:</para>
|
---|
[5accd22] | 97 |
|
---|
| 98 | <screen os="i"><userinput>USE_ARCH=32 ./test
|
---|
| 99 | USE_ARCH=64 ./test</userinput></screen>
|
---|
| 100 |
|
---|
| 101 | <para os="j">The output of the above command should be:</para>
|
---|
| 102 |
|
---|
[32c37aa8] | 103 | <screen os="k" role="nodump"><userinput>32bit Version
|
---|
[5accd22] | 104 | 64bit Version</userinput></screen>
|
---|
| 105 |
|
---|
| 106 | </sect2>
|
---|
| 107 |
|
---|
| 108 | <sect2 id="contents-multiarch-wrapper" role="content">
|
---|
| 109 | <title>Contents of The Multiarch Wrapper</title>
|
---|
| 110 |
|
---|
| 111 | <segmentedlist>
|
---|
| 112 | <segtitle>Installed programs</segtitle>
|
---|
| 113 |
|
---|
| 114 | <seglistitem>
|
---|
| 115 | <seg>multiarch_wrapper</seg>
|
---|
| 116 | </seglistitem>
|
---|
| 117 | </segmentedlist>
|
---|
| 118 |
|
---|
| 119 | <variablelist>
|
---|
| 120 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 121 | <?dbfo list-presentation="list"?>
|
---|
| 122 | <?dbhtml list-presentation="table"?>
|
---|
| 123 |
|
---|
| 124 | <varlistentry id="multiarch_wrapper">
|
---|
| 125 | <term><command>multiarch_wrapper</command></term>
|
---|
| 126 | <listitem>
|
---|
| 127 | <para>Will execute a different program based on the
|
---|
| 128 | <envar>USE_ARCH</envar> variable. The <envar>USE_ARCH</envar>
|
---|
| 129 | variable will be the suffix of the executed program.</para>
|
---|
| 130 | <indexterm zone="ch-system-multiarch-wrapper multiarch_wrapper">
|
---|
| 131 | <primary sortas="b-multiarch_wrapper">multiarch_wrapper</primary>
|
---|
| 132 | </indexterm>
|
---|
| 133 | </listitem>
|
---|
| 134 | </varlistentry>
|
---|
| 135 |
|
---|
| 136 | </variablelist>
|
---|
| 137 |
|
---|
| 138 | </sect2>
|
---|
| 139 |
|
---|
| 140 | </sect1>
|
---|