ENH: wmakeLnInclude support for multiple dirs and -force option (#1693)
STYLE: minor changes to makefiles
This commit is contained in:
parent
488b03980e
commit
8bd9f41efd
@ -6,11 +6,10 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# Copyright (C) 2018 OpenCFD Ltd.
|
# Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM, licensed under GNU General Public License
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
# <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
#
|
||||||
# File
|
# File
|
||||||
# wmake/makefiles/files
|
# wmake/makefiles/files
|
||||||
@ -52,7 +51,7 @@ all : $(OPTIONS) $(SFILES) $(VARS)
|
|||||||
|
|
||||||
$(OPTIONS) : $(MAKE_DIR)/options
|
$(OPTIONS) : $(MAKE_DIR)/options
|
||||||
@$(CPP) $(GFLAGS) $(MAKE_DIR)/options | sed -e 's@ *@ @g' > $(OPTIONS)
|
@$(CPP) $(GFLAGS) $(MAKE_DIR)/options | sed -e 's@ *@ @g' > $(OPTIONS)
|
||||||
ifeq ("$(WM_OSTYPE)","MSwindows")
|
ifneq (,$(findstring windows,$(WM_OSTYPE)))
|
||||||
@$(WM_SCRIPTS)/wmakeWindowsDlOpenLibs $(OPTIONS) >> $(OPTIONS)
|
@$(WM_SCRIPTS)/wmakeWindowsDlOpenLibs $(OPTIONS) >> $(OPTIONS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
SHELL = /bin/sh
|
SHELL = /bin/sh
|
||||||
|
|
||||||
ifeq ("$(WM_OSTYPE)","")
|
ifeq (,$(WM_OSTYPE))
|
||||||
WM_OSTYPE = POSIX
|
WM_OSTYPE := POSIX
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ objects: $(OBJECTS) | silent
|
|||||||
.PHONY: libso
|
.PHONY: libso
|
||||||
libso: $(LIB)$(EXT_SO) | silent
|
libso: $(LIB)$(EXT_SO) | silent
|
||||||
|
|
||||||
ifeq ("$(WM_OSTYPE)","MSwindows")
|
ifneq (,$(findstring windows,$(WM_OSTYPE)))
|
||||||
$(LIB)$(EXT_SO): $(OBJECTS)
|
$(LIB)$(EXT_SO): $(OBJECTS)
|
||||||
@$(WM_SCRIPTS)/makeTargetDir $(LIB)
|
@$(WM_SCRIPTS)/makeTargetDir $(LIB)
|
||||||
$(call QUIET_MESSAGE,ld,$(LIB)$(EXT_SO))
|
$(call QUIET_MESSAGE,ld,$(LIB)$(EXT_SO))
|
||||||
@ -211,7 +211,7 @@ $(LIB).o: $(OBJECTS)
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
lnInclude: $(MAKE_DIR)/files $(MAKE_DIR)/options
|
lnInclude: $(MAKE_DIR)/files $(MAKE_DIR)/options
|
||||||
@rm -rf lnInclude ; wmakeLnInclude .
|
@wmakeLnInclude -force .
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@ -231,7 +231,7 @@ dep: $(DEPENDENCIES)
|
|||||||
|
|
||||||
updatedep: dep
|
updatedep: dep
|
||||||
|
|
||||||
ifeq ($(findstring lnInclude,$(MAKECMDGOALS))$(findstring updatedep,$(MAKECMDGOALS)),)
|
ifeq (,$(findstring lnInclude,$(MAKECMDGOALS))$(findstring updatedep,$(MAKECMDGOALS)))
|
||||||
sinclude $(DEPENDENCIES)
|
sinclude $(DEPENDENCIES)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -7,60 +7,59 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# Copyright (C) 2019 OpenCFD Ltd.
|
# Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM.
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
#
|
|
||||||
# OpenFOAM 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 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
#
|
||||||
# Script
|
# Script
|
||||||
# wmakeLnInclude
|
# wmake/wmakeLnInclude
|
||||||
#
|
#
|
||||||
# Usage
|
# Usage
|
||||||
# wmakeLnInclude [OPTION] [-pwd | <dir>]
|
# wmakeLnInclude [OPTION] [-pwd | dir [.. dirN]]
|
||||||
#
|
#
|
||||||
# Description
|
# Description
|
||||||
# Link all the source files in the <dir> directory into <dir>/lnInclude
|
# Link source files in the specified dir(s) into their respective
|
||||||
|
# lnInclude directories
|
||||||
#
|
#
|
||||||
# C files: .c .h
|
# C files: .c .h
|
||||||
# C++ files: .C .cc .cpp .cxx .H .hh .hpp .hxx
|
# C++ files: .C .cc .cpp .cxx .H .hh .hpp .hxx
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
Script="${0##*/}" # Use 'Script' for error messages in wmakeFunctions
|
Script="${0##*/}" # Need 'Script' for wmakeFunctions messages
|
||||||
. "${0%/*}/scripts/wmakeFunctions" # Source wmake functions
|
scriptsDir="${0%/*}"/scripts # wmake/scripts directory
|
||||||
|
. "$scriptsDir"/wmakeFunctions # Source wmake functions
|
||||||
|
|
||||||
usage() {
|
printHelp() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: $Script [OPTION] [-pwd | dir]
|
Usage: ${0##*/} [OPTION] [-pwd | dir [.. dirN]]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-u | -update Update
|
-f | -force Force remove of existing lnInclude before recreating
|
||||||
|
-u | -update Update existing lnInclude directories
|
||||||
-s | -silent Silent mode (do not echo command)
|
-s | -silent Silent mode (do not echo command)
|
||||||
-pwd Locate root directory containing a Make/ directory.
|
-pwd Locate root directory containing Make/ directory
|
||||||
-h | -help Print the usage
|
-h | -help Print the usage
|
||||||
|
|
||||||
Link all the source files in the <dir> into <dir>/lnInclude
|
Link source files in specified dir(s) into their respective
|
||||||
|
lnInclude directories. With '-update', items are relinked with 'ln -sf'
|
||||||
Note
|
|
||||||
The '-u' option forces an update when the lnInclude directory already exists
|
|
||||||
and changes the default linking from 'ln -s' to 'ln -sf'.
|
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
exit 0 # clean exit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Report error and exit
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
exec 1>&2
|
||||||
|
echo
|
||||||
|
echo "Error encountered:"
|
||||||
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||||
|
echo
|
||||||
|
echo "See '${0##*/} -help' for usage"
|
||||||
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,26 +71,30 @@ USAGE
|
|||||||
# Option for 'ln'
|
# Option for 'ln'
|
||||||
optLink="-s"
|
optLink="-s"
|
||||||
|
|
||||||
unset update optQuiet optFindRootDir
|
unset optForce optQuiet optUpdate optPwd
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help*) # Provide immediate help
|
-h | -help*)
|
||||||
usage
|
printHelp
|
||||||
|
;;
|
||||||
|
-f | -force)
|
||||||
|
optForce=true
|
||||||
|
optLink="-sf"
|
||||||
;;
|
;;
|
||||||
-u | -update)
|
-u | -update)
|
||||||
update=true
|
optUpdate=true
|
||||||
optLink="-sf"
|
optLink="-sf"
|
||||||
;;
|
;;
|
||||||
-s | -silent)
|
-s | -silent)
|
||||||
optQuiet=true
|
optQuiet=true
|
||||||
;;
|
;;
|
||||||
-pwd)
|
-pwd)
|
||||||
optFindRootDir=true
|
optPwd=true
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$1'"
|
die "unknown option: '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -100,16 +103,15 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$optFindRootDir" = true ] || [ "$#" -eq 1 ] || \
|
[ "$optPwd" = true ] || [ "$#" -ge 1 ] || \
|
||||||
usage "Error: incorrect number of arguments"
|
die "incorrect number of arguments"
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
unset dir
|
|
||||||
baseDir="$1"
|
baseDir="$1"
|
||||||
|
|
||||||
# With -root, go on discovery
|
# With -pwd, go on discovery
|
||||||
if [ "$optFindRootDir" = true ]
|
if [ "$optPwd" = true ]
|
||||||
then
|
then
|
||||||
if [ -n "$baseDir" ]
|
if [ -n "$baseDir" ]
|
||||||
then
|
then
|
||||||
@ -121,6 +123,7 @@ then
|
|||||||
then
|
then
|
||||||
dir="${dir%/*}"
|
dir="${dir%/*}"
|
||||||
: "${dir:=.}"
|
: "${dir:=.}"
|
||||||
|
[ "$dir" != "$baseDir" ] || dir="."
|
||||||
else
|
else
|
||||||
echo "$Script error: not a file or directory" 1>&2
|
echo "$Script error: not a file or directory" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
@ -141,75 +144,94 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Using $baseDir" 1>&2
|
echo "Using $baseDir" 1>&2
|
||||||
|
|
||||||
|
set -- "$baseDir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Convert incorrect path/dir/lnInclude to something sensible
|
unset errorCode
|
||||||
while [ "${baseDir##*/}" = lnInclude ]
|
|
||||||
|
for baseDir
|
||||||
do
|
do
|
||||||
baseDir="${baseDir%/*}"
|
|
||||||
if [ "$baseDir" = lnInclude ]
|
# Correct path/dir/lnInclude to something more sensible
|
||||||
|
while [ "${baseDir##*/}" = lnInclude ]
|
||||||
|
do
|
||||||
|
baseDir="${baseDir%/*}"
|
||||||
|
if [ "$baseDir" = lnInclude ]
|
||||||
|
then
|
||||||
|
baseDir="."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -d "$baseDir" ] || {
|
||||||
|
echo "$Script error: base directory $baseDir does not exist" 1>&2
|
||||||
|
errorCode=2
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
incDir="$baseDir/lnInclude"
|
||||||
|
|
||||||
|
if [ "$optForce" = true ]
|
||||||
then
|
then
|
||||||
baseDir="."
|
rm -rf -- "$incDir"
|
||||||
|
mkdir "$incDir"
|
||||||
|
elif [ -d "$incDir" ]
|
||||||
|
then
|
||||||
|
if [ "$optUpdate" != true ]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
mkdir "$incDir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$incDir" ]
|
||||||
|
then
|
||||||
|
(
|
||||||
|
cd "$incDir" || {
|
||||||
|
errorCode=1
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Display compact info
|
||||||
|
echo " ln: $incDir" 1>&2
|
||||||
|
|
||||||
|
# Remove any broken links first
|
||||||
|
# - helps if file locations have moved
|
||||||
|
|
||||||
|
case "$WM_ARCH" in
|
||||||
|
(darwin*)
|
||||||
|
# -exec rm (not -delete) to remove names with '/' in their name
|
||||||
|
# with \+ instead of \; to pack into a single command
|
||||||
|
find -L . -type l -exec rm -- {} \+
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
find -L . -type l -delete
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Create links, avoid recreating links unless necessary
|
||||||
|
# things in the 'noLink' directory are skipped
|
||||||
|
|
||||||
|
find .. \
|
||||||
|
\( -name lnInclude -o -name Make -o -name config -o -name noLink \) \
|
||||||
|
-prune \
|
||||||
|
-o \( \
|
||||||
|
-name '*.[CHch]' \
|
||||||
|
-o -name '*.cc' \
|
||||||
|
-o -name '*.hh' \
|
||||||
|
-o -name '*.[ch]xx' \
|
||||||
|
-o -name '*.[ch]pp' \
|
||||||
|
-o -name '*.type' \
|
||||||
|
\) \
|
||||||
|
-exec ln "$optLink" {} . \;
|
||||||
|
)
|
||||||
|
else
|
||||||
|
echo "$Script error: failed to create include directory $incDir" 1>&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
incDir="$baseDir/lnInclude"
|
|
||||||
|
|
||||||
|
|
||||||
[ -d "$baseDir" ] || {
|
|
||||||
echo "$Script error: base directory $baseDir does not exist" 1>&2
|
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -d "$incDir" ]
|
|
||||||
then
|
|
||||||
[ "$update" = true ] || exit 0
|
|
||||||
else
|
|
||||||
mkdir "$incDir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -d "$incDir" ] || {
|
|
||||||
echo "$Script error: failed to create include directory $incDir" 1>&2
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cd "$incDir" || exit 1
|
|
||||||
|
|
||||||
# Always just display compact info
|
|
||||||
echo " ln: $incDir" 1>&2
|
|
||||||
|
|
||||||
|
exit "${errorCode:-0}" # clean exit
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
# Remove any broken links first (this helps when file locations have moved)
|
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
case "$WM_ARCH" in
|
|
||||||
(darwin*)
|
|
||||||
find -L . -type l -exec rm -- {} \+
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
find -L . -type l -delete
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
# Create links, avoid recreating links unless necessary
|
|
||||||
# things placed in the 'noLink' directory are skipped
|
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
find .. \
|
|
||||||
\( -name lnInclude -o -name Make -o -name config -o -name noLink \) \
|
|
||||||
-prune \
|
|
||||||
-o \( \
|
|
||||||
-name '*.[CHch]' \
|
|
||||||
-o -name '*.cc' \
|
|
||||||
-o -name '*.hh' \
|
|
||||||
-o -name '*.[ch]xx' \
|
|
||||||
-o -name '*.[ch]pp' \
|
|
||||||
-o -name '*.type' \
|
|
||||||
\) \
|
|
||||||
-exec ln "$optLink" {} . \;
|
|
||||||
|
|
||||||
exit 0 # clean exit
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user