How to check in Makefile if some program is running ?
I write my university lections in LyX and draw diagrams in LibreOffice Draw. So, one day I decided to write a Makefile to covert a batch of odg-diagrams to pdf. You may ask me: what is the problem? Well... you can convert odg to pdf in may ways:
- libreoffice --convert-to pdf
I choose an easiest one:
$ libreoffice --headless --convert-to pdf "file.odg"
It works fine until... there is no other LO instances. There is a workaround to fix it, but I decide just to check in Makefile, if any LO instance is running now, and exit if any.
My resulting Makefile looks like:
SOURCES = $(wildcard *.odg) TARGETS = $(SOURCES:.odg=.pdf) LIBREOFFICE_PID = $(shell pidof soffice.bin) %.pdf:%.odg ifneq ("", "$(LIBREOFFICE_PID)") $(error "Please, close all LibreOffice instances ($(LIBREOFFICE_PID)) to continue") endif libreoffice --headless --convert-to pdf "$^" all: $(TARGETS) clean: rm -f $(TARGETS)