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.