#!/bin/sh
prefix=gst
basedir=`dirname $0`
templatedir=$basedir/element-templates
while [ "$1" ] ; do
case $1 in
--help)
cat <<-EOF
Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS
Create a GStreamer element that subclasses BASE_CLASS.
Options:
--help Print this information
--prefix PREFIX Use PREFIX instead of "gst"
Example: 'element-maker my_element basetransform' will create the files
gstmyelement.c and gstmyelement.h that implement GstMyElement, a
subclass of GstBaseTransform, as an element named myelement.
EOF
exit 0
;;
--prefix)
shift
prefix=$1
;;
-*)
echo Unknown option: $1
exit 1
;;
*)
if [ "$name" = "" ]; then
name=$1
elif [ "$class" = "" ]; then
class=$1
else
echo Ignored: $1
fi
esac
shift
done
if [ "$name" = "" -o "$class" = "" ] ; then
echo "Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS"
exit 1
fi
if [ ! -f "$templatedir/$class" ] ; then
echo "Template file for $class not found."
exit 1
fi
PREFIX=$(echo $prefix | sed -e 's/\(.*\)/\U\1/')
NAME=$(echo $name | sed -e 's/\(.*\)/\U\1/')
Prefix=$(echo $prefix | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
Name=$(echo $name | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
name=$(echo $name | sed -e 's/\(.*\)/\L\1/')
GST_IS_REPLACE=${PREFIX}_IS_${NAME}
GST_REPLACE=${PREFIX}_${NAME}
GST_TYPE_REPLACE=${PREFIX}_TYPE_${NAME}
GstReplace=${Prefix}${Name}
gst_replace=${prefix}_${name}
gstreplace=${prefix}$(echo $name | sed -e 's/_//g')
replace=$(echo $name | sed -e 's/_//g')
if [ "$REAL_NAME" = "" ] ; then
REAL_NAME=FIXME
fi
if [ "$EMAIL_ADDRESS" = "" ] ; then
EMAIL_ADDRESS=fixme@example.com
fi
pkg=`grep -A 10000 '^% pkg-config' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
GST_TYPE_BASE_REPLACE=`grep -A 10000 '^% TYPE_CLASS_NAME' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
GstBaseReplace=`grep -A 10000 '^% ClassName' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
pads=`grep -A 10000 '^% pads' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
generate ()
{
cat <<-EOF
/* GStreamer
* Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
* Boston, MA 02110-1335, USA.
*/
EOF
cat <<-EOF
/**
* SECTION:element-$gstreplace
*
* The $replace element does FIXME stuff.
*
*
* Example launch line
* |[
* gst-launch -v fakesrc ! $replace ! FIXME ! fakesink
* ]|
* FIXME Describe what the pipeline does.
*
*/
EOF
cat <
EOF
grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
cat <");
}
static void
gst_replace_class_init (GstReplaceClass * klass)
{
EOF
grep -A 10000 '^% declare-class' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
grep -A 10000 '^% declare-class' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
echo
grep -A 10000 '^% set-methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
grep -A 10000 '^% set-methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
cat <
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
EOF
cat <$gstreplace.c
generate_header | sed \
-e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
-e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
-e "s/GstBaseReplace/$GstBaseReplace/g" \
-e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
-e "s/GST_REPLACE/$GST_REPLACE/g" \
-e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
-e "s/GstReplace/$GstReplace/g" \
-e "s/gst_replace/$gst_replace/g" \
-e "s/gstreplace/$gstreplace/g" \
-e "s/replace/$replace/g" >$gstreplace.h
gst-indent $gstreplace.c
echo pkg is $pkg
gcc -Wall -fPIC $CPPFLAGS $(pkg-config --cflags gstreamer-0.10 $pkg) -c -o $gstreplace.o $gstreplace.c
if test $? -ne 0; then
exit 1
fi
gcc -shared -o $gstreplace.so $gstreplace.o $(pkg-config --libs gstreamer-0.10 $pkg)
if test $? -ne 0; then
exit 1
fi