Skip to content

Commit ec6ebe8

Browse files
author
Damian Rouson
committed
Adding script to build pkg-config.
Signed-off-by: Damian Rouson <[email protected]>
1 parent d94ff75 commit ec6ebe8

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

install_prerequisites/buildpkg-config

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/bash
2+
#
3+
# buildpkg-config
4+
#
5+
# -- This script downloads and installs the GNU pkg-config file retrieval package
6+
# (https://www.gnu.org/software/pkg-config/)
7+
#
8+
# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License:
9+
# Copyright (c) 2015, Sourcery, Inc.
10+
# Copyright (c) 2015, Sourcery Institute
11+
# All rights reserved.
12+
#
13+
# Redistribution and use in source and binary forms, with or without modification,
14+
# are permitted provided that the following conditions are met:
15+
#
16+
# 1. Redistributions of source code must retain the above copyright notice, this
17+
# list of conditions and the following disclaimer.
18+
# 2. Redistributions in binary form must reproduce the above copyright notice, this
19+
# list of conditions and the following disclaimer in the documentation and/or
20+
# other materials provided with the distribution.
21+
# 3. Neither the names of the copyright holders nor the names of their contributors
22+
# may be used to endorse or promote products derived from this software without
23+
# specific prior written permission.
24+
#
25+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28+
# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
# POSSIBILITY OF SUCH DAMAGE.
35+
36+
cmd=`basename $0`
37+
usage()
38+
{
39+
echo ""
40+
echo " $cmd - Bash script for building pkg-config from source"
41+
echo ""
42+
echo " Usage (optional arguments in square brackets): "
43+
echo " $cmd <version-number> [<installation-path> <number-of-threads>]"
44+
echo " or $cmd [options] "
45+
echo ""
46+
echo " Options:"
47+
echo " --help, -h Show this help message"
48+
echo " --version, -v, -V Show this help message"
49+
echo ""
50+
echo " Example usage:"
51+
echo ""
52+
echo " $cmd default"
53+
echo " $cmd 1.16.3"
54+
echo " $cmd 1.16.3 /opt/ftp/1.16.3 4"
55+
echo " $cmd --help"
56+
echo ""
57+
echo " Note: For a list of available pkg-config versions, visit"
58+
echo " http://ftp.gnu.org/gnu/pkg-config/?C=M;O=D"
59+
echo ""
60+
exit 1
61+
}
62+
63+
# Default to installing pkg-config 1.16.3 if no version specified in the first
64+
# command-line argument
65+
if [[ $1 == 'default' ]]; then
66+
version=0.28
67+
else
68+
version=$1
69+
fi
70+
71+
build_path=${PWD}/pkg-config-$version-build
72+
73+
# Default to installing in the present working directory if no install path is specified:
74+
if [ -z $2 ]; then
75+
install_path=$build_path
76+
else
77+
install_path=$2
78+
fi
79+
80+
# Default to 2 threads if no specified thread count:
81+
if [ -z $3 ]; then
82+
num_threads=1
83+
else
84+
num_threads=$3
85+
fi
86+
87+
check_prerequisites()
88+
{
89+
# If there are no user-specified compilers in the path, default to gcc/g++.
90+
if [ -z $CC ]; then
91+
CC=gcc
92+
fi
93+
if [ -z $CXX ]; then
94+
CXX=g++
95+
fi
96+
# Verify that 'ftp' is is in the path.
97+
if ! type wget > /dev/null; then
98+
echo
99+
echo "$cmd requires 'wget'. Please ensure that it is installed and in your path. Aborting."
100+
exit 1
101+
fi
102+
if ! type make > /dev/null; then
103+
echo
104+
echo "$cmd requires 'make'. Please ensure that it is installed and in your path. Aborting."
105+
exit 1
106+
fi
107+
}
108+
109+
# Download pkg-config if the tar ball is not already in the present working directory
110+
download()
111+
{
112+
if [ ! -f "pkg-config-$version.tar.xz" ]; then
113+
echo "Downloading pkg-config-$version.tar.xz"
114+
wget http://pkgconfig.freedesktop.org/releases/pkg-config-$version.tar.gz
115+
else
116+
echo "Found pkg-config-$version.tar.xz in the current directory. Skipping download"
117+
fi
118+
}
119+
120+
# Unpack pkg-config if the unpacked tar ball is not in the present working directory
121+
unpack()
122+
{
123+
if [ ! -d "pkg-config-$version" ]; then
124+
echo "Unpacking pkg-config-$version.tar.xz"
125+
tar xf pkg-config-$version.tar.gz
126+
fi
127+
}
128+
129+
# Make the build directory, configure, and build
130+
build()
131+
{
132+
echo "Building pkg-config"
133+
mkdir -p $build_path &&
134+
cd $build_path &&
135+
../pkg-config-$version/configure --prefix=$install_path #&&
136+
CC=$CC CXX=$CXX make -j $num_threads
137+
}
138+
139+
if [ $# == 0 ]; then
140+
# Print usage information if script is invoked without arguments
141+
usage | less
142+
elif [[ $1 == '--help' || $1 == '-h' ]]; then
143+
# Print usage information if script is invoked with --help or -h argument
144+
usage | less
145+
elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
146+
# Print script copyright if invoked with -v, -V, or --version argument
147+
echo ""
148+
echo "pkg-config Build Script"
149+
echo "Copyright (C) 2015 Sourcery, Inc."
150+
echo "Copyright (C) 2015 Sourcery Institute"
151+
echo ""
152+
echo "$cmd comes with NO WARRANTY, to the extent permitted by law."
153+
echo "You may redistribute copies of $cmd under the terms of the"
154+
echo "BSD 3-Clause License. For more information about these matters, see"
155+
echo "http://www.sourceryinstitute.org/license.html"
156+
echo ""
157+
else
158+
# Download, unpack, and build CMake
159+
time \
160+
{
161+
check_prerequisites &&
162+
download &&
163+
unpack &&
164+
CC=$CC CXX=$CXX build $version $install_path $num_threads
165+
} >&1 | tee build.log
166+
echo ""
167+
echo "Check build.log for results. If the build was successful, type"
168+
echo "'cd pkg-config-$version-build && make install' (or 'cd pkg-config-$version-build && sudo make install')"
169+
echo "to complete the installation, after which pkg-config will be in the 'bin' subdirectory of $install_path"
170+
echo ""
171+
fi

0 commit comments

Comments
 (0)