about summary refs log tree commit diff stats
path: root/linux/ports.html
blob: 28047c56a76f29ea2c7667850a71aef0b4fc41f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>1.4. Ports</title>
    </head>
    <body>

        <a href="index.html">GNU/Linux Index</a>

        <h1>1.4. Ports</h1>

        <p>This instructions are done
        <a href="configure.html#chroot">inside chroot</a>.</p>

        <h2 id="filesystem">1.4.1. Ports Layout</h2>

	<p>Make sure follow directories exist;</p>

	<pre>
	#  mkdir /usr/ports
	#  mkdir -p /usr/ports/{distfiles,packages,work,pkgbuild}
	</pre>

        <h2 id="fakeroot">1.4.2. Build as user</h2>

        <p>For more information read
	<a href="https://crux.nu/Wiki/FakerootPorts">Fakeroot Ports</a>.
	Add a user that will be used by ports tools, this example pkgmk;</p>

        <pre>
        # useradd -r -U -d /usr/ports -s /bin/false pkgmk
        </pre>

        <p>You can add your self to group pkgmk. Check if members of this
        group are under <a href="linux.html#sysctl">tpe</a> protection.</p>

        <pre>
        # usermod -a -G pkgmk username
        </pre>

        <pre>
	#  chown pkgmk /usr/ports/{distfiles,packages,work,pkgbuild}
	#  chown pkgmk:pkgmk /usr/ports/pkgbuild
	#  chmod g+w /usr/ports/pkgbuild
        </pre>

        <p>Configure to
        <a href="https://crux.nu/Wiki/HowToSpeedUpBuildingPackages#ram">compile in ram</a>
        average of 3GB is recommended for core while firefox need at least 30G.
	Discover id of pkgmk user;</p>

        <pre>
        # id pkgmk
        uid=102(pkgmk) gid=102(pkgmk) groups=102(pkgmk)
        </pre>

        <p>Edit fstab, change uid to id of pkgmk, this example 102;</p>

        <pre>
        pkgmk /usr/ports/work tmpfs size=30G,uid=102,defaults,mode=0750 0 0
        </pre>

        <h2 id="pkgmk">1.4.3. Configure pkgmk</h2>

        <p>Read <a href="https://crux.nu/Handbook3-3#ntoc22">4.5. Adjust/Configure the Package Build Process</a>
        to take advantage of your specific hardware. Packages build with
        native flag will not run on different hardware. This is the best choice
        if you want gcc to find the best settings based on your hardware.</p>

        <p>Edit /etc/pkgmk.conf, remove pipe from compiler flags and let the system
        get from nproc how many cpu's it can use for compiling;</p>

        <pre>
        #
        # /etc/pkgmk.conf: pkgmk(8) configuration
        #

        export CFLAGS="-O2 -march=x86-64"
        export CXXFLAGS="${CFLAGS}"

        export JOBS=$(nproc)
        export MAKEFLAGS="-j $JOBS"

        case ${PKGMK_ARCH} in
                "64"|"")
                        ;;
                "32")
                        export CFLAGS="${CFLAGS} -m32"
                        export CXXFLAGS="${CXXFLAGS} -m32"
                        export LDFLAGS="${LDFLAGS} -m32"
                        export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
                        ;;
                *)
                        echo "Unknown architecture selected! Exiting."
                        exit 1
                        ;;
        esac

        PKGMK_SOURCE_MIRRORS=(https://tribu.semdestino.org/mirror-3.4/distfiles/)
        # PKGMK_SOURCE_DIR="$PWD"
        PKGMK_SOURCE_DIR="/usr/ports/distfiles"
        # PKGMK_PACKAGE_DIR="$PWD"
        PKGMK_PACKAGE_DIR="/usr/ports/packages"
        # PKGMK_WORK_DIR="$PWD/work"
        PKGMK_WORK_DIR="/usr/ports/work/${name}"
        # PKGMK_DOWNLOAD="no"
        # PKGMK_IGNORE_SIGNATURE="no"
        # PKGMK_IGNORE_MD5SUM="no"
        # PKGMK_IGNORE_FOOTPRINT="no"
        # PKGMK_IGNORE_NEW="no"
        # PKGMK_NO_STRIP="no"
        # PKGMK_DOWNLOAD_PROG="wget"
        # PKGMK_WGET_OPTS=""
        # PKGMK_CURL_OPTS=""
        # PKGMK_COMPRESSION_MODE="gz"

        # End of file
        </pre>

        <p>If you want native build change the above example to;</p>

        <pre>
        export CFLAGS="-O2 -march=native -mtune=native"
        </pre>

        <p>Check <a href="toolchain.html">toolchain</a> for more options on how packages
        are build.</p>

        <h2 id="prtget">1.4.4. Configure prt-get</h2>

        <p>Edit /etc/prt-get.conf;</p>

        <pre>
        ###
        ### prt-get conf
        ###

        # note: the order matters: the package found first is used
        prtdir /usr/ports/core
        prtdir /usr/ports/opt
        prtdir /usr/ports/xorg

        # the following line enables the multilib compat-32 collection
        #prtdir /usr/ports/compat-32

        # the following line enables the user maintained contrib collection
        prtdir /usr/ports/contrib
        prtdir /usr/ports/ports
        prtdir /usr/ports/mate
        prtdir /usr/ports/kde5

        ### use mypackage form local directory
        # prtdir /home/packages/build:mypackage

        ### log options:
        writelog enabled         # (enabled|disabled)
        logmode  overwrite       # (append|overwrite)
        rmlog_on_success yes     # (no|yes)
        logfile  /usr/ports/pkgbuild/%n.log
                                   # path, %p=path to port dir, %n=port name
                                   #       %v=version, %r=release

        ### use alternate cache file (default: /var/lib/pkg/prt-get.cache
        # cachefile /mnt/nfs/cache

        ### print README information:
        readme verbose           # (verbose|compact|disabled)

        ### prefer higher versions in sysup / diff
        preferhigher yes      # (yes|no)

        ### use regexp search
        # useregex no        # (yes|no)

        ### run pre- and post-installs scripts; yes is equivalent to the
        ### --install-scripts option
        runscripts yes            # (no|yes)

        ### expert section ###

        ### alternative commands
        makecommand      sudo -H -u pkgmk fakeroot pkgmk
        addcommand       sudo pkgadd
        removecommand    sudo pkgrm
        runscriptcommand sudo sh
        </pre>

        <h2 id="distcc">1.4.5. Ccache and distcc</h2>

        <p>Ccache avoids same code to be compiled by saving
        the output from compilers and identifying same
        input by using hashes and distcc distributes
        compiling process across machines.</p>

        <p>Don't set native or generic on /etc/pkgmk.conf.</p>
        <pre>
        $ prt-get depinst ccache distcc
        </pre>

        <p>Configure pkgmk and define number of cores available,
        in this example get dynamically Edit 
        <a href="conf/pkgmk.conf">/etc/pkgmk.conf</a> and
        set ccaching directory and instructs to use distcc
        backend;</p>

        <pre>
        # ccache settings
        export PATH="/usr/lib/ccache/:$PATH"
        export CCACHE_DIR="/usr/ports/ccache"
        export CCACHE_PREFIX="distcc"
        export CCACHE_COMPILERCHECK="%compiler% -dumpversion; crux"
        </pre>

        <p>Set distcc hosts and respective number of
        cpu cores to send work, hosts names, exp; "worker" must
        be configured on /etc/hosts.</p>

        <pre>
        ### compile using distcc without ccache
        ##export PATH="/usr/lib/distcc/:$PATH"
        ##export DISTCC_HOSTS="localhost/4,lzo,cpp xborg/4,lzo,cpp"
        ##export PUMP_BUILD=yes

        # distcc settings
        export JOBS=$(/usr/bin/distcc -j 2> /dev/null)
        export DISTCC_DIR="/usr/ports/distcc"
        export MAKEFLAGS="-j ${JOBS}"
        export SCONSFLAGS="$MAKEFLAGS"

        # local compile only
        #export JOBS=$(nproc)
        #export MAKEFLAGS="-j $JOBS"
        </pre>

        <p>Configure distcc daemon, edit
        /etc/rc.d/distccd;</p>

        <pre>
        #!/usr/bin/env bash
        #
        # /etc/rc.d/distccd: start/stop distcc daemon
        #

        . /etc/distcc.conf
        if [ -z "$DISTCC_ALLOW" ]; then
        </pre>

        <p>Create /etc/distcc.conf;</p>

        <pre>
        DISTCC_ALLOW="10.0.0.0/8"
        DISTCC_USER="pkgmk"
        DISTCC_LOG_LEVEL="info"
        </pre>

        <a href="index.html">GNU/Linux Index</a>
        <p>
        This is part of the LeetIO System Documentation.
        Copyright (C) 2021
        LeetIO Team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>
    </body>
</html>