Linux HOWTOs

About | Home | Search


HOWTO: flex
Description: Fast lexical analyzer generator
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# flex 2.6.4
# ===========
# Slackware 13.37, 14.0: flex 2.5.35
# Slackware 14.1: flex 2.5.37
# Slackware 14.2: flex 2.6.0

# The latest version (released in 1996) of the original flex is available at:
# ftp://ftp.ee.lbl.gov/
# Then there was the Sourceforge "project":
# https://sourceforge.net/projects/flex/

# Prerequisites:
# gettext
# Bison
# help2man (optional; to generate the man page)
# m4
# indent

# I use --disable-nls below because I am good with the default, if you need
# translations, leave that off

# If you prefer, the download is also available as tar.lz
# (http://www.nongnu.org/lzip/) on the releases page:
# https://github.com/westes/flex/releases

# Get the source
cd
test -f installed/flex-2.6.4.tar.gz && mv installed/flex-2.6.4.tar.gz .
test ! -f flex-2.6.4.tar.gz &&
 wget --no-check-certificate \
https://github.com/westes/flex/files/981163/flex-2.6.4.tar.gz

# Verify tarball w/ sha1sum:
# (this came from my gpg-verified tarball)
echo "fafece095a0d9890ebd618adb1f242d8908076e1  flex-2.6.4.tar.gz" | \
sha1sum -c

# Verify tarball w/ sha256sum:
# (this also came from my gpg-verified tarball)
echo "e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995  f\
lex-2.6.4.tar.gz" | sha256sum -c

# Verify tarball w/ gpg:
( gpg --list-keys 64885307 > /dev/null 2>&1 || gpg --recv-keys 64885307 ) &&
 wget -nc --no-check-certificate \
https://github.com/westes/flex/releases/download/v2.6.4/\
flex-2.6.4.tar.gz.sig &&
  gpg --verify flex-2.6.4.tar.gz.sig && rm flex-2.6.4.tar.gz.sig

# Extract the source
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "flex-*" -exec rm -r {} \;
tar xzvf ~/flex-2.6.4.tar.gz
cd flex-2.6.4
test $UID = 0 && chown -R root:root .

# Configure the build - 64-bit
test $(uname -m) = 'x86_64' &&
./configure --prefix=/usr --docdir=/usr/doc/flex --infodir=/usr/info \
--libdir=/usr/lib64 --mandir=/usr/man --disable-nls

# Configure the build - anything else
test $(uname -m) != 'x86_64' &&
./configure --prefix=/usr --docdir=/usr/doc/flex --infodir=/usr/info\
 --mandir=/usr/man --disable-nls

# Build it
make

# Become root to install it
su

# Remove the Slackware package, if there is one
test -x /sbin/removepkg && /sbin/removepkg flex

# Install it
make install
ldconfig

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# Create a little bash script that'll take care of things that look for
# 'lex' instead of 'flex':
echo '#!/bin/sh' > /usr/bin/lex
echo 'flex -l $*' >> /usr/bin/lex
chmod 755 /usr/bin/lex

# Become yourself again
exit

# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/flex-*.tar.*
mv flex-2.6.4.tar.gz installed/


# If you ever want to uninstall flex, this should do it:
cd
su
test -d src/flex-* && ( cd src/flex-* ; make uninstall )
( cd /usr/bin ; rm -f flex flex++ )
test -d /usr/doc/flex && rm -r /usr/doc/flex
( cd /usr/lib ; libfl.a libfl_pic.a )
test -d /usr/lib64 && ( cd /usr/lib64 ; libfl.a libfl_pic.a )
find /usr/share/locale -type f -name "flex.mo" -exec rm {} \;
rm -f /usr/include/FlexLexer.h /usr/info/flex.info /usr/man/man1/flex.1
test -L /usr/bin/lex && rm -f /usr/bin/lex
test -f /usr/bin/lex &&
 test "$(file -b /usr/bin/lex)" = \
"POSIX shell script, ASCII text executable" &&
  rm -f /usr/bin/lex
exit
find ~/src -maxdepth 1 -type d -name "flex-*" -exec rm -r {} \;
rm -f ~/installed/flex-*.tar.*

Back to the list


Last updated: Wed, 29 Apr 2020 22:04:50 -0400
Jason Englander <jason at englanders dot us>