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