The mini pre processor parses files and resolves C-style #include and #define macros
Crystal Makefile Shell CSS JavaScript

README.md

mpp, a mini preprocessor Build Status

This mini preprocessor parses files and resolves #include and #define macros similar to how cpp(1) does.

Get it

Homebrew

$ brew tap foca/mpp
$ brew install mpp

Manually download a binary

Download the latest stable binary from our Releases page.

Compile from source

You will need the Crystal compiler, and a ruby interpreter to generate the man pages.

$ git clone https://github.com/foca/mpp && cd mpp
$ ./configure --prefix=/usr/local
$ make
$ make install

Example

Given the following two CSS files:

/* app.css */

#include "other.css"

#define $margin 15px

.something-other {
  margin: $margin;
}
/* other.css */

.something {
  padding: 0;
}

Running mpp app.css will result in this:

.something {
  padding: 0;
}



.something-other {
  margin: 15px;
}

See the example directory for a more interesting example.

Load Paths

By default, mpp will look for file paths relative to the working directory. In order to specify the paths to search, you should use the -I command line flag:

$ mpp example/app.css
Can't find file other.css in /current/directory

$ mpp -Iexample example/app.css
.something {
  padding: 0;
}
...

Each invocation of -I adds a new directory to the search path:

$ mpp -Iexample -Ivendor example/app.css

Files will be searched relative to the directories in the load path in order. So if your search path is [./example, ./], mpp will first try to open the file ./example/app.css, and then ./app.css. If neither is a file, then it will exit with an error status.

Make Dependencies

By passing -M (or --make) mpp will generate output suitable for a Makefile to define the dependencies between files, according to the #include rules in each processed file.

For example:

$ mpp -Iexample -M example/app.css
example/app.css: example/other.css
        @touch $@

$

You can add this to your Makefile in order to let make handle this on its own:

.deps.mk: $(ASSETS)
        @mpp -M $^ > $@

-include .deps.mk

Where $(ASSETS) is the list of all the assets that you're compiling. For example, in one of my projects I have it set to

ASSETS = $(shell find assets/ -type f)

This ensures that whenever a new asset is added / modified, .deps.mk is rebuilt, and thus the dependencies are kept up-to-date.

License

Licensed under the MIT license. See the attached LICENSE file for details.