Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a file content into a Makefile variable without losing carriage-returns

Tags:

makefile

According to GNU manual:

It converts each newline or carriage-return / newline pair to a single space. It also removes the trailing (carriage-return and) newline, if it's the last thing in the result.

But it makes more difficult to use awk without carriage-returns:

FILE = $(shell cat $(PATH))
TEXT = $(shell echo "$(FILE)" | awk '/Text/ {print $$3}')

So my question is whether there is a way to keep carriage-returns when assign a file content to a Makefile variable, or any smart workarounds?

like image 807
Zhang Fan Avatar asked Nov 02 '22 12:11

Zhang Fan


1 Answers

No, you cannot preserve newlines in the results of the $(shell ...) function.

You can of course change your makefile like this:

FILE = $(PATH)
TEXT = $(shell cat $(FILE) | awk '/Text/ {print $$3}')

Or, to avoid UUOC,

TEXT = $(shell awk '/Text/ {print $$3}' < $(FILE))
like image 84
MadScientist Avatar answered Jan 04 '23 14:01

MadScientist