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