1# vim: syntax=pod 2 3If you read this file _as_is_, just ignore the funny characters you see. 4It is written in the POD format (see pod/perlpod.pod) which is specially 5designed to be readable as is. But if you have been into Perl you 6probably already know this. 7 8=head1 NAME 9 10perlsynology - Perl 5 on Synology DSM systems 11 12=head1 DESCRIPTION 13 14Synology manufactures a vast number of Network Attached Storage (NAS) 15devices that are very popular in large organisations as well as small 16businesses and homes. 17 18The NAS systems are equipped with Synology Disk Storage Manager (DSM), 19which is a trimmed-down Linux system enhanced with several tools for 20managing the NAS. There are several flavours of hardware: Marvell 21Armada (ARMv5tel, ARMv7l), Intel Atom (i686, x86_64), Freescale QorIQ 22(PPC), and more. For a full list see the 23L<Synology FAQ|https://kb.synology.com/en-global/DSM/tutorial/What_kind_of_CPU_does_my_NAS_have>. 24 25Since it is based on Linux, the NAS can run many popular Linux 26software packages, including Perl. In fact, Synology provides a 27ready-to-install package for Perl, depending on the version of DSM 28the installed perl ranges from 5.8.6 on DSM-4.3 to 5.28.1 on DSM-7.1. 29 30There is an active user community that provides many software packages 31for the Synology DSM systems; at the time of writing this document 32they provide Perl version 5.28.1. 33 34This document describes various features of Synology DSM operating 35system that will affect how Perl 5 (hereafter just Perl) is 36configured, compiled and/or runs. It has been compiled and verified by 37Johan Vromans for the Synology DS413 (QorIQ), with feedback from 38H.Merijn Brand (DS213: ARMv5tel, RS815: Intel Atom x64, and DS218+: 39Celeron J3355). 40 41=head2 Setting up the build environment 42 43=head3 DSM 7 44 45For a comfortable development environment, Entware is currently the only 46viable solution. Just follow the detailed instructions on 47L<Install Entware on Synology NAS|https://github.com/Entware/Entware/wiki/Install-on-Synology-NAS>. 48supported architectures are armv5, armv7, mipsel, wl500g, x86_32, and x86_64. 49Check L<here|https://pkg.entware.net/binaries/> for supported platforms. 50 51That github link also shows what environments should be supported. 52 53It was tested on DSM-7.1 by H.Merijn Brand on a DS218+ and a DS220+ (both 54Intel x64). 55 56Entware comes with a precompiled 5.26.1 (Jan 2018) that allowes 57building shared XS code. Note that this installation does B<not> use 58a site_perl folder. The available C<cpan> works. If all required 59development packages are installed too, also for XS. 60 61Installing perl from the Community package center: 62 63=over 4 64 65=item * 66 67Using your favourite browser open the DSM management page and start 68the Package Center. 69 70=item * 71 72In Settings, add the following Package Sources: 73 74 Name: Community 75 Location: https://synopackage.com/repository/spk/All 76 77=item * 78 79Still in Settings, in Channel Update, select Beta Channel. 80 81=back 82 83To complete the development environment, install make and gcc 84 85 ds220# opkg install make gcc 86 87Then, optionally, make sure you use the more recent bash and gawk. 88 89 ds220# opkg install bash gawk 90 ds220# cd /usr/bin 91 ds220# mv bash bash.syno 92 ds220# ln -s /opt/bin/bash . 93 94In order to have Configure find the required libraries 95 96 ds220# cd /opt/lib 97 ds220# ln -s libcrypt.so.? libcrypt.so 98 ds220# ln -s libdl.so.? libdl.so 99 ds220# ln -s libgdbm.so.? libgdbm.so 100 ds220# ln -s libgdbm_compat.so.? libgdbm_compat.so 101 ds220# ln -s libm.so.? libm.so 102 ds220# ln -s libpthread.so.? libpthread.so 103 ds220# ln -s libutil.so.? libutil.so 104 105=head3 DSM 6 106 107Using iPkg has been deprecated on DSM 6, but an alternative is available 108for DSM 6: entware/opkg. For instructions on how to use that, please read 109L<Install Entware-ng on Synology NAS|https://github.com/Entware-ng/Entware-ng/wiki/Install-on-Synology-NAS> 110 111That sadly does not (yet) work on QorIQ. At the moment of writing, the 112supported architectures are armv5, armv7, mipsel, wl500g, x86_32, and x86_64. 113Check L<here|https://pkg.entware.net/binaries/> for supported platforms. 114 115Entware-ng comes with a precompiled 5.24.1 (June 2017) that allowes 116building shared XS code. Note that this installation does B<not> use 117a site_perl folder. The available C<cpan> works. If all required 118development packages are installed too, also for XS. 119 120=head3 DSM 5 121 122As DSM is a trimmed-down Linux system, it lacks many of the tools and 123libraries commonly found on Linux. The basic tools like sh, cp, rm, 124etc. are implemented using 125L<BusyBox|https://en.wikipedia.org/wiki/BusyBox>. 126 127=over 4 128 129=item * 130 131Using your favourite browser open the DSM management page and start 132the Package Center. 133 134=item * 135 136If you want to smoke test Perl, install C<Perl>. 137 138=item * 139 140In Settings, add the following Package Sources: 141 142 https://www.cphub.net 143 http://packages.quadrat4.de 144 145As these two are both discontinued, it is unlikely you will be able 146to set up a build environment on DSM 5. 147 148=item * 149 150Still in Settings, in Channel Update, select Beta Channel. 151 152=item * 153 154Press Refresh. In the left panel the item "Community" will appear. 155Click it. Select "Bootstrap Installer Beta" and install it. 156 157=item * 158 159Likewise, install "iPKGui Beta". 160 161The application window should now show an icon for iPKGui. 162 163=item * 164 165Start iPKGui. Install the packages C<make>, C<gcc> and C<coreutils>. 166 167If you want to smoke test Perl, install C<patch>. 168 169=back 170 171The next step is to add some symlinks to system libraries. For 172example, the development software expect a library C<libm.so> that 173normally is a symlink to C<libm.so.6>. Synology only provides the 174latter and not the symlink. 175 176Here the actual architecture of the Synology system matters. You have 177to find out where the gcc libraries have been installed. Look in /opt 178for a directory similar to arm-none-linux-gnueab or 179powerpc-linux-gnuspe. In the instructions below I'll use 180powerpc-linux-gnuspe as an example. 181 182=over 4 183 184=item * 185 186On the DSM management page start the Control Panel. 187 188=item * 189 190Click Terminal, and enable SSH service. 191 192=item * 193 194Close Terminal and the Control Panel. 195 196=item * 197 198Open a shell on the Synology using ssh and become root. 199 200=item * 201 202Execute the following commands: 203 204 cd /lib 205 ln -s libm.so.6 libm.so 206 ln -s libcrypt.so.1 libcrypt.so 207 ln -s libdl.so.2 libdl.so 208 cd /opt/powerpc-linux-gnuspe/lib (or 209 /opt/arm-none-linux-gnueabi/lib) 210 ln -s /lib/libdl.so.2 libdl.so 211 212=back 213 214B<WARNING:> When you perform a system software upgrade, these links 215will disappear and need to be re-established. 216 217=head2 Compiling Perl 5 218 219When the build environment has been set up, building and testing Perl 220is straightforward. The only thing you need to do is download the 221sources as usual, and add a file Policy.sh as follows: 222 223 # Administrivia. 224 perladmin="your.email@goes.here" 225 226 # Install Perl in a tree in /opt/perl instead of /opt/bin. 227 prefix=/opt/perl 228 229 # Select the compiler. Note that there is no 'cc' alias or link 230 # on older DSM versions 231 cc=gcc 232 awk=/opt/bin/gawk 233 234 # Build flags. Optional 235 ccflags="-DDEBUGGING" 236 237 # Library and include paths. 238 locincpth="/opt/include" 239 loclibpth="/opt/lib /usr/local/lib /usr/lib" 240 libpth="/opt/lib /usr/local/lib /usr/lib" 241 242You may want to create the destination directory and give it the right 243permissions before installing, thus eliminating the need to build Perl 244as a super user. 245 246In the directory where you unpacked the sources, issue the familiar 247commands: 248 249 $ bash ./Configure -Dusedevel -Duseshrplib -Duse64bitall -des 250 $ make -j2 251 $ env TEST_JOBS=2 make test_harness 252 $ make install 253 254=head2 Known problems 255 256=head3 Configure 257 258The GNU C-compiler might spit out unexpected stuff under -v, which 259causes the analysis of cppsymbols to fail because of unmatched quotes. 260 261You'll note if config.sh fails with a syntax error. 262 263=head3 Build 264 265=over 4 266 267=item Error message "No error definitions found". 268 269This error is generated when it is not possible to find the local 270definitions for error codes, due to the uncommon structure of the 271Synology file system. 272 273This error was fixed in the Perl development git for version 5.19, 274commit 7a8f1212e5482613c8a5b0402528e3105b26ff24. 275 276=back 277 278=head3 Failing tests 279 280=over 4 281 282=item F<ext/DynaLoader/t/DynaLoader.t> 283 284One subtest fails due to the uncommon structure of the Synology file 285system. The file F</lib/glibc.so> is missing. 286 287B<WARNING:> Do not symlink F</lib/glibc.so.6> to F</lib/glibc.so> or 288some system components will start to fail. 289 290=back 291 292=head2 Smoke testing Perl 293 294If building completes successfully, you can set up smoke testing as 295described in the Test::Smoke documentation. 296 297For smoke testing you need a running Perl. You can either install the 298Synology supplied package for Perl 5.8.6, or build and install your 299own, much more recent version. 300 301Note that I could not run successful smokes when initiated by the 302Synology Task Scheduler. I resorted to initiating the smokes via a 303cron job run on another system, using ssh: 304 305 ssh nas1 wrk/Test-Smoke/smoke/smokecurrent.sh 306 307=head3 Local patches 308 309When local patches are applied with smoke testing, the test driver 310will automatically request regeneration of certain tables after the 311patches are applied. The Synology supplied Perl 5.8.6 (at least on the 312DS413) B<is NOT capable> of generating these tables. It will generate 313opcodes with bogus values, causing the build to fail. 314 315You can prevent regeneration by adding the setting 316 317 'flags' => 0, 318 319to the smoke config, or by adding another patch that inserts 320 321 exit 0 if $] == 5.008006; 322 323in the beginning of the C<regen.pl> program. 324 325=head2 Adding libraries 326 327The above procedure describes a basic environment and hence results in 328a basic Perl. If you want to add additional libraries to Perl, you may 329need some extra settings. 330 331For example, the basic Perl does not have any of the DB libraries (db, 332dbm, ndbm, gdsm). You can add these using iPKGui, however, you need to 333set environment variable LD_LIBRARY_PATH to the appropriate value: 334 335 LD_LIBRARY_PATH=/lib:/opt/lib 336 export LD_LIBRARY_PATH 337 338This setting needs to be in effect while Perl is built, but also when 339the programs are run. 340 341=head1 REVISION 342 343July 2022, for DSM 5.1.5022 and DSM 6.1-15101-4, and DSM-7.1-42661-3. 344 345=head1 AUTHOR 346 347Johan Vromans <jvromans@squirrel.nl> 348H. Merijn Brand <cpan@tux.freedom.nl> 349 350=cut 351