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