-
Jan David Mol authoredJan David Mol authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
gen_LofarPackageList_cmake.sh 3.44 KiB
#!/bin/sh
#
# gen_LofarPackageList.cmake.sh: generate file LofarPackageList.cmake
#
# Copyright (C) 2009
# ASTRON (Netherlands Foundation for Research in Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, softwaresupport@astron.nl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
# This script generates the file LofarPackageList.cmake, which initializes the
# <pkg>_SOURCE_DIR variables for each LOFAR package.
# Get the LOFAR source directory root
script_dir=$(cd $(dirname $0) && pwd)
lofar_root=$script_dir/..
# Just a safety net; this script must be inside the LOFAR tree.
#if test "$script_dir" = "$lofar_root"; then
# echo "ERROR: $(basename $0) MUST be inside the LOFAR source tree!"
# exit 1
#fi
# Open the output file
exec 3> $script_dir/LofarPackageList.cmake
# Write header
cat >&3 <<EOF
# - Create for each LOFAR package a variable containing the absolute path to
# its source directory.
#
# Generated by $(basename $0) at $(date)
#
# ---- DO NOT EDIT ----
#
# ATTENTION: This file must be included BEFORE calling the lofar_package()
# macro; either directly, or indirectly.
#
# NOTE: This file must be kept up-to-date when LOFAR packages are added,
# moved, or deleted. You can use gen_LofarPackageList_cmake.sh to regenerate
# this file.
#
if(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED)
set(LOFAR_PACKAGE_LIST_INCLUDED TRUE)
EOF
# Guarantee we always sort the same way by setting the collate order to C.
export LC_COLLATE="C"
# Set internal field separator (IFS) to newline only.
IFS='
'
# Add a trailing slash to the directory path $lofar_root to ensure that, if
# it is a symbolic link, it is translated to the directory it links to.
for f in $(find $lofar_root/ -name CMakeLists.txt | sort)
do
# get directory name relative to $lofar_root
bdir=$(dirname $f | sed "s|$lofar_root/\?||")
# Search for the lofar_add_package() command, which looks like:
# lofar_add_package (MyPackage [MyPackageDir])
for pkg in $(sed -n "s|^[[:space:]]*[Ll][Oo][Ff][Aa][Rr]_[Aa][Dd][Dd]_[Pp][Aa][Cc][Kk][Aa][Gg][Ee][[:space:]]*([[:space:]]*\([^)]\+\)).*$|\1|p" $f)
do
# Strip optional command options to lofar_add_package()
pkg=$(echo $pkg | sed "s|[[:space:]]\+REQUIRED||")
# First argument is the package name
pkgnam=$(echo $pkg | sed "s|[[:space:]].*||")
# Continue with next package if package name is a variable
if echo $pkgnam | grep "\${.*}" > /dev/null; then
continue;
fi
# Remaining part is the package source dir
pkgdir=$(echo $pkg | sed -e "s|[^[:space:]]\+[[:space:]]\+||")
# Prefix pkgdir with bdir unless bdir is empty
pkgdir=${bdir:+$bdir/}$pkgdir
echo >&3 " set(${pkgnam}_SOURCE_DIR \${CMAKE_SOURCE_DIR}/${pkgdir})"
done
done
echo >&3 "endif(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED)"
# Close the output file
exec 3>&-