gst: Update for GST_PLUGIN_DEFINE() API changes
[platform/upstream/gstreamer.git] / tools / gst-element-maker
1 #!/bin/sh
2
3
4 prefix=gst
5 basedir=`dirname $0`
6 templatedir=$basedir/element-templates
7
8 while [ "$1" ] ; do
9   case $1 in
10     --help)
11       cat <<-EOF
12 Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS
13 Create a GStreamer element that subclasses BASE_CLASS.
14 Options:
15   --help             Print this information
16   --prefix PREFIX    Use PREFIX instead of "gst"
17 Example: 'element-maker my_element basetransform' will create the files
18   gstmyelement.c and gstmyelement.h that implement GstMyElement, a
19   subclass of GstBaseTransform, as an element named myelement.
20 EOF
21       exit 0
22       ;;
23     --prefix)
24       shift
25       prefix=$1
26       ;;
27     -*)
28       echo Unknown option: $1
29       exit 1
30       ;;
31     *)
32       if [ "$name" = "" ]; then
33         name=$1
34       elif [ "$class" = "" ]; then
35         class=$1
36       else
37         echo Ignored: $1
38       fi
39   esac
40   shift
41 done
42
43 if [ "$name" = "" -o "$class" = "" ] ; then
44   echo "Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS"
45   exit 1
46 fi
47
48 if [ ! -f "$templatedir/$class" ] ; then
49   echo "Template file for $class not found."
50   exit 1
51 fi
52
53
54 PREFIX=$(echo $prefix | sed -e 's/\(.*\)/\U\1/')
55 NAME=$(echo $name | sed -e 's/\(.*\)/\U\1/')
56 Prefix=$(echo $prefix | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
57 Name=$(echo $name | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
58 name=$(echo $name | sed -e 's/\(.*\)/\L\1/')
59
60 GST_IS_REPLACE=${PREFIX}_IS_${NAME}
61 GST_REPLACE=${PREFIX}_${NAME}
62 GST_TYPE_REPLACE=${PREFIX}_TYPE_${NAME}
63 GstReplace=${Prefix}${Name}
64 gst_replace=${prefix}_${name}
65 gstreplace=${prefix}$(echo $name | sed -e 's/_//g')
66 replace=$(echo $name | sed -e 's/_//g')
67
68 if [ "$REAL_NAME" = "" ] ; then
69   REAL_NAME=FIXME
70 fi
71 if [ "$EMAIL_ADDRESS" = "" ] ; then
72   EMAIL_ADDRESS=fixme@example.com
73 fi
74
75
76 pkg=`grep -A 10000 '^% pkg-config' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
77 GST_TYPE_BASE_REPLACE=`grep -A 10000 '^% TYPE_CLASS_NAME' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
78 GstBaseReplace=`grep -A 10000 '^% ClassName' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
79 pads=`grep -A 10000 '^% pads' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
80
81 generate ()
82 {
83
84 cat <<-EOF
85 /* GStreamer
86  * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
87  *
88  * This library is free software; you can redistribute it and/or
89  * modify it under the terms of the GNU Library General Public
90  * License as published by the Free Software Foundation; either
91  * version 2 of the License, or (at your option) any later version.
92  *
93  * This library is distributed in the hope that it will be useful,
94  * but WITHOUT ANY WARRANTY; without even the implied warranty of
95  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
96  * Library General Public License for more details.
97  *
98  * You should have received a copy of the GNU Library General Public
99  * License along with this library; if not, write to the
100  * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
101  * Boston, MA 02110-1335, USA.
102  */
103 EOF
104
105 cat <<-EOF
106 /**
107  * SECTION:element-$gstreplace
108  *
109  * The $replace element does FIXME stuff.
110  *
111  * <refsect2>
112  * <title>Example launch line</title>
113  * |[
114  * gst-launch -v fakesrc ! $replace ! FIXME ! fakesink
115  * ]|
116  * FIXME Describe what the pipeline does.
117  * </refsect2>
118  */
119 EOF
120
121
122 cat <<EOF
123
124 #ifdef HAVE_CONFIG_H
125 #include "config.h"
126 #endif
127
128 #include <gst/gst.h>
129 EOF
130
131 grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
132 grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
133
134 cat <<EOF
135 #include "gstreplace.h"
136
137 GST_DEBUG_CATEGORY_STATIC (gst_replace_debug_category);
138 #define GST_CAT_DEFAULT gst_replace_debug_category
139
140 /* prototypes */
141
142 EOF
143
144 grep -A 10000 '^% prototypes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
145 grep -A 10000 '^% prototypes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
146 for each in $pads
147 do
148   grep -A 10000 '^% prototypes' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
149 done
150
151 cat <<EOF
152
153 enum
154 {
155   PROP_0
156 };
157
158 /* pad templates */
159
160 EOF
161
162 for each in $pads
163 do
164   grep -A 10000 '^% pad-template' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
165 done
166
167 cat <<EOF
168
169 /* class initialization */
170
171 #define DEBUG_INIT(bla) \\
172   GST_DEBUG_CATEGORY_INIT (gst_replace_debug_category, "replace", 0, \\
173       "debug category for replace element");
174
175 GST_BOILERPLATE_FULL (GstReplace, gst_replace, GstBaseReplace,
176     GST_TYPE_BASE_REPLACE, DEBUG_INIT);
177
178 static void
179 gst_replace_base_init (gpointer g_class)
180 {
181   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
182
183 EOF
184
185 for each in $pads
186 do
187   grep -A 10000 '^% base-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
188 done
189
190 cat <<EOF
191
192   gst_element_class_set_details_simple (element_class, "FIXME Long name",
193       "Generic", "FIXME Description", "$REAL_NAME <$EMAIL_ADDRESS>");
194 }
195
196 static void
197 gst_replace_class_init (GstReplaceClass * klass)
198 {
199 EOF
200 grep -A 10000 '^% declare-class' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
201 grep -A 10000 '^% declare-class' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
202
203 echo
204
205 grep -A 10000 '^% set-methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
206 grep -A 10000 '^% set-methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
207
208 cat <<EOF
209
210 }
211
212 static void
213 gst_replace_init (GstReplace * replace, GstReplaceClass * replace_class)
214 {
215 EOF
216
217 for each in $pads
218 do
219   grep -A 10000 '^% instance-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
220 done
221
222
223 cat <<EOF
224 }
225 EOF
226
227
228 grep -A 10000 '^% methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
229 grep -A 10000 '^% methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
230 for each in $pads
231 do
232   grep -A 10000 '^% methods' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
233 done
234
235
236 cat <<EOF
237
238 static gboolean
239 plugin_init (GstPlugin * plugin)
240 {
241
242   return gst_element_register (plugin, "replace", GST_RANK_NONE,
243       GST_TYPE_REPLACE);
244 }
245
246 #ifndef VERSION
247 #define VERSION "0.0.FIXME"
248 #endif
249 #ifndef PACKAGE
250 #define PACKAGE "FIXME_package"
251 #endif
252 #ifndef PACKAGE_NAME
253 #define PACKAGE_NAME "FIXME_package_name"
254 #endif
255 #ifndef GST_PACKAGE_ORIGIN
256 #define GST_PACKAGE_ORIGIN "http://FIXME.org/"
257 #endif
258
259 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
260     GST_VERSION_MINOR,
261     replace,
262     "FIXME plugin description",
263     plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
264
265 EOF
266
267
268 }
269
270 generate_header ()
271 {
272
273 cat <<-EOF
274 /* GStreamer
275  * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
276  *
277  * This library is free software; you can redistribute it and/or
278  * modify it under the terms of the GNU Library General Public
279  * License as published by the Free Software Foundation; either
280  * version 2 of the License, or (at your option) any later version.
281  *
282  * This library is distributed in the hope that it will be useful,
283  * but WITHOUT ANY WARRANTY; without even the implied warranty of
284  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
285  * Library General Public License for more details.
286  *
287  * You should have received a copy of the GNU Library General Public
288  * License along with this library; if not, write to the
289  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
290  * Boston, MA 02111-1307, USA.
291  */
292
293 EOF
294
295 cat <<EOF
296 #ifndef _GST_REPLACE_H_
297 #define _GST_REPLACE_H_
298
299 EOF
300
301 grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
302 grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
303
304 cat <<EOF
305
306 G_BEGIN_DECLS
307
308 #define GST_TYPE_REPLACE \
309   (gst_replace_get_type())
310 #define GST_REPLACE(obj) \
311   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_REPLACE,GstReplace))
312 #define GST_REPLACE_CLASS(klass) \
313   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_REPLACE,GstReplaceClass))
314 #define GST_IS_REPLACE(obj) \
315   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_REPLACE))
316 #define GST_IS_REPLACE_CLASS(obj) \
317   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_REPLACE))
318
319 typedef struct _GstReplace GstReplace;
320 typedef struct _GstReplaceClass GstReplaceClass;
321
322 struct _GstReplace
323 {
324   GstBaseReplace base_replace;
325
326 EOF
327
328 for each in $pads
329 do
330   grep -A 10000 '^% instance-members' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
331 done
332
333 cat <<EOF
334 };
335
336 struct _GstReplaceClass
337 {
338   GstBaseReplaceClass base_replace_class;
339 };
340
341 GType gst_replace_get_type (void);
342
343 G_END_DECLS
344
345 #endif
346 EOF
347
348
349 }
350
351
352 generate | sed \
353   -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
354   -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
355   -e "s/GstBaseReplace/$GstBaseReplace/g" \
356   -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
357   -e "s/GST_REPLACE/$GST_REPLACE/g" \
358   -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
359   -e "s/GstReplace/$GstReplace/g" \
360   -e "s/gst_replace/$gst_replace/g" \
361   -e "s/gstreplace/$gstreplace/g" \
362   -e "s/replace/$replace/g" >$gstreplace.c
363
364 generate_header | sed \
365   -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
366   -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
367   -e "s/GstBaseReplace/$GstBaseReplace/g" \
368   -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
369   -e "s/GST_REPLACE/$GST_REPLACE/g" \
370   -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
371   -e "s/GstReplace/$GstReplace/g" \
372   -e "s/gst_replace/$gst_replace/g" \
373   -e "s/gstreplace/$gstreplace/g" \
374   -e "s/replace/$replace/g" >$gstreplace.h
375
376 gst-indent $gstreplace.c
377
378 echo pkg is $pkg
379
380 gcc -Wall -fPIC $CPPFLAGS $(pkg-config --cflags gstreamer-0.10 $pkg) -c -o $gstreplace.o $gstreplace.c
381 if test $? -ne 0; then
382     exit 1
383 fi
384
385 gcc -shared -o $gstreplace.so $gstreplace.o $(pkg-config --libs gstreamer-0.10 $pkg)
386 if test $? -ne 0; then
387     exit 1
388 fi
389