abergmeier
abergmeier

Reputation: 14042

Generate pkg-config out of Makefile

For a project, which historically uses make I would now like to generate a pkg-config file. However I cannot seem to prevent the substitution of the variables

mylib.pc:
    echo 'prefix='$(PREFIX) > bzip2.pc
    echo "exec_prefix=\${prefix}" >> mylib.pc
    echo 'libdir=\${prefix}/lib'  >> mylib.pc

install: mylib.pc

Afterwards I have a mylib.pc with expanded variables, which is not what I want. So how does one generate a pkg-config out of a Makefile or how do I prevent variable substitution?

Upvotes: 1

Views: 1824

Answers (2)

Jérôme Pouiller
Jérôme Pouiller

Reputation: 10177

You can use define to define a variable while keeping new lines and use file to write a file.

define PKG_CONFIG_TEMPLATE
prefix=$(PREFIX)
exec_prefix=$${prefix}
includedir=$${prefix}/include
libdir=$${exec_prefix}/lib

Name: MyLib
Description: MyLib description
Version: 1.0
Cflags: -I$${includedir}
Libs: -L$${libdir}
endef

mylib.pc:
    $(file > $@,$(PKG_CONFIG_TEMPLATE))

Upvotes: 0

Beta
Beta

Reputation: 99084

This will produce what I think you want:

mylib.pc:
    echo 'prefix='$(PREFIX)                                                    
    echo 'exec_prefix=$${prefix}' >> mylib.pc
    echo 'libdir=$${prefix}/lib' >> mylib.pc

Upvotes: 3

Related Questions