From: Leandro Lucarella Date: Fri, 18 Sep 2009 18:13:18 +0000 (-0300) Subject: Add support for easy geneation of pkg-config files X-Git-Url: https://git.llucax.com/software/makeit.git/commitdiff_plain/2825d7cb9f58a30d0280ff3bea5dfe4c6faa6ddf?ds=inline Add support for easy geneation of pkg-config files A replace function is added to ease the generation of a .pc file based on a template. Default rules to build and install the .pc files are added too. otherproj now provides a pkg-config file and lib2 uses some otherproj CFLAGS as an example. --- diff --git a/Lib.mak b/Lib.mak index 526fb17..6a6c9f9 100644 --- a/Lib.mak +++ b/Lib.mak @@ -169,6 +169,20 @@ install_file = $(call exec,install -m $(if $1,$1,0644) $(if $2,$2,-D) \ # Will produce something like "a -- b --" varcat = $(foreach v,$1,$($2$v)$(if $3,$3, ~)) +# Replace variables with specified values in a template file. The first +# argument is a list of make variables names which will be replaced in the +# target file. The strings @VARNAME@ in the template file will be replaced +# with the value of the make $(VARNAME) variable and the result will be stored +# in the target file. The second (optional) argument is a prefix to add to the +# make variables names, so if the prefix is PREFIX_ and @VARNAME@ is found in +# the template file, it will be replaced by the value of the make variable +# $(PREFIX_VARNAME). The third and fourth arguments are the source file and +# the destination file (both optional, $< and $@ are used if omitted). The +# fifth (optional) argument are options to pass to the substitute sed command +# (for example, use "g" if you want to do multiple substitutions per line). +replace = $(call exec,sed '$(foreach v,$1,s|@$v@|$($2$v)|$5;)' $(if $3,$3,$<) \ + > $(if $4,$4,$@)) + # Create a symbolic link to the project under the $(INCLUDE_DIR). The first # argument is the name of symlink to create. The link is only created if it # doesn't already exist. @@ -254,6 +268,10 @@ $L/%.so: override CXXFLAGS += -fPIC $L/%.so: $G/link-o-flags $(call link,-shared) +# Create pkg-config files using a template +$L/%.pc: + $(call replace,$(PC_VARS),$*-PC-) + # Install binary programs $I/bin/%: $(call install_file,0755) @@ -262,6 +280,10 @@ $I/bin/%: $I/sbin/%: $(call install_file,0755) +# Install pkg-config specification files +$I/lib/pkgconfig/%: + $(call install_file) + # Install libraries $I/lib/%: $(call install_file) diff --git a/lib2/Build.mak b/lib2/Build.mak index ba7d510..4f201de 100644 --- a/lib2/Build.mak +++ b/lib2/Build.mak @@ -1,5 +1,6 @@ # Build the shared library +$L/liblib2.so: CXXFLAGS += $(otherproj-PC-CFLAGS) $L/liblib2.so: $(call find_objects,cpp) $L/liblib1.so $L/libotherproj.so # Nice shortcut target diff --git a/subproj/Build.mak b/subproj/Build.mak index 9552ae0..b391b79 100644 --- a/subproj/Build.mak +++ b/subproj/Build.mak @@ -1,19 +1,33 @@ -# Create the include directory symlink -setup_include_dir__ := $(call symlink_include_dir,otherproj) - -# Build the shared library -$L/libotherproj.so: LINKER := $(CC) -$L/libotherproj.so: $(call find_objects,c) +# Symbolic target to add to all +.PHONY: otherproj all += otherproj -# Nice shortcut target -.PHONY: otherproj -otherproj: $L/libotherproj.so +# pkg-config specification file +otherproj-PC-PREFIX := $(prefix) +otherproj-PC-NAME := otherproj +otherproj-PC-DESC := Some other project +otherproj-PC-URL := http://www.otherproj.example.com/ +otherproj-PC-VERSION := 1.0 +otherproj-PC-LIBS := -lotherproject +otherproj-PC-CFLAGS := -DOTHERPROJ_DEFINE +otherproj-PC-VARS := PREFIX NAME DESC URL VERSION LIBS CFLAGS +$L/otherproj.pc: PC_VARS := $(otherproj-PC-VARS) +$L/otherproj.pc: $C/otherproj.pc.in $L/otherproj.pc-flags +# trigger a rebuild when flags change +setup_flags_files__ := $(call gen_rebuild_flags,$L/otherproj.pc-flags,\ + $(call varcat,$(otherproj-PC-VARS),otherproj-PC-)) +# install +$I/lib/pkgconfig/otherproj.pc: $L/otherproj.pc +install += $I/lib/pkgconfig/otherproj.pc +otherproj: $L/otherproj.pc -# Install the shared library +# Shared library +$L/libotherproj.so: LINKER := $(CC) +$L/libotherproj.so: $(call find_objects,c) $I/lib/libotherproj.so: $L/libotherproj.so install += $I/lib/libotherproj.so +otherproj: $L/libotherproj.so # Install the library's headers $I/include/otherproj/%.h: $C/%.h @@ -21,3 +35,6 @@ $I/include/otherproj/%.h: $C/%.h # XXX: we can't use += here, call will be resolved lazily if we do install := $(install) $(call find_headers,h,$I/include/otherproj) +# Create the include directory symlink and pkg-config flags file +setup_include_dir__ := $(call symlink_include_dir,otherproj) + diff --git a/subproj/otherproj.pc.in b/subproj/otherproj.pc.in new file mode 100644 index 0000000..dd4c457 --- /dev/null +++ b/subproj/otherproj.pc.in @@ -0,0 +1,13 @@ + +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @NAME@ +Description: @DESC@ +URL: @URL@ +Version: @VERSION@ +Libs: -L${libdir} @LIBS@ +Cflags: -I${includedir} @CFLAGS@ +