Hopefully the list of small code samples will help other people that cope with the same problems I ran into (before writing these).
All snippets have been tested on Ubuntu unless specified otherwise.
This is a small set of scripts I wrote to easily compile a (C)? program using various compilers and versions.
For each version it creates a Docker image based on the Ubuntu 18.04 image, to try and make the environment as similar as possible.
Oh, and it was easier to implement that way.
Please use an up-to-date version of bash as some used functionality is relatively recent.
To specify which compilers to use and what versions,
there is a compilers.conf file where every odd line specifies the compiler and the even line afterwards specifies the versions, delimited by a space.
Note that the script (ab)uses aptitudes naming convention of "<compiler> - <version>". If this is not the case, the vanilla script doesn't work.
tl;dr: To make a Docker image for each version specified in the conf file, simply run the script ./build.sh
This may take a while, but should make an appropriate name for each image (the tag is compiler:version). If this name is already in use, it will override the current image.
If a different version of Ubuntu is required, please change the version name and the repositories inside the top bit of build.sh.
tl;dr: To compile, run ./build.sh <path_to_binary>
This will create a new directory inside the current directory, called after the name of the file to compile. Inside this directory, more subdirectories will be made for each compiler+version. Inside these directories, 3 files will be generated, corresponding to the 3 optimisation modes (hardcoded a -O<num> loop). Furthermore, the -s option is given to the script to create a stripped binary, but this is obviously easily removed. Currently it only supports single files to be compiled, but feel free to edit the script or to ping me if you need the functionality of the script. This script automatically removes the containers after it compiled, but will not remove the images.
tl;dr: When you are done and want to remove all the images, ./remove.sh can be run.
This will remove all the Docker images that correspond to the naming convention (compiler:version).
It does not track the Docker images being made but simply reads out the conf file. Thus, it will not remove the image if the tag has been manually changed and will delete images with a name corresponding to a combination inside the conf file.
Note for Mac users: The (standard) mac version of Docker is currently still leaking memory. Creating this many images and containers may pose a problem to your hard disk until you remove the main file (and hence remove all images and containers).
This main file is usually here: ~/Library/Containers/com.docker.docker/Data/vms/0/Docker.qcow2