2010-01-14 06:42:49 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Script to configure "staticability" of plugins
|
|
|
|
# author: pancake // nopcode
|
2011-05-21 01:49:50 +08:00
|
|
|
# update: 2010-01-14
|
2010-01-14 06:42:49 +08:00
|
|
|
#
|
|
|
|
|
2015-04-20 20:44:54 +08:00
|
|
|
LANG=C
|
|
|
|
LC_ALL=C
|
2015-04-10 06:17:30 +08:00
|
|
|
LOADLIBS=1
|
|
|
|
|
2015-04-20 20:44:54 +08:00
|
|
|
export LANG
|
|
|
|
export LC_ALL
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
list () {
|
2010-01-14 06:42:49 +08:00
|
|
|
for a in $STATIC ; do echo "static $a" ; done
|
|
|
|
for a in $SHARED ; do echo "shared $a" ; done
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
help () {
|
2010-01-14 06:42:49 +08:00
|
|
|
echo "Usage: ./configure-plugins [options]"
|
|
|
|
echo " -n do nothing.. do not generate any file"
|
|
|
|
echo " --list list all static and shared plugins"
|
2016-05-04 07:31:07 +08:00
|
|
|
echo " --rm-static [dir] remove plugins that are already in core from dir"
|
2010-01-14 06:42:49 +08:00
|
|
|
echo " --static [name ..] define named plugin as static"
|
|
|
|
echo " --shared [name ..] define named plugin as shared"
|
|
|
|
echo " --help, -h display this helpful message"
|
|
|
|
echo "NOTE: static plugins are compiled inside the owner library"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg=./plugins.cfg
|
|
|
|
|
2017-05-15 05:15:07 +08:00
|
|
|
if [ ! -f "$cfg" ]; then
|
|
|
|
cp -f ./plugins.def.cfg plugins.cfg
|
|
|
|
fi
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
load () {
|
2010-01-14 07:12:41 +08:00
|
|
|
if [ -e $cfg ]; then
|
|
|
|
echo "configure-plugins: Loading $cfg .."
|
|
|
|
. $cfg
|
|
|
|
else
|
2015-02-07 08:41:54 +08:00
|
|
|
echo "configure-plugins: Loading $1 .."
|
|
|
|
. "$1" #plugins.def.cfg
|
2010-01-14 07:12:41 +08:00
|
|
|
fi
|
2010-01-14 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
save () {
|
2017-05-15 05:15:07 +08:00
|
|
|
cp $cfg plugins.cfg
|
|
|
|
# echo "STATIC=\"$STATIC\"" > $cfg
|
|
|
|
# echo "SHARED=\"$SHARED\"" >>$cfg
|
2010-01-14 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
generate_configh () {
|
2010-02-26 07:37:49 +08:00
|
|
|
plugins=""
|
2010-01-14 06:42:49 +08:00
|
|
|
oldlib=""
|
|
|
|
for a in ${STATIC} ; do
|
|
|
|
lib=$(echo $a | cut -d . -f 1) # library
|
|
|
|
plg=$(echo $a | cut -d . -f 2) # plugin name
|
|
|
|
if [ ! "$oldlib" = "$lib" ]; then
|
|
|
|
[ -n "$oldlib" ] && echo " 0"
|
|
|
|
oldlib=$lib
|
2017-04-14 05:34:15 +08:00
|
|
|
if type perl > /dev/null 2>&1 ; then
|
2017-03-24 07:54:23 +08:00
|
|
|
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
|
|
|
|
else
|
|
|
|
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
|
|
|
|
fi
|
2010-01-14 06:42:49 +08:00
|
|
|
echo
|
|
|
|
echo "#define R_${uclib}_STATIC_PLUGINS \\"
|
2010-02-26 07:37:49 +08:00
|
|
|
plugins="${plugins} __${uclib}"
|
2010-01-14 06:42:49 +08:00
|
|
|
fi
|
|
|
|
echo " &r_${lib}_plugin_${plg}, \\"
|
|
|
|
done
|
2010-02-22 03:21:36 +08:00
|
|
|
[ -n "$oldlib" ] && echo " 0"
|
2010-02-26 07:37:49 +08:00
|
|
|
|
|
|
|
# FILL EMPTY PLUGIN ARRAYS WITH LOVE
|
|
|
|
for a in ${SHARED} ; do
|
|
|
|
lib=$(echo $a | cut -d . -f 1) # library
|
|
|
|
plg=$(echo $a | cut -d . -f 2) # plugin name
|
|
|
|
if [ ! "$oldlib" = "$lib" ]; then
|
|
|
|
oldlib=$lib
|
2017-04-14 05:34:15 +08:00
|
|
|
if type perl > /dev/null 2>&1; then
|
2017-03-24 07:54:23 +08:00
|
|
|
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
|
|
|
|
else
|
|
|
|
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
|
|
|
|
fi
|
2010-02-26 07:37:49 +08:00
|
|
|
if [ -z "`echo ${plugins} | grep __${uclib}`" ]; then
|
|
|
|
plugins="${plugins} __${uclib}"
|
|
|
|
echo
|
|
|
|
echo "#define R_${uclib}_STATIC_PLUGINS 0"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2010-01-14 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
generate_configmk () {
|
2010-02-26 07:37:49 +08:00
|
|
|
plugins=""
|
2010-01-14 06:42:49 +08:00
|
|
|
oldlib=""
|
|
|
|
for a in ${STATIC} ; do
|
|
|
|
lib=$(echo $a | cut -d . -f 1) # library
|
|
|
|
plg=$(echo $a | cut -d . -f 2) # plugin name
|
|
|
|
if [ ! "$oldlib" = "$lib" ]; then
|
|
|
|
[ -n "$oldlib" ] && printf "\n"
|
|
|
|
oldlib=$lib
|
2017-04-14 05:34:15 +08:00
|
|
|
if type perl > /dev/null 2>&1 ; then
|
2017-03-24 07:54:23 +08:00
|
|
|
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
|
|
|
|
else
|
|
|
|
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
|
|
|
|
fi
|
2010-01-14 06:42:49 +08:00
|
|
|
printf "STATIC_${uclib}_PLUGINS= "
|
2010-02-26 07:37:49 +08:00
|
|
|
plugins="${plugins} __${uclib}"
|
2010-01-14 06:42:49 +08:00
|
|
|
fi
|
|
|
|
printf "p/${plg}.mk "
|
|
|
|
done
|
2010-02-26 07:37:49 +08:00
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
# fill the holes with love
|
|
|
|
for a in ${SHARED} ; do
|
|
|
|
lib=$(echo $a | cut -d . -f 1) # library
|
2017-04-14 05:34:15 +08:00
|
|
|
if type perl > /dev/null 2>&1 ; then
|
2017-03-24 07:54:23 +08:00
|
|
|
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
|
|
|
|
else
|
|
|
|
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
|
|
|
|
fi
|
2010-02-26 07:37:49 +08:00
|
|
|
if [ -z "`echo ${plugins} | grep __${uclib}`" ]; then
|
|
|
|
plugins="${plugins} __${uclib}"
|
|
|
|
echo "STATIC_${uclib}_PLUGINS="
|
|
|
|
fi
|
|
|
|
done
|
2010-01-14 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
generate () {
|
2010-01-14 06:42:49 +08:00
|
|
|
echo "configure-plugins: Generating libr/config.h .."
|
|
|
|
cat libr/config.h.head > libr/config.h
|
2015-04-10 06:17:30 +08:00
|
|
|
echo "#define R2_LOADLIBS ${LOADLIBS}" >> libr/config.h
|
2010-01-14 06:42:49 +08:00
|
|
|
generate_configh >> libr/config.h
|
|
|
|
cat libr/config.h.tail >> libr/config.h
|
|
|
|
|
|
|
|
echo "configure-plugins: Generating libr/config.mk .."
|
|
|
|
cat libr/config.mk.head > libr/config.mk
|
|
|
|
generate_configmk >> libr/config.mk
|
|
|
|
cat libr/config.mk.tail >> libr/config.mk
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
add () {
|
2010-01-14 06:42:49 +08:00
|
|
|
for a in $1 ; do [ $a = $2 ] && return ; done ; echo $1 $2
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
sub () {
|
2010-01-14 06:42:49 +08:00
|
|
|
n="" ; for a in $1 ; do [ $a = $2 ] && continue ; n="$n $a" ; done ; echo $n
|
|
|
|
}
|
|
|
|
|
2014-09-01 21:25:32 +08:00
|
|
|
|
|
|
|
echo | sort -t. > /dev/null 2>&1
|
|
|
|
if [ $? = 0 ]; then
|
|
|
|
SORT="sort -t."
|
|
|
|
else
|
|
|
|
SORT="sort"
|
|
|
|
fi
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
dosort () {
|
2015-04-20 17:57:33 +08:00
|
|
|
( for a in $1 ; do echo $a ; done ) | tr _ Z | ${SORT} | tr Z _
|
2010-02-22 03:21:36 +08:00
|
|
|
#( for a in $1 ; do echo $a ; done ) | sort -t. --key=1,1d
|
2010-01-14 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
sort_vars () {
|
2010-01-14 06:42:49 +08:00
|
|
|
STATIC=$(dosort "$STATIC")
|
|
|
|
SHARED=$(dosort "$SHARED")
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
make_static () {
|
2010-01-14 06:42:49 +08:00
|
|
|
STATIC=$(add "$STATIC" $1)
|
|
|
|
SHARED=$(sub "$SHARED" $1)
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
make_shared () {
|
2010-01-14 06:42:49 +08:00
|
|
|
SHARED=$(add "$SHARED" $1)
|
|
|
|
STATIC=$(sub "$STATIC" $1)
|
|
|
|
}
|
|
|
|
|
2010-01-15 02:15:36 +08:00
|
|
|
make_ () { : ; }
|
2010-01-14 06:42:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
MODE=""
|
|
|
|
DONOTHING=0
|
2015-02-07 08:41:54 +08:00
|
|
|
DEFCFG=./plugins.def.cfg
|
|
|
|
|
2016-05-04 07:31:07 +08:00
|
|
|
rmstatic() {
|
|
|
|
C=0
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Missing argument"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
for a in ${STATIC} ; do
|
|
|
|
b="`echo $a | tr . _`"
|
|
|
|
for ext in dll dylib so ; do
|
|
|
|
f="$b.$ext"
|
|
|
|
if [ -f "$f" ]; then
|
|
|
|
C=$(($C+1))
|
|
|
|
printf " $C found\r"
|
|
|
|
#echo "rm -f $f"
|
|
|
|
rm -f "$f"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
echo "Removed $C shared plugins that are already static"
|
|
|
|
}
|
|
|
|
|
|
|
|
RMSTATIC=-
|
|
|
|
|
2010-01-14 06:42:49 +08:00
|
|
|
while : ; do
|
|
|
|
[ -z "$1" ] && break
|
|
|
|
case "$1" in
|
|
|
|
"--static") MODE=static ; ;;
|
|
|
|
"--shared") MODE=shared ; ;;
|
2015-02-07 08:41:54 +08:00
|
|
|
"--without-gpl") DEFCFG=./plugins.nogpl.cfg ;;
|
2015-04-10 06:17:30 +08:00
|
|
|
"--disable-loadlibs") LOADLIBS=0 ;;
|
2016-05-04 07:31:07 +08:00
|
|
|
"--rm-static") RMSTATIC="$2" ; ;;
|
2010-01-14 06:42:49 +08:00
|
|
|
"--list") sort_vars ; list ; ;;
|
|
|
|
"-n") DONOTHING=1 ; ;;
|
|
|
|
"-h"|"--help") help ; ;;
|
|
|
|
*) eval make_$MODE $1 ; ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2015-02-07 08:41:54 +08:00
|
|
|
load ${DEFCFG}
|
2010-01-14 06:42:49 +08:00
|
|
|
sort_vars
|
|
|
|
|
2016-05-04 07:31:07 +08:00
|
|
|
if [ - != "${RMSTATIC}" ]; then
|
|
|
|
if [ -z "${RMSTATIC}" ]; then
|
2017-02-01 05:13:32 +08:00
|
|
|
echo "Missing argument" >&2
|
2016-05-04 07:31:07 +08:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
if [ -d "${RMSTATIC}" ]; then
|
|
|
|
cd "${RMSTATIC}" && rmstatic "${RMSTATIC}"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2010-01-14 06:42:49 +08:00
|
|
|
[ ${DONOTHING} = 0 ] && generate
|
|
|
|
|
2015-03-16 08:19:25 +08:00
|
|
|
echo SHARED: ${SHARED}
|
|
|
|
echo STATIC: ${STATIC}
|
2014-09-01 21:25:32 +08:00
|
|
|
|
2010-01-14 06:42:49 +08:00
|
|
|
save
|
2010-01-14 07:12:41 +08:00
|
|
|
|
|
|
|
exit 0
|