]> git.sesse.net Git - vlc/blob - toolbox
79598333b559a49fb2ba8f0814e06f45bc94d616
[vlc] / toolbox
1 #! /bin/sh
2
3 ##  toolbox for the VLC media player
4 ##  $Id: toolbox,v 1.17 2003/03/18 01:54:40 sam Exp $
5 ##
6 ##  Authors: Samuel Hocevar <sam@zoy.org>
7
8 ###
9 ###  Get a sane environment, just in case
10 ###
11 LANG=C
12 export LANG
13 CYGWIN=binmode
14 export CYGWIN
15
16 ##
17 ##  Give help
18 ##
19 help()
20 {
21   cat << EOF
22 recognized flags are:
23   --update-changelog            update the CVS changelog
24   --update-vc                   update Microsoft Visual Studio files
25   --update-po                   update translation files
26   --update-includes [BUILTINS]  generate various include files
27   --update-glade                generate and fix Glade code
28   --update-glade2               generate and fix Glade 2 code
29 EOF
30   exit 1
31 }
32
33 ##
34 ##  Extract stuff from Makefile.am
35 ##
36 getfiles()
37 {
38   awk 'BEGIN{a=0}{if(!a&&/^'"$1"'[^-_a-zA-Z0-9]*=/){a=1;print$0;next;}if(a){if(/^[a-zA-Z]/){exit;}print $0}}' < Makefile.am | \
39     tr '\\ ' '\n\n' | \
40     sed -ne 's/[^-$_a-zA-Z0-9][^-$_a-zA-Z0-9]*\([a-zA-Z]\)/\1/p'
41 }
42
43 ###
44 ###  argument check
45 ###
46
47 if test "$1" = ""
48 then
49   help
50 fi
51
52 case "$1" in
53   --update-changelog)
54     action=changelog
55     ;;
56   --update-vc)
57     action=vc
58     ;;
59   --update-po)
60     action=po
61     ;;
62   --update-includes)
63     action=includes
64     ;;
65   --update-glade|--fix-glade)
66     action=glade
67     ;;
68   --update-glade2|--update-glade-2|--fix-glade2)
69     action=glade2
70     ;;
71   --help)
72     help
73     ;;
74   *)
75     echo "$0: unknown option $1"
76     help
77     ;;
78 esac
79 shift
80
81 ##
82 ##  Update the CVS changelog
83 ##
84 if test "${action}" = "changelog"
85 then
86   cvs2cl --help >/dev/null 2>&1 || exit 1
87   rm -f ChangeLog
88   cvs2cl --hide-filenames --no-wrap -w --stdout | \
89     sed -e 's/^[^0-9]/ /' -e 's/^  *$//' | \
90     uniq > ChangeLog
91   exit 0
92 fi
93
94 ##
95 ##  Update the MSVC project files
96 ##
97 if test "${action}" = "vc"
98 then
99   echo "generating Visual Studio files..."
100
101   #  The evil ^M
102   M='\r'
103
104   #  Variables we get from configure.ac.in
105   LIBVLC_VERSION=`sed -ne '/AC_INIT/s/.*,\(.*\))/\1/p' < configure.ac.in`
106   LIBVLC_CODENAME=`sed -ne '/CODENAME=/s/.*"\(.*\)"/\1/p' < configure.ac.in`
107   LIBVLC_SYMBOL=`echo $LIBVLC_VERSION | sed -e 'y/.-/__/'`
108
109   #  Sources that get built under Win32 - FIXME: anyone wanna deuglify this? :)
110   LIBVLC_SOURCES=`getfiles SOURCES_libvlc_common; getfiles SOURCES_libvlc_win32; getfiles SOURCES_libvlc_dirent; getfiles SOURCES_libvlc_getopt; getfiles SOURCES_libvlc_libc`
111
112   LIBVLC_HEADERS=`getfiles HEADERS_include; getfiles HEADERS_include_built`
113
114   LIBVLC_PKG_HEADERS=`getfiles dist_pkginclude_HEADERS`
115
116   # Clean up
117   rm -f evc/*.vcp msvc/*.dsp
118
119   # config files
120   for target in evc/config.h msvc/config.h
121   do
122     echo "${target}"
123     rm -f ${target}
124     sed -e "s/@CODENAME@/${LIBVLC_CODENAME}/" \
125         -e "s/@VERSION@/${LIBVLC_VERSION}/" \
126         -e "s/@SYMBOL@/${LIBVLC_SYMBOL}/" < ${target}.in > ${target}
127   done
128
129   # libvlc files
130   for target in evc/libvlc.vcp msvc/libvlc.dsp
131   do
132     echo "${target}"
133     #  Top of the project file
134     perl -pe 'if(/§SOURCES§/){last;}' < ${target}.in > ${target}
135     #  The source files
136     for file in `for i in ${LIBVLC_SOURCES} ; do echo $i ; done | grep -v "/.*/"`
137     do
138       cat >> ${target} << EOF
139 # Begin Source File${M}
140 SOURCE="..\\`echo $file | sed -e 's%/%\\\\%g'`"${M}
141 # ADD CPP /D "__VLC__" /D PLUGIN_PATH=\\".\\" /D DATA_PATH=\\"share\\"${M}
142 # End Source File${M}
143 EOF
144     done
145     for subdir in `for i in ${LIBVLC_SOURCES} ; do echo $i ; done | grep "/.*/" | cut -f2 -d/ | sort | uniq`
146     do
147       cat >> ${target} << EOF
148 # Begin Group "${subdir}"${M}
149 EOF
150       for file in `for i in ${LIBVLC_SOURCES} ; do echo $i ; done | grep "/${subdir}/"`
151       do
152       if test "${target}" = "evc/libvlc.vcp"
153       then
154         cat >> ${target} << EOF
155 # Begin Source File${M}
156 SOURCE="..\\`echo $file | sed -e 's%/%\\\\%g'`"${M}
157 # ADD CPP /D "__VLC__" /D PLUGIN_PATH=\\".\\" /D DATA_PATH=\\"share\\"${M}
158 !IF "\$(CFG)" == "libvlc - Win32 (WCE MIPS) Release"${M}
159 # PROP Output_Dir "MIPSRel\\${subdir}"${M}
160 # PROP Intermediate_Dir "MIPSRel\\${subdir}"${M}
161 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE MIPS) Debug"${M}
162 # PROP Output_Dir "MIPSDbg\\${subdir}"${M}
163 # PROP Intermediate_Dir "MIPSDbg\\${subdir}"${M}
164 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE SH4) Release"${M}
165 # PROP Output_Dir "SH4Rel\\${subdir}"${M}
166 # PROP Intermediate_Dir "SH4Rel\\${subdir}"${M}
167 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE SH4) Debug"${M}
168 # PROP Output_Dir "SH4Dbg\\${subdir}"${M}
169 # PROP Intermediate_Dir "SH4Dbg\\${subdir}"${M}
170 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE SH3) Release"${M}
171 # PROP Output_Dir "SH3Rel\\${subdir}"${M}
172 # PROP Intermediate_Dir "SH3Rel\\${subdir}"${M}
173 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE SH3) Debug"${M}
174 # PROP Output_Dir "SH3Dbg\\${subdir}"${M}
175 # PROP Intermediate_Dir "SH3Dbg\\${subdir}"${M}
176 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE ARM) Release"${M}
177 # PROP Output_Dir "ARMRel\\${subdir}"${M}
178 # PROP Intermediate_Dir "ARMRel\\${subdir}"${M}
179 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE ARM) Debug"${M}
180 # PROP Output_Dir "ARMDbg\\${subdir}"${M}
181 # PROP Intermediate_Dir "ARMDbg\\${subdir}"${M}
182 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE x86em) Release"${M}
183 # PROP Output_Dir "X86EMRel\\${subdir}"${M}
184 # PROP Intermediate_Dir "X86EMRel\\${subdir}"${M}
185 !ELSEIF "\$(CFG)" == "libvlc - Win32 (WCE x86em) Debug"${M}
186 # PROP Output_Dir "X86EMDbg\\${subdir}"${M}
187 # PROP Intermediate_Dir "X86EMDbg\\${subdir}"${M}
188 !ENDIF${M}
189 # End Source File${M}
190 EOF
191         else
192           cat >> ${target} << EOF
193 # Begin Source File${M}
194 SOURCE="..\\`echo $file | sed -e 's%/%\\\\%g'`"${M}
195 # ADD CPP /D "__VLC__" /D PLUGIN_PATH=\\".\\" /D DATA_PATH=\\"share\\"${M}
196 !IF "\$(CFG)" == "libvlc - Win32 Release"${M}
197 # PROP Output_Dir "Release\\${subdir}"${M}
198 # PROP Intermediate_Dir "Release\\${subdir}"${M}
199 !ELSEIF "\$(CFG)" == "libvlc - Win32 Debug"${M}
200 # PROP Output_Dir "Debug\\${subdir}"${M}
201 # PROP Intermediate_Dir "Debug\\${subdir}"${M}
202 !ENDIF${M}
203 # End Source File${M}
204 EOF
205         fi
206       done
207       cat >> ${target} << EOF
208 # End Group${M}
209 EOF
210     done
211     #  The headers
212     perl -e 'while(<>){if(/§SOURCES§/){last;}}while(<>){if(/§HEADERS§/){last;}print $_}' < ${target}.in >> ${target}
213     for file in ${LIBVLC_HEADERS}
214     do
215       cat >> ${target} << EOF
216 # Begin Source File${M}
217 SOURCE="..\\`echo $file | sed -e 's%/%\\\\%g'`"${M}
218 # End Source File${M}
219 EOF
220     done
221     cat >> ${target} << EOF
222 # Begin Group "vlc"${M}
223 EOF
224     for file in ${LIBVLC_PKG_HEADERS}
225     do
226       cat >> ${target} << EOF
227 # Begin Source File${M}
228 SOURCE="..\\`echo $file | sed -e 's%/%\\\\%g'`"${M}
229 # End Source File${M}
230 EOF
231     done
232     cat >> ${target} << EOF
233 # End Group${M}
234 EOF
235     perl -e 'while(<>){if(/§HEADERS§/){last;}}while(<>){print $_}' < ${target}.in >> ${target}
236   done
237
238   # plugins files
239   grep '^L_[^ ]*_pic =' Modules.am | while read a b c
240   do
241     makefile="`echo $c | sed -e 's@/[^/]*$@/Modules.am@'`"
242     plugin="`echo $a | sed 's/L_\(.*\)_pic/\1/'`"
243     # this is an attempt at getting a list of plugin sources... we take the
244     # production and remove everything that does not contain "module", which
245     # means you miss $(NULL), but other variables too.
246     cfiles=`grep -v '[^-_a-zA-Z0-9]*#' ${makefile} | awk 'BEGIN{a=0}{if(!a&&/^SOURCES_'${plugin}'[^-_a-zA-Z0-9]*=/){a=1;print$0;next;}if(a){if(/^[a-zA-Z]/){exit;}print $0}}' | tr '\\ ' '\n\n' | sed -ne 's,/,\\\\,g; s/.*modules/modules/p'`
247     hfiles=`for i in ${cfiles} ; do echo $i ; done | grep '\.h$'`
248     cfiles=`for i in ${cfiles} ; do echo $i ; done | grep -v '\.h$'`
249     for dir in evc msvc
250     do
251       test "${dir}" = "evc" && suf="vcp" || suf="dsp"
252       source="${dir}/plugins.${suf}.in"
253       target="${dir}/plugin_${plugin}.${suf}"
254       echo "${target}"
255       perl -pe 'if(/§SOURCES§/){last;} s/§PLUGIN§/'${plugin}'/g' < ${source} > ${target}
256       for cfile in ${cfiles}
257       do
258         cat >> ${target} << EOF
259 # Begin Source File${M}
260 SOURCE="..\\${cfile}"${M}
261 # ADD CPP /D "__VLC__" /D "__PLUGIN__"  /D "MODULE_NAME=${plugin}" /D "MODULE_NAME_IS_${plugin}" ${M}
262 # End Source File${M}
263 EOF
264       done
265       # sed is really nicer for this... unfortunately it's broken under cygwin
266       # sed -ne '1,/§SOURCES§/d; /§HEADERS§/,$d; p' < ${source} >> ${target}
267       perl -e 'while(<>){if(/§SOURCES§/){last;}}while(<>){if(/§HEADERS§/){last;}print $_}' < ${source} >> ${target}
268       for hfile in ${hfiles}
269       do
270         cat >> ${target} << EOF
271 # Begin Source File${M}
272 SOURCE="..\\${hfile}"${M}
273 # End Source File${M}
274 EOF
275       done
276       # sed -ne '1,/§HEADERS§/d; p' < ${source} >> ${target}
277       perl -e 'while(<>){if(/§HEADERS§/){last;}}while(<>){print $_}' < ${source} >> ${target}
278     done
279   done
280
281   # vlc files
282   for target in evc/vlc.vcp msvc/vlc.dsp
283   do
284     echo "${target}"
285     #  Top of the project file
286     perl -pe 'if(/§SOURCES§/){last;}' < ${target}.in > ${target}
287     #  The source files
288     if test "${target}" = "evc/vlc.vcp"
289     then
290       cat >> ${target} << EOF
291 # Begin Source File${M}
292 SOURCE="..\\evc\\vlc.c"${M}
293 # End Source File${M}
294 EOF
295     else
296       cat >> ${target} << EOF
297 # Begin Source File${M}
298 SOURCE="..\\src\\vlc.c"${M}
299 # End Source File${M}
300 EOF
301     fi
302     #  Bottom of the project file - handles resource files too
303     perl -e 'while(<>){if(/§SOURCES§/){last;}}while(<>){print $_}' < ${target}.in >> ${target}
304   done
305
306   echo "done."
307   exit 0
308 fi
309
310 ##
311 ##  Update the potfiles because no one ever does it
312 ##
313 if test "${action}" = "po"
314 then
315   # create a fake file containing win32 strings
316   rm -f modules/gui/win32/strings.cpp
317   printf "/* Automatically generated by 'toolbox --update-po', please don't compile */\n" > modules/gui/win32/strings.cpp
318   find modules/gui/win32 -name '*.dfm' | while read file
319   do
320     printf "\n/*\n * from $file:\n */\n\n" >> modules/gui/win32/strings.cpp
321     perl -ne 'chop; chop; if( / (Caption|Text|Hint) / || $buffer =~ /[+=] *$/ ) { $buffer =~ s/\+ *$//; $buffer .= $_; } if( $buffer =~ /'"'"' *$/) { $buffer =~ s/'"'"'/"/g; $buffer =~ s/\\/\\\\/g; $buffer =~ s/=/= _(/; print $buffer." );\n"; $buffer = "";}' < $file | grep -v '"-*"' | grep -v '"http://' | grep -v '"vlcs"' >> modules/gui/win32/strings.cpp || exit 1
322   done
323   # clean old potfiles
324   cd po
325   rm -f vlc.pot
326   # update
327   make vlc.pot || exit 1
328   make update-po || exit 1
329   cd ..
330
331   exit 0
332 fi
333
334 ##
335 ##  Create include files
336 ##
337 if test "${action}" = "includes"
338 then
339   set -x
340
341   LIBVLC_HEADERS=`getfiles HEADERS_include`
342   BUILTINS=`while test $# -gt 0; do echo $1; shift; done`
343
344   file=include/vlc_symbols.h
345
346   rm -f ${file}.in
347   echo '/* DO NOT EDIT THIS FILE! See Makefile.am */' >> ${file}.in
348   echo 'struct module_symbols_t {' >> ${file}.in
349   cat ${LIBVLC_HEADERS} | grep '^ *VLC_EXPORT.*;' | sed -e 's/VLC_EXPORT( *\([^,]*\), *\([^,]*\), *\(.*\));.*/    \1 (* \2_inner) \3;/' >> ${file}.in
350   echo '};' >> ${file}.in
351   echo '#ifdef __PLUGIN__' >> ${file}.in
352   cat ${LIBVLC_HEADERS} | grep '^ *VLC_EXPORT.*;' | sed -e 's/VLC_EXPORT( *\([^,]*\), *\([^,]*\), *\(.*\));.*/#   define \2 p_symbols->\2_inner/' >> ${file}.in
353   echo '#endif /* __PLUGIN__ */' >> ${file}.in
354   if ! diff -q ${file} ${file}.in
355   then
356     mv -f ${file}.in ${file}
357   else
358     rm -f ${file}.in
359   fi
360
361   file=src/misc/modules_plugin.h
362
363   rm -f ${file}.tmp && cp ${file}.in ${file}.tmp
364   sed -e 's#.*\$[I][d]:.*# * Automatically generated from '${file}'.in by bootstrap#' < ${file}.in > ${file}.tmp
365   echo '#define STORE_SYMBOLS( p_symbols ) \' >> ${file}.tmp
366   cat ${LIBVLC_HEADERS} | grep '^ *VLC_EXPORT.*;' | sed -e 's/VLC_EXPORT( *\([^,]*\), *\([^,]*\), *\(.*\));.*/    (p_symbols)->\2_inner = \2; \\/' >> ${file}.tmp
367   echo '' >> ${file}.tmp
368   if ! diff -q ${file} ${file}.tmp
369   then
370     mv -f ${file}.tmp ${file}
371   else
372     rm -f ${file}.tmp
373   fi
374
375   file=src/misc/modules_builtin.h
376
377   rm -f ${file}.tmp && cp ${file}.in ${file}.tmp
378   if test "${BUILTINS}" != ""
379   then
380     for i in `echo ${BUILTINS}`
381     do
382       echo "int vlc_entry__`echo $i | sed -e 'y@/@_@' -e 's@\..*@@'`( module_t* );" >>${file}.tmp
383     done
384     echo "" >> ${file}.tmp
385   fi
386   echo "#define ALLOCATE_ALL_BUILTINS() \\" >> ${file}.tmp
387   echo "    do \\" >> ${file}.tmp
388   echo "    { \\" >> ${file}.tmp
389   if test "${BUILTINS}" != ""
390   then
391     for i in `echo ${BUILTINS}`
392     do
393       echo "        ALLOCATE_BUILTIN(`echo $i | sed -e 'y@/@_@' -e 's@\..*@@'`); \\" >> ${file}.tmp
394     done
395   fi
396   echo "    } while( 0 );" >> ${file}.tmp
397   echo "" >> ${file}.tmp
398   if ! diff -q ${file} ${file}.tmp
399   then
400     mv -f ${file}.tmp ${file}
401   else
402     rm -f ${file}.tmp
403   fi
404
405   exit 0
406 fi
407
408 ##
409 ##  Fix glade-generated files
410 ##
411 if test "${action}" = "glade"
412 then
413   for file in modules/gui/gtk/gnome.glade modules/gui/gtk/gtk.glade modules/gui/familiar/familiar.glade
414   do
415     echo "generating code from $file"
416     glade -w $file || exit 1
417   done
418
419   for file in modules/gui/gtk/gnome_interface.c modules/gui/gtk/gtk_interface.c modules/gui/familiar/interface.c
420   do
421     echo "fixing $file"
422     if grep "DO NOT EDIT THIS FILE" $file 2>&1 > /dev/null
423     then
424       rm -f $file.$$.bak
425       cat > $file.$$.bak << EOF
426 /* This file was created automatically by glade and fixed by bootstrap */
427
428 #include <vlc/vlc.h>
429 EOF
430       sed -e 1,7d \
431           -e 's#_(\(".:..:.."\))#\1#' \
432           -e 's#_(\("[a-z0-9]*://[^"]*"\))#\1#' \
433           -e 's#_("---")#"---"#' \
434           -e 's#_("--")#"--"#' \
435           -e 's#_("/dev/dvd")#"/dev/dvd"#' \
436           -e 's#_(\("./."\))#\1#' \
437           < $file >> $file.$$.bak
438       mv -f $file.$$.bak $file
439     fi
440   done
441
442   for file in modules/gui/gtk/gtk_support.h modules/gui/familiar/support.h
443   do
444     echo "fixing $file"
445     if grep "DO NOT EDIT THIS FILE" $file 2>&1 > /dev/null
446     then
447       rm -f $file.$$.bak
448       sed -e 's/DO NOT EDIT.*/Created by glade, fixed by bootstrap/' \
449           -e 's,<config.h>,<vlc/vlc.h>,' \
450           -e 's,#if.*ENABLE_NLS.*,#if 0 /* Disabled by bootstrap */,' \
451           -e 's,#else,/* & */,' \
452           < $file > $file.$$.bak
453       mv -f $file.$$.bak $file
454     fi
455   done
456
457   exit 0
458 fi
459
460 ##
461 ##  Fix glade2-generated files
462 ##
463 if test "${action}" = "glade2"
464 then
465   for file in modules/gui/gtk2/gnome2.glade modules/gui/gtk2/gtk2.glade
466   do
467     echo "generating code from $file"
468     glade-2 -w $file || exit 1
469   done
470
471   exit 0
472 fi
473