1

I am trying to get this working in Gnu Make.

i am testing out wc watch inside Makefile.

I have a file which needs to be compiled whenever a change is detected and it should run the recipe in the rule which runs 2 parallel commands. one compiles the css and the other reloads the browser.

My setup works fine if i use the builtin watch command of cssnext --watch, but i want to do it with wc

Here is the code

BIN := node_modules/.bin

all: assets/css/style.css
assets/css/style.css: sources/style.css
    @mkdir -p $(@D)
    @set -e ; \
    while true;\
    do \
        $(shell wc -c "sources/style.css")\
        $(BIN)/cssnext $^ $@& $(BIN)/instant 3000;\
        sleep 1;\
    done

When i do make all, it shows

"D:/Program Files (x86)/Git/bin/sh.exe": line 4: 343: command not found
 •∙ listening on port 3000 and waiting for changes

i am new to GNU Make, i can't get my head around it.

UPDATE : If i use bash script. create a watchfile.sh file with the following code:

#!/bin/bash
clearline="\b\033[2K\r"

command=$@

while sleep 1;
do
    # watch each character change
    eval "wc -c $command"
    echo -n -e "$clearline"
done

and then replace the code in Makefile with

    ./watchfile.sh $^
    $(BIN)/cssnext $^ $@& $(BIN)/instant 3000;

I get the following in the shell

 •∙ listening on port 3000 and waiting for changes     344 sources/style.css
    284 node_modules/.bin/cssnext
    344 sources/style.css
    263 assets/css/style.css
   1235 total

I dont know why its also looking at other files, i only specified sources/styles.css

If i make a change in the css file, it shows the character count changing. But the source/style.css file is not compiled to the target. The shell only shows the wc command lopping over again and again.

I made a small change and it was reflected in the wc shell

322 sources/style.css
284 node_modules/.bin/cssnext
322 sources/style.css
263 assets/css/style.css
1191 total

But the issue now is that its not compiling or even reloading the browser.

Another issue is that now the wc command does not stop from looping. Even after i do CTRL+C. I have to close the terminal

Also, i would prefer not using the watchfile.sh script, and rather do it in Makefile.

Ibn Saeed
  • 3,171
  • 11
  • 50
  • 59
  • 1
    Why don't you just use grunt or gulp? These look better suited to your needs. – Teyras Apr 22 '15 at 06:59
  • I dont want to use grunt or gulp, i am trying to get it to work with Makefile. – Ibn Saeed Apr 22 '15 at 07:22
  • 1
    Well, make isn't really suited for watching for changes in files and rebuilding - it just builds once and exits. Also, wc is not a reliable way of checking if something changed, although it will probably work in most cases. – Teyras Apr 22 '15 at 09:10
  • @IbnSaeed any particular reasons for not using easy2use tools such as mentioned grunt or gulp? – petrbel Apr 22 '15 at 09:17
  • i use NPM as a build tool and it works fine for all my needs. I was trying out something new with Makefile. Grunt and Gulp, i dont see the reason for them to be useful when we have NPM scripts. – Ibn Saeed Apr 22 '15 at 09:40

2 Answers2

0

If you insist on using make, just write a Makefile that compiles your CSS etc. - that's what make is for, you run make and it compiles everything that has changed.

To make compilation automatic, you can use the watch utility, which runs make periodically:

watch make

That should be fine for your needs. More info in this question: Is there a smarter alternative to "watch make"?

Community
  • 1
  • 1
Teyras
  • 1,262
  • 11
  • 22
  • i am on windows, and i do not have watch. I have wc which came with Gnuwin32 tools – Ibn Saeed Apr 22 '15 at 13:58
  • Then the simplest solution I see would be using `watchr`, which is mentioned in the question I referenced. Also, `watch` is a part of Cygwin, you might want to take a look at that, too. – Teyras Apr 22 '15 at 14:02
  • i am using msysgit. Cant switch to cygwin. – Ibn Saeed Apr 22 '15 at 16:08
0

I got it to work with Makefile + NPM. Though i needed a full Makefile solution. Anyway, it works now.

Ibn Saeed
  • 3,171
  • 11
  • 50
  • 59