source: clfs-sysroot/BOOK/cross-tools/common/sysroot_wrapper.xml @ 12e6567

Last change on this file since 12e6567 was 12e6567, checked in by Joe Ciccone <jciccone@…>, 15 years ago

Added a sysroot wrapper.
Updated the build variables section of the book, each package uses its own.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4  <!ENTITY % general-entities SYSTEM "../../general.ent">
5  %general-entities;
6]>
7
8<sect1 id="ch-cross-tools-sysroot-wrapper" role="wrap">
9  <?dbhtml filename="sysroot_wrapper.html"?>
10
11  <title>Creating a Sysroot Wrapper</title>
12
13  <indexterm zone="ch-cross-tools-sysroot-wrapper">
14    <primary sortas="a-File">Sysroot Wrapper</primary>
15  </indexterm>
16
17  <sect2 role="package">
18    <title/>
19
20    <para>The Sysroot 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 Sysroot Wrapper</title>
27
28    <para os="a">Create the source file:</para>
29
30<screen os="b"><userinput>cat &gt; sysroot_wrapper.c &lt;&lt; "EOF"
31#include &lt;sys/wait.h&gt;
32#include &lt;stdio.h&gt;
33#include &lt;stdlib.h&gt;
34#include &lt;unistd.h&gt;
35#include &lt;string.h&gt;
36
37char *sysrootdir = "";
38
39int main(int argc, char *argv[]) {
40  sysrootdir = getenv("CLFS");
41  if (!sysrootdir)
42    sysrootdir="";
43
44  int stdout_pipe[2];
45  pipe(stdout_pipe);
46
47  pid_t pid = fork();
48
49  if (pid == 0) {
50    /* Redirect stdout to our pipe */
51    close(1);
52    dup(stdout_pipe[1]);
53    close(stdout_pipe[0]);
54    close(stdout_pipe[1]);
55
56    char *name = strdup(argv[0]);
57    strcat(name, ".sysroot");
58
59    execvp(name, argv);
60
61    free(name);
62
63    exit(0);
64  } else {
65    /* Close stdout for write */
66    close(stdout_pipe[1]);
67
68    /* redirect our stdout pipe from the child to our stdin */
69    close(0);
70    dup(stdout_pipe[0]);
71    close(stdout_pipe[0]);
72
73    char c, lc;
74    char *d = malloc(1);
75    int d_len = 0;
76
77    while ((c = fgetc(stdin)) != EOF) {
78      d_len++;
79      d = realloc(d, d_len + 1);
80      *(d + d_len - 1) = c;
81      *(d + d_len) = '\0';
82
83      if ((lc == '-')&amp;&amp;((c == 'L')||(c == 'I'))) {
84        d_len = d_len + strlen(sysrootdir);
85        d = realloc(d, d_len + 1);
86        strcat(d, sysrootdir);
87      }
88
89      lc = c;
90    }
91
92    printf ("%s", d);
93    free(d);
94
95    exit(0);
96  }
97
98  return 0;
99}
100EOF</userinput></screen>
101
102    <para os="c">Compile and Install the Sysroot Wrapper:</para>
103
104<screen os="d"><userinput>gcc ${BUILD64} sysroot_wrapper.c -o ${CLFS}/cross-tools/bin/sysroot_wrapper</userinput></screen>
105
106  </sect2>
107
108  <sect2 id="contents-sysroot-wrapper" role="content">
109    <title>Contents of The Sysroot Wrapper</title>
110
111    <segmentedlist>
112      <segtitle>Installed programs</segtitle>
113
114      <seglistitem>
115        <seg>sysroot_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="sysroot_wrapper">
125        <term><command>sysroot_wrapper</command></term>
126        <listitem>
127          <para>Description Needed</para>
128          <indexterm zone="ch-cross-tools-sysroot-wrapper sysroot_wrapper">
129            <primary sortas="b-sysroot_wrapper">sysroot_wrapper</primary>
130          </indexterm>
131        </listitem>
132      </varlistentry>
133
134    </variablelist>
135
136  </sect2>
137
138</sect1>
Note: See TracBrowser for help on using the repository browser.