Merging gst-plugins-bad
[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: $(basename "$0") [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: '$(basename "$0") 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: $(basename "$0") [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
97 NOTE:
98 plugins can be installed locally by using "\$HOME" as prefix:
99
100   $ meson --prefix="\$HOME" build/
101   $ ninja -C build/ install
102
103 However be advised that the automatic scan of plugins in the user home
104 directory won't work under gst-build devenv.
105 EOF
106
107 cat >$basedir/meson.build <<EOF
108 project('${gst__replace}', 'c',
109   version : '0.1.0',
110   default_options : [ 'warning_level=1',
111                       'buildtype=debugoptimized' ])
112
113 core_conf = configuration_data()
114 core_conf.set('PACKAGE', '"@0@"'.format(meson.project_name()))
115 core_conf.set('VERSION', '"@0@"'.format(meson.project_version()))
116
117 configure_file(output : 'config.h', configuration : core_conf)
118
119 configinc = include_directories('.')
120
121 common_args = ['-DHAVE_CONFIG_H']
122
123 gst_req = '>= 1.0.0'
124
125 # Check for the required version of GStreamer core (and gst-plugins-base)
126 #
127 # If you need libraries from gst-plugins-base here, also add:
128 # for libgstaudio-1.0: gstreamer-audio-1.0
129 # for libgstvideo-1.0: gstreamer-video-1.0
130 # for libgsttag-1.0: gstreamer-tag-1.0
131 # for libgstpbutils-1.0: gstreamer-pbutils-1.0
132 # for libgstfft-1.0: gstreamer-fft-1.0
133 # for libgstinterfaces-1.0: gstreamer-interfaces-1.0
134 # for libgstrtp-1.0: gstreamer-rtp-1.0
135 # for libgstrtsp-1.0: gstreamer-rtsp-1.0
136 # etc.
137 gst_dep = dependency('gstreamer-1.0', version : gst_req,
138   fallback : ['gstreamer', 'gst_dep'])
139 gst_base_dep = dependency('gstreamer-base-1.0', version : gst_req,
140   fallback : ['gstreamer', 'gst_base_dep'])
141
142 # Set the directory where plugins should be installed.
143 #
144 # If the prefix is the user home directory, adjust the plugin installation
145 # path so that GStreamer can find it. Requires meson >= 0.53.0
146 fs = import('fs')
147 if fs.is_samepath(get_option('prefix'), '~')
148   plugins_install_dir = '@0@/.local/share/gstreamer-1.0/plugins'.format(get_option('prefix'))
149 else
150   plugins_install_dir = '@0@/gstreamer-1.0'.format(get_option('libdir'))
151 endif
152
153 plugin_deps = [gst_dep, gst_base_dep]
154 tool_deps = [gst_dep]
155
156 subdir('plugins')
157 subdir('tools')
158 EOF
159
160
161 mkdir -p $basedir/plugins
162
163 cat >$basedir/plugins/meson.build <<EOF
164 lib_args = common_args + []
165
166 # sources used to compile this plug-in
167 plugin_sources = [
168   '${gstreplace}plugin.c',
169   '${gstreplace}.c',
170   '${gstreplace}.h'
171 ]
172
173 shlib = shared_library('${gstreplace}',
174   plugin_sources,
175   c_args : lib_args,
176   include_directories: [configinc],
177   dependencies : plugin_deps,
178   gnu_symbol_visibility : 'hidden',
179   install : true,
180   install_dir : plugins_install_dir,
181 )
182
183 # Make this library usable as a Meson subproject.
184 gst_${replace}_dep = declare_dependency(
185   include_directories: include_directories('.'),
186   link_with : shlib)
187
188 pkg_mod = import('pkgconfig')
189 pkg_mod.generate(
190   name : '${gst__replace}',
191   filebase : '${gst__replace}',
192   description : 'Meson sample project.',
193   subdirs : 'src',
194   libraries : shlib,
195   version : '"@0@"'.format(meson.project_version()),
196 )
197 EOF
198
199
200 generate()
201 {
202 cat <<EOF
203 /*
204  * GStreamer
205  * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
206  *
207  * Permission is hereby granted, free of charge, to any person obtaining a
208  * copy of this software and associated documentation files (the "Software"),
209  * to deal in the Software without restriction, including without limitation
210  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
211  * and/or sell copies of the Software, and to permit persons to whom the
212  * Software is furnished to do so, subject to the following conditions:
213  *
214  * The above copyright notice and this permission notice shall be included in
215  * all copies or substantial portions of the Software.
216  *
217  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
218  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
219  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
220  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
221  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
222  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
223  * DEALINGS IN THE SOFTWARE.
224  *
225  * Alternatively, the contents of this file may be used under the
226  * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
227  * which case the following provisions apply instead of the ones
228  * mentioned above:
229  *
230  * This library is free software; you can redistribute it and/or
231  * modify it under the terms of the GNU Library General Public
232  * License as published by the Free Software Foundation; either
233  * version 2 of the License, or (at your option) any later version.
234  *
235  * This library is distributed in the hope that it will be useful,
236  * but WITHOUT ANY WARRANTY; without even the implied warranty of
237  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
238  * Library General Public License for more details.
239  *
240  * You should have received a copy of the GNU Library General Public
241  * License along with this library; if not, write to the
242  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
243  * Boston, MA 02110-1301, USA.
244  */
245
246 #ifdef HAVE_CONFIG_H
247 #include <config.h>
248 #endif
249
250 #include <gst/gst.h>
251 #include "gstreplace.h"
252
253 static gboolean
254 plugin_init (GstPlugin * plugin)
255 {
256   gst_element_register (plugin, "replace", GST_RANK_NONE,
257       GST_TYPE_REPLACE);
258
259   return TRUE;
260 }
261
262 GST_PLUGIN_DEFINE (
263     GST_VERSION_MAJOR,
264     GST_VERSION_MINOR,
265     replace,
266     "FIXME Template plugin",
267     plugin_init,
268     VERSION,
269     "LGPL", /* FIXME */
270     "GStreamer",
271     "http://gstreamer.net/"
272 )
273 EOF
274 }
275
276
277 generate | sed \
278   -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
279   -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
280   -e "s/GstBaseReplace/$GstBaseReplace/g" \
281   -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
282   -e "s/GST_REPLACE/$GST_REPLACE/g" \
283   -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
284   -e "s/GstReplace/$GstReplace/g" \
285   -e "s/gst_replace/$gst_replace/g" \
286   -e "s/gstreplace/$gstreplace/g" \
287   -e "s/replace/$replace/g" >$basedir/plugins/${gstreplace}plugin.c
288
289 gst-indent $basedir/plugins/${gstreplace}plugin.c || echo "Warning: could not run gst-indent on the generated code." 1>&2
290 rm -f $basedir/plugins/${gstreplace}plugin.c~
291
292 cat >$basedir/plugins/${gstreplace}.c <<EOF
293 /* This file should be replaced by element source generated by
294  * gst-element-maker, or by your own source code.  To generate suitable
295  * element source using gst-element-maker, run:
296  *
297  *   gst-element-maker $cmdline_prefix $replace BASE_CLASS
298  *
299  * Where BASE_CLASS is replaced by one of the base class templates,
300  * such as basesrc, basetransform, audiofilter, videofilter2, etc.
301  * Then copy the resulting $gstreplace.c file over this file, and
302  * $gstreplace.h over $gstreplace.h.
303  */
304 /* The rest of this file is shim code to allow the project to compile */
305 EOF
306
307 cat >$basedir/plugins/${gstreplace}.h <<EOF
308 /* This file should be replaced by element header generated by
309  * gst-element-maker, or by your own source code.  To generate suitable
310  * element header using gst-element-maker, run:
311  *
312  *   gst-element-maker $cmdline_prefix $replace BASE_CLASS
313  *
314  * Where BASE_CLASS is replaced by one of the base class templates,
315  * such as basesrc, basetransform, audiofilter, videofilter2, etc.
316  * Then copy the resulting $gstreplace.h file over this file, and
317  * $gstreplace.c over $gstreplace.c.
318  */
319 /* The rest of this file is shim code to allow the project to compile */
320 #define ${GST_TYPE_REPLACE} G_TYPE_NONE
321 EOF
322
323
324 mkdir -p $basedir/tools
325
326 cat >$basedir/tools/meson.build <<EOF
327 exe_args = common_args + []
328
329 # sources used to compile this program
330 tool_sources = [
331   '${gstreplace}.c',
332 ]
333
334 executable('${gstreplace}',
335   tool_sources,
336   install: true,
337   c_args : exe_args,
338   include_directories: [configinc],
339   dependencies : tool_deps,
340 )
341 EOF
342
343 cat >$basedir/tools/${gstreplace}.c <<EOF
344 /* This file should be replaced by application source generated by
345  * gst-app-maker, or by your own source code.  To generate suitable
346  * app source using gst-app-maker, run:
347  *
348  *   gst-app-maker $cmdline_prefix $replace
349  *
350  * Then copy the resulting $gstreplace.c file over this file.
351  */
352 /* The rest of this file is shim code to allow the project to compile */
353 #include <stdio.h>
354 int main (void) { printf ("FIXME\n"); return 0; }
355 EOF