For anyone who wants to know how to install SDL 2.0.5 on Ubuntu 16.04:
Currently the most recent Ubuntu packaged version of SDL is 2.0.4, so I'll be doing a source install for 2.0.5. First you'll need to grab the source package from the
SDL2 download page.
Note that additional SDL libraries have their own download page:
SDL_ttfSDL_imageSDL_mixerSDL_netThey also host source packages for dependencies:
https://www.libsdl.org/projects/For SDL_mixer, I also needed to grab the SMPEG project source from above. Ubuntu has a packaged version of the SMPEG development library (libsmpeg-dev), but it's too old.
I'm only going to install SDL2, SDL2_ttf, SDL2_image, and SDL2_mixer. If you copy the URLs from the project pages, you can download the source packages all in one go with wget (space separated, not newlines):
wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz https://www.libsdl.org/projects/smpeg/release/smpeg2-2.0.0.tar.gz
I also needed to install some development packages before compiling some of them. The needed development packages (including optional ones) were:
SDL2:
sudo apt install libesd0-dev
SDL2_image:
sudo apt install libwebp-dev libtiff-dev
SDL2_mixer:
sudo apt install libvorbis-dev libflac-dev libfluidsynth-dev libmodplug-dev
From there installing each package was basically the same. Just remember that SMPEG needs to be compiled and installed before SDL2_mixer is built.
To unpack, build, and install each package the process looks something like this (adjusting for package and folder name):
tar -zxvf SDL2-2.0.5.tar.gz
cd SDL2-2.0.5
./configure
make
sudo make install
cd ..
Of course, if you're feeling lazy, this can be automated a bit.
You can combine the ./configure, make, and sudo make install steps into one command:
./configure && make && sudo make install
The && is used to chain commands, but only if the previous command succeeded.
The tar command only accepts one archive at a time to unpack, but there is a workaround. To unpack all the archives in one command:
ls smpeg2*.tar.gz SDL2*.tar.gz | xargs -i tar -zxvf {}
The
ls command will produce a list of the relevant source packages, and then pipe the filename list into
xargs. The
xargs command is used to run a command repeatedly, for each argument passed in. This will be each of the archive file names. The
xargs -i option (equivalent to
-I{}) will replace any occurrence of
{} with each input string. What follows is the command to be run for each argument. Here we use the
tar command to unpack the archive. The
-zxvf are options to
tar, where
z means we're dealing with a gzip archive (.gz),
x means to extract,
v means verbose so each filename is printed as it is extracted, and
f means an archive file name follows.
You can apply the xargs trick to compile each package too:
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make && sudo make install"
A list of package folders is generated, piped into xargs, which then runs a sequence of commands in a new bash shell. The bash shell is used to run multiple commands at once within xargs (structured like: ls | xargs (cmd1, cmd2, cmd3)), as opposed to running just the first command with xargs, and then trying to run the remaining commands after xargs completes (structured as: (ls | xargs cmd1), cmd2, cmd3). It also has the handy benefit of restoring the current directory after each bash shell completes, so you don't need to worry about tracking the effects of
cd {}.
As each build can take a while, your sudo password might time out, causing you to be prompted to enter it again for each
sudo make install command. This of course halts the build while it waits for your input. Instead, you can split the sudo step for later so this doesn't happen:
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make"
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && sudo make install"
All together, that becomes:
# Install ubuntu dependencies
sudo apt install libwebp-dev libtiff-dev
sudo apt install libvorbis-dev libflac-dev libfluidsynth-dev libmodplug-dev
# Download source archives
wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz https://www.libsdl.org/projects/smpeg/release/smpeg2-2.0.0.tar.gz
# Unpack archives
ls smpeg2*.tar.gz SDL2*.tar.gz | xargs -i tar -zxvf {}
# Compile packages
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make"
# Install packages
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && sudo make install"