'use strict';
const BinBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

bin.run(['--help'], err => {
	if (err) {
		log.warn(err.message);
		log.warn('zopflipng pre-build test failed');
		log.info('compiling from source');

		const builder = new BinBuild()
			.src('https://github.com/google/zopfli/archive/a29e46ba9f268ab273903558dcb7ac13b9fe8e29.zip')
			.cmd(`mkdir -p ${bin.dest()}`)
			.cmd(`make zopflipng && mv ./zopflipng ${bin.path()}`);

		return builder.run(err => {
			if (err) {
				log.error(err.stack);
				return;
			}

			log.success('zopflipng built successfully');
		});
	}

	log.success('zopflipng pre-build test passed successfully');
});

@@ -256,16 +256,108 @@
 rce');%0A%0A
+%09%09let makeBin = 'make';%0A%0A%09%09if (process.platform === 'freebsd') %7B%0A%09%09%09makeBin = 'gmake';%0A%09%09%7D%0A%0A
 %09%09const 
@@ -521,20 +521,26 @@
 %09%09.cmd(%60
+$%7B
 make
+Bin%7D
  zopflip

Use `gmake` on FreeBSD