[Makefile] Concetenate and Minify CSS via sed and tr Command


Concatenate and Minify CSS via sed and tr command in Makefile.

SOURCE_CSS_FILES=$(filter-out %.min.css, $(wildcard *.css))
MINIFIED_CSS=app.min.css

minify: concat
      @# remove css comments
      sed -r ':a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba' -i $(MINIFIED_CSS)
      @# remove leading spaces and tabs
      sed 's/^\s*//' -i $(MINIFIED_CSS)
      @# remove trailing spaces, tabs, and newline
      sed 's/\s*$$//' -i $(MINIFIED_CSS)
      @# remove newline
      tr --delete '\n' < $(MINIFIED_CSS) > tmp.css
      mv tmp.css $(MINIFIED_CSS)

concat:
      cat $(SOURCE_CSS_FILES) > $(MINIFIED_CSS)

Tested on Ubuntu Linux 15.10.


References:

[1]GNU make: Text Functions
[2]GNU make: Wildcard Function
[3]

sed remove comments c

sed - Remove multi-line comments - Stack Overflow

[4]unix - how to remove leading whitespace from each line in a file? - Stack Overflow
[5]bash - How to use sed in a Makefile - Stack Overflow
[6]unix - How can I replace a newline (n) using sed? - Stack Overflow
[7]

makefile instead of grunt

What's in a Build Tool? (lihaoyi.com) (HN discussions)

ocaml-9p/Makefile at master · mirage/ocaml-9p · GitHub

rappel/Makefile at master · yrp604/rappel · GitHub

In defense of Unix (leancrew.com) (HN discussions)

[8]makefile check if symlink exists
[9]

makefile concatenate files

javascript - Makefile to combine js files and make a compressed version - Stack Overflow

build - Is there a way to exclude certain source files or folders from a makefile? - Stack Overflow

[10]concatenate and minify css via make/sed/tr · siongui/pali@188d66f · GitHub
[11]tr replace file