Alexander Nasonov's shared items

Thursday, March 15, 2007

I thought I found a bug in OpenBSD ...

... but someone else found that bug a bit earlier. I spent a funny evening tracking it down to the same lines as in the fix.

Sunday, February 25, 2007

How to run print/acroread7 on FreeBSD 6.2

This instruction explains how to install and run print/acroread7 on FreeBSD 6.2 using pkgsrc. Before you start, please check that it's still broken. I hope it'll be fixed soon after my post and you would only need to follow configuration of /compat/linux.

  1. Go to emulators/suse100_base and suppress an execution of /dev/MAKEDEV - this file doesn't exist (/dev is devfs mount point on FreeBSD 6.2)
  2. % cvs diff -u Makefile
    Index: Makefile
    ===================================================================
    RCS file: /cvsroot/pkgsrc/emulators/suse100_base/Makefile,v
    retrieving revision 1.7
    diff -u -r1.7 Makefile
    --- Makefile    22 Feb 2007 19:26:27 -0000      1.7
    +++ Makefile    25 Feb 2007 18:38:10 -0000
    @@ -53,8 +53,8 @@
              ${INSTALL_SCRIPT} $$FILE ${PREFIX}/sbin/`basename $$FILE .sh`; \
            done
            ${INSTALL_DATA_DIR} ${EMULDIR}/dev
    -       ${INSTALL_DATA} /dev/MAKEDEV ${EMULDIR}/dev
    -       cd ${EMULDIR}/dev && ${SH} ./MAKEDEV  std audio
    +#      ${INSTALL_DATA} /dev/MAKEDEV ${EMULDIR}/dev
    +#      cd ${EMULDIR}/dev && ${SH} ./MAKEDEV  std audio
            cd ${EMULDIR}/dev && ${LN} -fs sound dsp
            @${CP} ${PKGDIR}/PLIST ${PLIST_SRC}
            ${RPM2PKG} ${RPM2PKGARGS}
  3. Go to print/acroread7 and patch Makefile.
  4. % cvs diff -u Makefile
    Index: Makefile
    ===================================================================
    RCS file: /cvsroot/pkgsrc/print/acroread7/Makefile,v
    retrieving revision 1.17
    diff -u -r1.17 Makefile
    --- Makefile    11 Jan 2007 11:52:17 -0000      1.17
    +++ Makefile    25 Feb 2007 19:29:36 -0000
    @@ -32,7 +32,7 @@
     # Default (overridden below)
     PLATFORM=      unknown
     
    -.if ${OPSYS} == "NetBSD" || ${OPSYS} == "DragonFly"
    +.if ${OPSYS} == "NetBSD" || ${OPSYS} == "DragonFly" || ${OPSYS} == "FreeBSD"
     . if (${MACHINE_ARCH} == "i386")
     DEPENDS+=      suse_gtk2>=10.0:../../emulators/${SUSE_DIR_PREFIX}_gtk2
     DEPENDS+=      suse_libcups>=10.0:../../emulators/${SUSE_DIR_PREFIX}_libcups
  5. Run bmake with properly set $BRANDELF. For some reason, this variable is not set when building suse100_base and it would break an installation of that package.
  6. % env BRANDELF=brandelf bmake
  7. Run
  8. % sed -i '' -e 's/\(NetBSD | DragonFly\)/\1 | FreeBSD/' work/AdobeReader/INSTALL
  9. Install acroread7
  10. % bmake install
  11. Run as root
  12. # sed -i '' -e 's/\(NetBSD | DragonFly\)/\1 | FreeBSD/' /usr/pkg/bin/acroread7
  13. Set LD_LIBRARY_PATH to
  14. LD_LIBRARY_PATH=/usr/pkg/emul/linux/usr/lib/:/usr/pkg/emul/linux/opt/gnome/lib:/usr/pkg/Acrobat7/Reader/intellinux/lib

When I completed these steps, I was able to run /usr/pkg/bin/acroread7 but later I removed packages installed from ports and I couldn't run the program anymore. To fix this, I replaced FreeBSD linux compatibility directory with pkgsrc linux emulator and regenerated gdk-pixbuf.loaders:

# mv /compat/linux /compat/linux.freebsd
# ln -s /usr/pkg/emul/linux /compat/linux
# /usr/pkg/emul/linux/opt/gnome/bin/gdk-pixbuf-query-loaders > /usr/pkg/emul/linux/etc/opt/gnome/gtk-2.0/gdk-pixbuf.loaders

This method proves that suse100 linux emulator works on FreeBSD but since it could "interfere" in a bad way with FreeBSD update procedure I went another route:

# ln -s /usr/pkg/emul/linux/opt/gnome /compat/linux/opt/gnome
# ln -s /usr/pkg/emul/linux/etc/opt/gnome /compat/linux/etc/opt/gnome
# ln -s /usr/pkg/emul/linux/opt/gnome/lib/pango /compat/linux/usr/lib/pango

You can always find these three foreign links with the find command:

% find /compat/linux -type l | xargs file | grep pkg
/compat/linux/etc/opt/gnome:                               symbolic link to `/usr/pkg/emul/linux/etc/opt/gnome'
/compat/linux/usr/lib/pango:                               symbolic link to `/usr/pkg/emul/linux/opt/gnome/lib/pango'
/compat/linux/opt/gnome:                                   symbolic link to `/usr/pkg/emul/linux/opt/gnome'

UPDATE: I thought that /compat/linux belongs to FreeBSD base system but it has been installed from linux_base port. So I can easily remove it and use suse100_base from pkgsrc. Another cool idea is to mount a real Linux to /compat/linux as described here.

Monday, November 27, 2006

Thursday, November 23, 2006

Quote generator

I'm a happy user of mutt but I always wanted dynamically generated signature with a cool content. And I finally did it! This simple script retrieves a random quote from www.quotedb.com, formats it and finally prints most interesting part of itself:
#!/bin/sh
cat ~/.signature
/usr/pkg/bin/curl -L http://tinyurl.com/veusy           | sed -e 's/^document\.write(.//' -e 's/.);$//'             -e 's/<[^>]*>//g' -e 's/^More quotes from //'   | fmt | tee ~/.signature-quote
echo ""
echo "This quote is generated by: "
cat -n $0 | grep -e '^[ ]*[3-6]' | sed 's/^[ ]*[0-9]*[ ]*//'
A typical result looks like this:
--
Alexander Nasonov
http://nasonov.blogspot.com

Diligence is the mother of good luck.  Benjamin Franklin

This quote is generated by:
      /usr/pkg/bin/curl -L http://tinyurl.com/veusy                 | sed -e 's/^document\.write(.//' -e 's/.);$//'                   -e 's/<[^>]*>//g' -e 's/^More quotes from //'         | fmt | tee ~/.signature-quote

Monday, November 20, 2006

How to remember arguments order in ln -s command

I couldn't remember for a long time what should go first after ln -s. It came to me when I learnt about !$ (last argument of last executed command). $ touch x $ ln -s x y $ file !$ file y y: symbolic link to x

Monday, November 13, 2006

Writing A Lisp Interpreter In Haskell

I'm reading Writing A Lisp Interpreter In Haskell right now. The author refers to Boost Spirit to introduce Haskell's Parsec library. Very interesting reading.

Saturday, September 30, 2006

CLFS 1.0.0 x86 report: Compile GNU/Linux from FreeBSD

I was able to build a temporary system on my Pentium M notebook but I couldn't boot it :( Few words about my system. It runs recently compiled FreeBSD 6.2 PRERELEASE. For package management I use ports and pkgsrc. Some tools required to build CLFS are either missing in the base FreeBSD system or don't understand an option. In these cases, I either appended /usr/pkg/bin to the $PATH or provided a full path to required tool. 1. Never run make, it's different from GNU make: run /usr/pkg/bin/gmake. 2. FreeBSD's cp doesn't accept -a: use /usr/local/bin/gcp. 3. FreeBSD's install doesn't accept -D: use /usr/local/bin/ginstall. 4. tic is in /usr/pkg/bin directory. 5. Other installed pkgsrc packages that were used when I appended /usr/pkg/bin to the $PATH. Many CLFS packages compile fine. Reported only those sections that I had to complete differently. 5.3. Build Variables CLFS_HOST=i386-cross-freebsd6 CLFS_TARGET=i686-pc-linux-gnu 4.5. Setting Up the Environment Specify full path to bash and env programs in .bash_profile: cat > ~/.bash_profile << "EOF" exec /usr/bin/env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /usr/pkg/bin/bash EOF 5.7. Glibc-2.4 Make sure that gmake is in the $PATH. $ PATH=$PATH:/usr/pkg/bin BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" ../glibc-2.4/configure --prefix=/tools --host=${CLFS_TARGET} --build=${CLFS_HOST} --disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.0 --with-__thread --with-binutils=/cross-tools/bin --with-headers=/tools/include --cache-file=config.cache $ PATH=$PATH:/usr/pkg/bin /usr/pkg/bin/gmake $ PATH=$PATH:/usr/pkg/bin /usr/pkg/bin/gmake install 6.5.1. Installation of Ncurses Make sure that tic is in the $PATH when installing ncurses. $ PATH=$PATH:/usr/pkg/bin /usr/pkg/bin/gmake install 6.6.1. Installation of Bash Linking of bash 3.1 fails with "/usr/bin/ld: cannot find -ldl" error. Strange that the command is gcc -rdynamic -g -O2 -o mkbuiltins mkbuiltins.o -ldl I would assume that i686-pc-linux-gnu-gcc would be a better compiler for cross build. To get rid of this error, I appended --enable-static-link option to ./configure: $ ./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --without-bash-malloc --cache-file=config.cache --enable-static-link 6.13.1. Installation of Grep Extra packages are required. It's still an open issue which ones, though. $ PATH=$PATH:/usr/pkg/bin ./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --disable-perl-regexp $ PATH=$PATH:/usr/pkg/bin /usr/pkg/bin/gmake $ PATH=$PATH:/usr/pkg/bin /usr/pkg/bin/gmake install 6.17.1. Installation of Sed It fails to compile because ./intl/Makefile and ./po/Makefile are empty after configure stage. To fix it, remove intl and po from SUBDIRS variable in ./Makefile. 7.9.1. Installation of Udev FreeBSD's install doesn't support -D option. You should use ginstall instead: cp Makefile{,.orig} sed -e 's/^\(INSTALL = \)\/usr\/bin\/install/\1\/usr\/local\/bin\/ginstall/' Makefile.orig > Makefile Make sure that a path to ginstall is correct. 7.11. Linux-2.6.17.13 I couldn't cross-compile it. 7.12. GRUB-0.97 I skipped this step. 7.17. Populating /dev I couldn't make nodes even with gmknod. Presumaly, ext2 driver on FreeBSD doesn't support this operation. 7.18. Changing Ownership You can't run chown successfully on FreeBSD because group "root" doesn't exist. Replace it with a numeric form: chown -Rv root:0 ${CLFS} Resulting system couldn't run /sbin/init. I booted from LFS 6.2-3 LiveCD and chroot'ed to /mnt/clfs. Bash started, buildins seemed to work but when I ran /sbin/init it printed "wait_for(1099): Invalid argument." and exited from /tools/bin/bash. Most successfull command was "cat /etc/passwd" which printed the content of /etc/passwd but it also broke execution of /tools/bin/bash.

Saturday, August 26, 2006

[boost] [lexical_cast] optimization commited to HEAD

I just posted it to boost-devel list: http://lists.boost.org/Archives/boost/2006/08/109590.php Hello, I recently commited the version 1.26 of lexical_cast.hpp that optimizes many combinations of types. How it works: The lexical_cast reserves a local buffer for bool, char, wchar_t and other integral types. Then it puts a string representation of a source to the buffer. Currently, all such algorithms don't use ostream at all but it's easy to implement a generic algorithm that sets a put area of a ostream object to point to that buffer and puts a string representation to the buffer. When a source type is a pointer to char/wchar_t array or basic_string<>, its value is already a string representation of itself and a call to ostream output operator is omitted. Futher optimization is applied when a target type is either char/wchar_t or basic_string<>. In this case, std streams are not involved in a conversion at all. For all other target types, basic_istream object is contructed, its get area is set to a string representation of a source type and the operator>> is called. Optimization for the following source types is ON: bool char wchar_t other integral types char*, char const*, char[], char const[] wchar_t*, wchar_t const*, wchar_t[], wchar_t const[] std::basic_string<> Optimization for the following source types is OFF: enums float double signed char unsigned char signed char*, signed char const*, signed char[], signed char const[] unsigned char*, unsigned char const*, unsigned char[], unsigned char const[] all other types not listed in ON list Tested on VC6, VC7.1, VC8, gcc 3.4 and Borland 5.5. I couldn't run the test on Borland so I tested only that it compiles. Diff: cvs diff -r 1.24 -r 1.26 boost/lexical_cast.hpp http://tinyurl.com/qu388 Performance: Compiled with gcc 3.4.4 on FreeBSD 6.1 with -O2 flag turned on. A coversion from an int value [0, 9] to char. With Boost 1.33.1 - 2.012 s With Boost HEAD - 0.322 s, 6.24 times faster Ignore locales - 0.083 s A coversion from an int value [0, 999999] to std::string. With Boost 1.33.1 - 2.516 s With Boost HEAD - 0.844 s, 2.98 times faster Ignore locales - 0.626 s TODO - Optimization for float and double. - Make MEASURE_LEXICAL_CAST_PERFORMANCE_WITHOUT_LOCALE_OVERHEAD a public configuration parameter. - Discuss a behavior of enums with user-defined output operator.

Monday, August 21, 2006

Blogger.com doesn't like C++ template code

I found out that most code snipsets of my Overload articles posted here are not correct. For example, template struct Mixin : T { ~Mixin(); }; but it should be template<class T> struct Mixin : T { ~Mixin(); }; I'll try to correct it.