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