Tuesday 30 July 2019

Apache Ant Patterns

Apache Ant is used for Java build files. It uses so called "Ant-style" wildcards which have been accepted and are now used by many other tools.

Ant-style wildcards:


  • Matches one character (any character except path separators)
  • used to match file names
  • matches one level
  • any character except path separators

  • Matches zero or more characters (not including path separators)
  • used to match file names
  • matches one level
  • any character except path separators


  • Matches zero or more path segments (directory tree) 
  • used for folder-names matching
  • includes/matches path separators (slash, /) 
  • matches multiple levels
  • src/**/*.cs will find all cs files in any sub-directory of src

If we have the following tree:


Ant pattern which filters all .txt files in any subdirectory of a dir2 directory would be:


When ** is used as the name of a directory in the pattern, it matches zero or more directories.


Directory-based Tasks
How do I use Nant/Ant naming patterns?
Pattern matching guide
Learning Ant path style

Monday 29 July 2019

How to play .mp4 videos on Ubuntu

Install the following packages (and accept EULAs):

$ sudo apt-get update
$ sudo apt install libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
$ sudo dpkg-reconfigure libdvd-pkg
$ sudo apt install ubuntu-restricted-extras

(Tested on Ubuntu 18.04)

Wednesday 17 July 2019

Introduction to Makefile

make utility is a build automation tool typically used to read the list of code source files and compilation, linking and building rules in order to create executables and/or libraries. As it's capable of running an arbitrary shell commands and applications, it is possible to use it as a general automation tool. 

make reads Makefile in order to find out which files it should operate on and which commands should be run.

Makefile consists of a list of so called targets (or recipies) which come in form:

target: dependency1 dependency2 ...

target can be:
  • name of the output file which is usually a binary or object file
  • name of the arbitrary action e.g. clean, linter etc. 
  • can be:
    • names of files which are used as inputs in creating the target file
    • names of previously defined targets 
  • dependencies are optional, they can be omitted in which case the command needs to be in the next line
  • must be written in its own line; if long, it can be break into new line with backslash character
  • each command line needs to start with TAB character
  • commands are optional in which case the list of dependencies goes in the same line as target label unless backslash is used to break dependencies list into multiple lines

If there are no commands but only dependencies:

target: dependency1 dependency2 ...

If we want to list each dependency in a separate line we can use backslash character to break lines (note that there is a backslash in each line apart the last!)

target: \
    dependency1 \

If there are no dependencies but only commands:


If target is the name of an arbitrary action it is called phony and we need to explicitly tell Make that it's not associated with some file:

.PHONY: action

To test the Makefile target syntax, run:

make my_target --dry-run

To run the target:

make my_target

make commands


They MUST NOT be indented with TAB characters as (almost) all lines with TAB characters as the first character on the line in a makefile are passed to the shell (/bin/sh). The shell doesn't know anything about  make commands. make commands can be indented with a set of SPACE characters but this might be misleading as recipies is what MUST be indented with TABs.


They must be indented with TAB character in order to be passed to shell.


Targets are labels that allow make to execute a group of commands together.


   @echo target1 is executing
   @echo target2 is executing

We can now run make as:

$ make target1


$ make target2

Minimal (but working) example of Makefile:

@echo Building and running Docker image...
docker build -t cpp-demo . && docker run --rm --name cpp-demo cpp-demo

To run it:

$ make docker-run 

Conditional Execution

Use ifeq-endif or ifeq-else-endif blocks.


VAR1= test


ifeq($(VAR1), $(VAR2))

Makefile ifeq: when are they evaluated?

Variable comparison

ifeq ($(TEST),ON)
    @echo PASSED
    @echo FAILED

To check if variable is empty:

ifeq ($(TEST),)
TEST := $(something else)

Makefile set if variable is empty


Using Makefile in Docker projects