#!/bin/bash

####
## THIS SIMPLE SCRIPT IS CALLED FROM dar_static_builder_with_musl_voidlinux.bash
## TO FIX BUG IN LIBCURL PROVIDED PKG-CONFIG CONFIGURATION FILE
## WHICH IS BROKEN FOR STATICAL LINKING (MISSING DEPENDENT LIBRARY TO ADD FOR
## THE LINKING TO SUCCEED).

## This scripts expects the libcurl library to be installed in /usr/local and
## built with the minimal options set from the dar_static_builder_with_musl_voidlinux.bash
## script

curlpkg=/usr/local/lib/pkgconfig/libcurl.pc

# -lpsl -lidn2 -lunistring

libs_line=$(grep -E '^Libs:' /usr/local/lib/pkgconfig/libcurl.pc)
is_fixed=$(echo "$libs_lline" | grep -- '-lidn2' | wc -l)

if [ $is_fixed -eq 0 ] ; then
   cp "$curlpkg" "${curlpkg}.old"
   sed -r -e 's/(^Libs:.*)/\1 -lidn2 -lunistring/' < "${curlpkg}.old" > "${curlpkg}"
   rm "${curlpkg}.old"
fi
