Quantcast
Channel: OS detecting makefile - Stack Overflow
Viewing all articles
Browse latest Browse all 15

Answer by Patrick B Warren for OS detecting makefile

$
0
0

I had a case where I had to detect the difference between two versions of Fedora, to tweak the command-line options for inkscape:
- in Fedora 31, the default inkscape is 1.0beta which uses --export-file
- in Fedora < 31, the default inkscape is 0.92 which uses --export-pdf

My Makefile contains the following

# set VERSION_ID from /etc/os-release$(eval $(shell grep VERSION_ID /etc/os-release))# select the inkscape export syntaxifeq ($(VERSION_ID),31)EXPORT = export-fileelseEXPORT = export-pdfendif# rule to convert inkscape SVG (drawing) to PDF%.pdf : %.svg    inkscape --export-area-drawing $< --$(EXPORT)=$@

This works because /etc/os-release contains a line

VERSION_ID=<value>

so the shell command in the Makefile returns the string VERSION_ID=<value>, then the eval command acts on this to set the Makefile variable VERSION_ID.This can obviously be tweaked for other OS's depending how the metadata is stored. Note that in Fedora there is not a default environment variable that gives the OS version, otherwise I would have used that!


Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>