gst: Update for GST_PLUGIN_DEFINE() API changes
[platform/upstream/gstreamer.git] / tools / gst-project-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: gst-project-maker [OPTIONS] PROJECT_NAME
12 Create an autotools project based on GStreamer from a template.
13 Options:
14   --help             Print this information
15   --prefix PREFIX    Use PREFIX instead of "gst"
16 Example: 'gst-project-maker my_project' will create the project gst-my-project.
17 EOF
18       exit 0
19       ;;
20     --prefix)
21       shift
22       prefix=$1
23       ;;
24     -*)
25       echo Unknown option: $1
26       exit 1
27       ;;
28     *)
29       if [ "$name" = "" ]; then
30         name=$1
31       else
32         echo Ignored: $1
33       fi
34   esac
35   shift
36 done
37
38 if [ "$name" = "" ] ; then
39   echo "Usage: gst-project-maker [OPTIONS] PROJECT_NAME"
40   exit 1
41 fi
42
43
44 PREFIX=$(echo $prefix | sed -e 's/\(.*\)/\U\1/')
45 NAME=$(echo $name | sed -e 's/\(.*\)/\U\1/')
46 Prefix=$(echo $prefix | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
47 Name=$(echo $name | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
48
49 if [ "$prefix" != "gst" ] ; then
50   cmdline_prefix="--prefix $prefix"
51 else
52   cmdline_prefix=""
53 fi
54
55 GST_IS_REPLACE=${PREFIX}_IS_${NAME}
56 GST_REPLACE=${PREFIX}_${NAME}
57 GST_TYPE_REPLACE=${PREFIX}_TYPE_${NAME}
58 GstReplace=${Prefix}${Name}
59 gst_replace=${prefix}_${name}
60 gst__replace=${prefix}-${name}
61 gstreplace=${prefix}$(echo $name | sed -e 's/_//g')
62 replace=$(echo $name | sed -e 's/_//g')
63
64 if [ "$REAL_NAME" = "" ] ; then
65   REAL_NAME=FIXME
66 fi
67 if [ "$EMAIL_ADDRESS" = "" ] ; then
68   EMAIL_ADDRESS=fixme@example.com
69 fi
70
71
72
73 basedir=`pwd`/$gst__replace
74
75 rm -rf $basedir
76 mkdir $basedir
77
78 cat >$basedir/AUTHORS <<EOF
79 $REAL_NAME <$EMAIL_ADDRESS>
80 EOF
81
82 cat >$basedir/COPYING <<EOF
83 Put your license here.
84 EOF
85
86 cat >$basedir/ChangeLog <<EOF
87 Put your changelog here.
88 EOF
89
90 cat >$basedir/NEWS <<EOF
91 News about your project.
92 EOF
93
94 cat >$basedir/README <<EOF
95 README for your project.
96 EOF
97
98 cat >$basedir/autogen.sh <<EOF
99 #!/bin/sh
100 # you can either set the environment variables AUTOCONF, AUTOHEADER, AUTOMAKE,
101 # ACLOCAL, AUTOPOINT and/or LIBTOOLIZE to the right versions, or leave them
102 # unset and get the defaults
103
104 autoreconf --verbose --force --install --make || {
105  echo 'autogen.sh failed';
106  exit 1;
107 }
108
109 ./configure || {
110  echo 'configure failed';
111  exit 1;
112 }
113
114 echo
115 echo "Now type 'make' to compile this module."
116 echo
117 EOF
118 chmod 755 $basedir/autogen.sh
119
120 cat >$basedir/configure.ac <<EOF
121 dnl required version of autoconf
122 AC_PREREQ([2.53])
123
124 dnl TODO: fill in your package name and package version here
125 AC_INIT([${gst__replace}],[0.10.0])
126
127 dnl required versions of gstreamer and plugins-base
128 GST_REQUIRED=0.10.16
129 GSTPB_REQUIRED=0.10.16
130
131 AC_CONFIG_SRCDIR([plugins/${gstreplace}.c])
132 AC_CONFIG_HEADERS([config.h])
133
134 dnl required version of automake
135 AM_INIT_AUTOMAKE([1.10])
136 AC_CONFIG_MACRO_DIR([m4])
137
138 dnl enable mainainer mode by default
139 AM_MAINTAINER_MODE([enable])
140
141 dnl check for tools (compiler etc.)
142 AC_PROG_CC
143 AM_PROG_CC_C_O
144
145 dnl required version of libtool
146 LT_PREREQ([2.2.6])
147 LT_INIT
148
149 dnl give error and exit if we don't have pkgconfig
150 AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, [ ], [
151   AC_MSG_ERROR([You need to have pkg-config installed!])
152 ])
153
154 dnl Check for the required version of GStreamer core (and gst-plugins-base)
155 dnl This will export GST_CFLAGS and GST_LIBS variables for use in Makefile.am
156 dnl
157 dnl If you need libraries from gst-plugins-base here, also add:
158 dnl for libgstaudio-0.10: gstreamer-audio-0.10 >= \$GST_REQUIRED
159 dnl for libgstvideo-0.10: gstreamer-video-0.10 >= \$GST_REQUIRED
160 dnl for libgsttag-0.10: gstreamer-tag-0.10 >= \$GST_REQUIRED
161 dnl for libgstpbutils-0.10: gstreamer-pbutils-0.10 >= \$GST_REQUIRED
162 dnl for libgstfft-0.10: gstreamer-fft-0.10 >= \$GST_REQUIRED
163 dnl for libgstinterfaces-0.10: gstreamer-interfaces-0.10 >= \$GST_REQUIRED
164 dnl for libgstrtp-0.10: gstreamer-rtp-0.10 >= \$GST_REQUIRED
165 dnl for libgstrtsp-0.10: gstreamer-rtsp-0.10 >= \$GST_REQUIRED
166 dnl etc.
167 PKG_CHECK_MODULES(GST, [
168   gstreamer-0.10 >= \$GST_REQUIRED
169   gstreamer-base-0.10 >= \$GST_REQUIRED
170   gstreamer-controller-0.10 >= \$GST_REQUIRED
171 ], [
172   AC_SUBST(GST_CFLAGS)
173   AC_SUBST(GST_LIBS)
174 ], [
175   AC_MSG_ERROR([
176       You need to install or upgrade the GStreamer development
177       packages on your system. On debian-based systems these are
178       libgstreamer0.10-dev and libgstreamer-plugins-base0.10-dev.
179       on RPM-based systems gstreamer0.10-devel, libgstreamer0.10-devel
180       or similar. The minimum version required is \$GST_REQUIRED.
181   ])
182 ])
183
184 dnl check if compiler understands -Wall (if yes, add -Wall to GST_CFLAGS)
185 AC_MSG_CHECKING([to see if compiler understands -Wall])
186 save_CFLAGS="\$CFLAGS"
187 CFLAGS="\$CFLAGS -Wall"
188 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ ], [ ])], [
189   GST_CFLAGS="\$GST_CFLAGS -Wall"
190   AC_MSG_RESULT([yes])
191 ], [
192   AC_MSG_RESULT([no])
193 ])
194
195 dnl set the plugindir where plugins should be installed (for plugins/Makefile.am)
196 if test "x\${prefix}" = "x\$HOME"; then
197   plugindir="\$HOME/.gstreamer-0.10/plugins"
198 else
199   plugindir="\\\$(libdir)/gstreamer-0.10"
200 fi
201 AC_SUBST(plugindir)
202
203 dnl set proper LDFLAGS for plugins
204 GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
205 AC_SUBST(GST_PLUGIN_LDFLAGS)
206
207 AC_CONFIG_FILES([Makefile plugins/Makefile tools/Makefile])
208 AC_OUTPUT
209 EOF
210
211 cat >$basedir/Makefile.am <<EOF
212 SUBDIRS = plugins tools
213
214 EXTRA_DIST = autogen.sh
215
216 ACLOCAL_AMFLAGS = -I m4
217 EOF
218
219 mkdir -p $basedir/m4
220
221 mkdir -p $basedir/plugins
222
223 cat >$basedir/plugins/Makefile.am <<EOF
224 plugin_LTLIBRARIES = lib$gstreplace.la
225
226 # sources used to compile this plug-in
227 lib${gstreplace}_la_SOURCES = ${gstreplace}plugin.c ${gstreplace}.c ${gstreplace}.h
228
229 # compiler and linker flags used to compile this plugin, set in configure.ac
230 lib${gstreplace}_la_CFLAGS = \$(GST_CFLAGS)
231 lib${gstreplace}_la_LIBADD = \$(GST_LIBS)
232 lib${gstreplace}_la_LDFLAGS = \$(GST_PLUGIN_LDFLAGS)
233 lib${gstreplace}_la_LIBTOOLFLAGS = --tag=disable-static
234
235 EOF
236
237
238 generate()
239 {
240 cat <<EOF
241 /*
242  * GStreamer
243  * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
244  * 
245  * Permission is hereby granted, free of charge, to any person obtaining a
246  * copy of this software and associated documentation files (the "Software"),
247  * to deal in the Software without restriction, including without limitation
248  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
249  * and/or sell copies of the Software, and to permit persons to whom the
250  * Software is furnished to do so, subject to the following conditions:
251  *
252  * The above copyright notice and this permission notice shall be included in
253  * all copies or substantial portions of the Software.
254  *
255  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
256  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
257  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
258  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
259  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
260  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
261  * DEALINGS IN THE SOFTWARE.
262  *
263  * Alternatively, the contents of this file may be used under the
264  * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
265  * which case the following provisions apply instead of the ones
266  * mentioned above:
267  *
268  * This library is free software; you can redistribute it and/or
269  * modify it under the terms of the GNU Library General Public
270  * License as published by the Free Software Foundation; either
271  * version 2 of the License, or (at your option) any later version.
272  *
273  * This library is distributed in the hope that it will be useful,
274  * but WITHOUT ANY WARRANTY; without even the implied warranty of
275  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
276  * Library General Public License for more details.
277  *
278  * You should have received a copy of the GNU Library General Public
279  * License along with this library; if not, write to the
280  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
281  * Boston, MA 02111-1307, USA.
282  */
283
284 #ifdef HAVE_CONFIG_H
285 #include <config.h>
286 #endif
287
288 #include <gst/gst.h>
289 #include "gstreplace.h"
290
291 static gboolean
292 plugin_init (GstPlugin * plugin)
293 {
294   gst_element_register (plugin, "replace", GST_RANK_NONE,
295       GST_TYPE_REPLACE);
296
297   return TRUE;
298 }
299
300 GST_PLUGIN_DEFINE (
301     GST_VERSION_MAJOR,
302     GST_VERSION_MINOR,
303     replace,
304     "FIXME Template plugin",
305     plugin_init,
306     VERSION,
307     "LGPL", /* FIXME */
308     "GStreamer",
309     "http://gstreamer.net/"
310 )
311 EOF
312 }
313
314
315 generate | sed \
316   -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
317   -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
318   -e "s/GstBaseReplace/$GstBaseReplace/g" \
319   -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
320   -e "s/GST_REPLACE/$GST_REPLACE/g" \
321   -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
322   -e "s/GstReplace/$GstReplace/g" \
323   -e "s/gst_replace/$gst_replace/g" \
324   -e "s/gstreplace/$gstreplace/g" \
325   -e "s/replace/$replace/g" >$basedir/plugins/${gstreplace}plugin.c
326
327 gst-indent $basedir/plugins/${gstreplace}plugin.c
328 rm -f $basedir/plugins/${gstreplace}plugin.c~
329
330 cat >$basedir/plugins/${gstreplace}.c <<EOF
331 /* This file should be replaced by element source generated by
332  * gst-element-maker, or by your own source code.  To generate suitable
333  * element source using gst-element-maker, run:
334  *
335  *   gst-element-maker $cmdline_prefix $replace BASE_CLASS
336  *
337  * Where BASE_CLASS is replaced by one of the base class templates,
338  * such as basesrc, basetransform, audiofilter, videofilter2, etc.
339  * Then copy the resulting $gstreplace.c file over this file, and
340  * $gstreplace.h over $gstreplace.h.
341  */
342 /* The rest of this file is shim code to allow the project to compile */
343 EOF
344
345 cat >$basedir/plugins/${gstreplace}.h <<EOF
346 /* This file should be replaced by element header generated by
347  * gst-element-maker, or by your own source code.  To generate suitable
348  * element header using gst-element-maker, run:
349  *
350  *   gst-element-maker $cmdline_prefix $replace BASE_CLASS
351  *
352  * Where BASE_CLASS is replaced by one of the base class templates,
353  * such as basesrc, basetransform, audiofilter, videofilter2, etc.
354  * Then copy the resulting $gstreplace.h file over this file, and
355  * $gstreplace.c over $gstreplace.c.
356  */
357 /* The rest of this file is shim code to allow the project to compile */
358 #define ${GST_TYPE_REPLACE} G_TYPE_NONE
359 EOF
360
361
362 mkdir -p $basedir/tools
363
364 cat >$basedir/tools/Makefile.am <<EOF
365 bin_PROGRAMS = ${gst__replace}
366
367 # sources used to compile this plug-in
368 ${gst_replace}_SOURCES = ${gstreplace}.c
369
370 # compiler and linker flags used to compile the program, set in configure.ac
371 ${gst_replace}_CFLAGS = \$(GST_CFLAGS)
372 ${gst_replace}_LDADD = \$(GST_LIBS)
373
374 EOF
375
376 cat >$basedir/tools/${gstreplace}.c <<EOF
377 /* This file should be replaced by application source generated by
378  * gst-app-maker, or by your own source code.  To generate suitable
379  * app source using gst-app-maker, run:
380  *
381  *   gst-app-maker $cmdline_prefix $replace
382  *
383  * Then copy the resulting $gstreplace.c file over this file.
384  */
385 /* The rest of this file is shim code to allow the project to compile */
386 #include <stdio.h>
387 int main (void) { printf ("FIXME\n"); return 0; }
388 EOF
389
390