]> git.sesse.net Git - vlc/blob - bootstrap
Portability fix: use head -n 1 iso head -1
[vlc] / bootstrap
1 #! /bin/sh
2
3 ##  bootstrap file for the VLC media player
4 ##
5 ## Copyright (C) 2005-2006 the VideoLAN team
6 ##
7 ##  Authors: Sam Hocevar <sam@zoy.org>
8 ##           RĂ©mi Denis-Courmont <rem # videolan # org>
9
10 if test "$#" != "0"; then
11   echo "Usage: $0"
12   echo "  Calls automake, autoconf, autoheader, autopoint and other auto* to generate"
13   echo "  m4 macros and prepare Makefiles."
14   exit 1
15 fi
16
17 ###
18 ###  Get a sane environment, just in case
19 ###
20 LANG=C
21 export LANG
22 CYGWIN=binmode
23 export CYGWIN
24
25 set -e
26 set -x
27
28 ##
29 ## Check for various tools
30 ##
31 AUTOMAKESUCKS=no
32 INSTALLSUCKS=no
33
34 ACLOCAL_ARGS="-I m4 ${ACLOCAL_ARGS}"
35
36 # Check for contrib directory
37 if test -d extras/contrib/bin; then
38   export PATH="`pwd`/extras/contrib/bin:$PATH"
39   if test -d extras/contrib/share/aclocal; then
40     ACLOCAL_ARGS="${ACLOCAL_ARGS} -I extras/contrib/share/aclocal"
41   fi
42   if test ".`uname -s`" = ".Darwin"; then
43     # Make sure contrib has been built
44     if test ! -e ./extras/contrib/config.mak; then
45         set +x
46         echo ""
47         echo "ERR: Contribs haven't been built"
48         echo "ERR: Please run:"
49         echo ""
50         echo "ERR:    'cd extras/contrib && ./bootstrap && make && cd ../..'"
51         echo ""
52         echo "ERR: Make sure fink has been disabled too"
53         echo ""
54         set -x
55         exit 1
56     fi
57     export LD_LIBRARY_PATH=./extras/contrib/lib:$LD_LIBRARY_PATH
58     export DYLD_LIBRARY_PATH=./extras/contrib/lib:$DYLD_LIBRARY_PATH
59   elif test ".`uname -s`" = ".BeOS"; then
60     export LIBRARY_PATH=./extras/contrib/lib:$LIBRARY_PATH
61     export BELIBRARIES=./extras/contrib/lib:$BELIBRARIES
62   fi
63 fi
64
65 # Check for autoconf
66 rm -f m4/autoconf260.m4
67 case "$(autoconf --version|head -n 1)" in
68   *2.5[012345678]*)
69     echo "Hey, your autoconf is quite old. Update it." >&2
70     exit 1
71     ;;
72
73   *2.59*)
74     echo "Enabling provisional autoconf 2.59 work-around. Update autoconf ASAP."
75     cp -f extras/m4/autoconf260.m4 m4/
76     ;;
77 esac
78
79 # Check for automake
80 amvers="no"
81 for v in "-1.10" "110" "-1.9" "19"; do
82   if automake${v} --version >/dev/null 2>&1; then
83     amsuff="${v}"
84     amvers="`echo ${v} | sed -e 's/^-//'`"
85     break
86   fi
87 done
88
89 if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then
90   amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`"
91   amsuff=""
92 fi
93
94 case "${amvers}" in
95   no|1.[012345678]|1.[0123456].*|1[0123456]|1.[0123456]-*)
96     set +x
97     echo "$0: you need automake version 1.9 or later"
98     exit 1
99     ;;
100 esac
101
102 # Check for libtool
103 libtoolize="no"
104 if glibtoolize --version >/dev/null 2>&1; then
105   libtoolize="glibtoolize"
106 elif libtoolize --version >/dev/null 2>&1; then
107   libtoolize="libtoolize"
108 fi
109
110 if test "$libtoolize" = "no"; then
111   set +x
112   echo "$0: you need libtool"
113   exit 1
114 fi
115
116 # Check for gettext
117 if gettextize --version >/dev/null 2>&1; then
118 # Autopoint is available from 0.11.3, but we need 0.11.5
119 if expr `gettextize --version | sed -e '1s/[^0-9]*//' -e q` \
120         '>=' 0.11.5 >/dev/null 2>&1; then
121   # We have gettext, and a recent version! Everything is cool.
122   autopoint=autopoint
123   GETTEXT=yes
124 else
125   # User's gettext is too old. try to continue anyway.
126   autopoint=:
127   GETTEXT=old
128 fi;else
129   set +x
130   echo "you need gettextize (package gettext-devel or gettext)"
131   exit 1
132 fi
133
134 # Check for pkg-config
135 if pkg-config --version >/dev/null 2>&1; then
136   # We have pkg-config, everything is cool.
137   PKGCONFIG=yes
138 else
139   PKGCONFIG=no
140 fi
141
142 aclocal=aclocal${amsuff}
143 automake=automake${amsuff}
144 autoconf=autoconf
145 autoheader=autoheader
146
147 ##
148 ## Generate the modules makefile, by parsing modules/**/Modules.am
149 ##
150
151 set +x
152 echo "generating modules/**/Makefile.am and m4/private.m4"
153
154 # Prepare m4/private.m4
155 rm -f m4/private.m4 && cat > m4/private.m4 << EOF
156 dnl  Private VLC macros - generated by bootstrap
157
158 EOF
159
160 if [ "${PKGCONFIG}" = "no" ]; then cat >> m4/private.m4 << EOF
161 dnl  User does not have pkg-config, so assume package was not found
162 AC_DEFUN([PKG_CHECK_MODULES],[ifelse([\$4], , :, [\$4])])
163
164 EOF
165 fi
166
167 if [ "${GETTEXT}" != "yes" ]; then cat >> m4/private.m4 << EOF
168 dnl  User does not have gettext, so this is a no-op
169 AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
170
171 EOF
172 fi
173
174 rm -f m4/private.m4-tmp1 && cat > m4/private.m4-tmp1 << EOF
175 dnl  The required AM_CONDITIONAL calls
176 dnl  XXX: too many conditionals make the build very slow, disabled them
177 AC_DEFUN([VLC_CONDITIONALS], [
178 EOF
179 rm -f m4/private.m4-tmp2 && cat > m4/private.m4-tmp2 << EOF
180 dnl  The required AC_SUBST calls
181 AC_DEFUN([VLC_SUBSTS], [
182 EOF
183 rm -f m4/private.m4-tmp3 && cat > m4/private.m4-tmp3 << EOF
184 dnl  The required AC_OUTPUT calls
185 dnl  XXX: this feature is only supported starting from automake-1.7
186 AC_DEFUN([VLC_MAKEFILES], [AC_OUTPUT([
187 EOF
188 rm -f m4/private.m4-tmp4 && cat > m4/private.m4-tmp4 << EOF
189 dnl  Helper macro for vlc-config generation
190 AC_DEFUN([VLC_CONFIG_HELPER], [
191   cat >> vlc-config.in << BLAH
192 EOF
193
194 modules=""
195
196 rm -f modules/Makefile.am && cat > modules/Makefile.am << EOF
197 # Autogenerated by bootstrap - DO NOT EDIT
198 EXTRA_DIST = LIST
199 SUBDIRS = `sed -ne 's,modules/\([^/]*\)/Makefile,\1,p' configure.ac | xargs`
200 EOF
201
202 for dir in `sed -ne 's,modules/\(.*\)/Makefile,\1,p' configure.ac`
203 do
204   printf "."
205   modf="modules/${dir}/Modules.am"
206   makf="modules/${dir}/Makefile.am"
207   basedir="`echo "${dir}" | cut -f1 -d/`"
208   # automake will not recurse for make dist if we don't define SUBDIRS = .
209   subdirs="`sed -ne 's,'modules/${dir}'/\([^/]*\)/Makefile,\1,p' configure.ac | xargs`"
210   mods="`sed -n -e 's/^ *SOURCES_\([^ ]*\).*/\1/p' < "${modf}" | xargs`"
211   extra_libs=""
212   extra_ltlibs=""
213   for mod in $mods
214   do
215     extra_libs="${extra_libs} lib${mod}_plugin.a lib${mod}.a"
216     extra_ltlibs="${extra_ltlibs} lib${mod}_plugin.la"
217   done
218   rm -f "${makf}" && cat > "${makf}" << EOF
219
220 # ${makf} automatically generated from ${modf} by bootstrap
221 # DO NOT EDIT - edit Modules.am or \$(top_srcdir)/bootstrap instead
222
223 basedir = ${basedir}
224 mods = ${mods}
225
226 NULL =
227 libvlc_LTLIBRARIES =
228 noinst_LTLIBRARIES =
229 EXTRA_DIST = Modules.am
230 BUILT_SOURCES =
231 clean_modules =
232 SUBDIRS = ${subdirs}
233 SUFFIXES = _plugin\$(LIBEXT) _plugin.a
234
235 libvlcdir = \$(libdir)/vlc/\$(basedir)
236
237 EXTRA_LIBRARIES = ${extra_libs}
238 EXTRA_LTLIBRARIES = ${extra_ltlibs}
239
240 include Modules.am
241
242 LTLIBVLC = \$(top_builddir)/src/libvlc.la
243
244 if HAVE_WIN32
245 LIBVLC = -L\$(top_builddir)/src -lvlc
246 LIBADD = \$(LIBVLC)
247 endif
248
249 all: all-modules
250
251 nice:
252         \$(top_builddir)/compile
253
254 # Find out which modules were enabled and tell make to build them
255 all-modules:
256 if USE_LIBTOOL
257         @set fnord \$\$MAKEFLAGS; amf=\$\$2; targets=\`\\
258         z=\$\$(\$(VLC_CONFIG) --list plugin); for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo lib\$\${mod}_plugin.la;; esac; done; \\
259         \`; case "\$\$targets" in *lib*) \$(MAKE) \$(AM_MAKEFLAGS) \$\$targets || case "\$\$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; ;; esac; \\
260         test -z "\$\$fail"
261 else
262         @set fnord \$\$MAKEFLAGS; amf=\$\$2; targets=\`\\
263         z=\$\$(\$(VLC_CONFIG) --list plugin); for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo lib\$\${mod}_plugin\$(LIBEXT);; esac; done; \\
264         z=\$\$(\$(VLC_CONFIG) --list builtin); for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo lib\$\${mod}.a;; esac; done; \\
265         \`; case "\$\$targets" in *lib*) \$(MAKE) \$(AM_MAKEFLAGS) \$\$targets || case "\$\$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; ;; esac; \\
266         test -z "\$\$fail"
267 endif
268
269 # Build a plugin with the adequate linker and linker's flags
270 _plugin.a_plugin\$(LIBEXT):
271         @mod="\$*" ; mod=\$\${mod#lib} ; \
272         ldfl="\`\$(VLC_CONFIG) --libs plugin \$\$mod\` \$(LIBADD) -u \$(SYMPREF)\$(VLC_ENTRY)" ; \
273         case \`\$(VLC_CONFIG) --linkage \$\$mod\` in \\
274           c++)  ld="\$(CXXLINK)" ;; \
275           objc) ld="\$(OBJCLINK)" ;; \
276           c|*)  ld="\$(LINK)" ;; \
277         esac ; \
278         echo \$\$ld \$< \$\$ldfl ; \
279         \$\$ld \$< \$\$ldfl
280 #ifneq (,\$(findstring cygwin,\$(host)))
281 #       mv -f "\$@.exe" "\$@"
282 #endif
283         @if test -f "\$@.exe"; then mv -f "\$@.exe" "\$@"; fi
284
285 if MAINTAINER_MODE
286 \$(srcdir)/Makefile.am: \$(srcdir)/Modules.am \$(top_srcdir)/bootstrap
287         cd \$(top_srcdir) && \$(SHELL) ./bootstrap
288 endif
289
290 mostlyclean-local:
291 if USE_LIBTOOL
292         -rm -f *.la
293 else
294         -rm -f *.a *\$(LIBEXT)
295 endif
296
297 clean-local: \$(clean_modules)
298
299 ### automake creates libvlcdir after running install-*-local
300 ### so we have to create it ourselves first
301 install-exec-local: all-modules
302 if USE_LIBTOOL
303         @if test -z "\$(libvlc_LTLIBRARIES)"; then \
304           z=\$\$(\$(VLC_CONFIG) --list plugin); \
305           m=\`for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo -n " lib\$\${mod}_plugin.la" ;; esac; done\` ; \
306           test -z "\$\$m" || \
307             \$(MAKE) \$(AM_MAKEFLAGS) libvlc_LTLIBRARIES="\$\$m" install-libvlcLTLIBRARIES || exit \$\$? ; \
308         fi
309 else
310         mkdir -p -- "\$(DESTDIR)\$(libvlcdir)"
311         @z=\$\$(\$(VLC_CONFIG) --list plugin); \
312         for mod in \$(mods); do \
313           case "\$\$z " \
314             in *\ \$\${mod}\ *) \
315               echo \$(INSTALL_PROGRAM) "lib\$\${mod}_plugin\$(LIBEXT)" "\$(DESTDIR)\$(libvlcdir)/" ; \
316               \$(INSTALL_PROGRAM) "lib\$\${mod}_plugin\$(LIBEXT)" "\$(DESTDIR)\$(libvlcdir)/" || exit \$\$?; \
317               ;; \
318           esac; \
319         done
320 endif
321
322 uninstall-local:
323 if USE_LIBTOOL
324         @if test -z "\$(libvlc_LTLIBRARIES)"; then \
325           z=\$\$(\$(VLC_CONFIG) --list plugin); \
326           m=\`for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo -n " lib\$\${mod}_plugin.la" ;; esac; done\` ; \
327           test -z "\$\$m" || \
328             \$(MAKE) \$(AM_MAKEFLAGS) libvlc_LTLIBRARIES="\$\$m" uninstall-libvlcLTLIBRARIES || exit \$\$?; \
329         fi
330 else
331         @z=\$\$(\$(VLC_CONFIG) --list plugin); \
332         for mod in \$(mods); do \
333           case "\$\$z " \
334             in *\ \$\${mod}\ *) \
335               echo rm -f "\$(DESTDIR)\$(libvlcdir)/lib\$\${mod}_plugin\$(LIBEXT)" ; \
336               rm -f "\$(DESTDIR)\$(libvlcdir)/lib\$\${mod}_plugin\$(LIBEXT)" || true; \
337               ;; \
338           esac; \
339         done
340 endif
341
342 EOF
343   for mod in $mods
344   do
345     if grep '^nodist_SOURCES_'${mod}'' < "${modf}" >/dev/null 2>&1; then
346         NODIST=''; else
347         NODIST='#'; fi
348     cat >> m4/private.m4-tmp4 << EOF
349     ${mod}) list="\\\${list} ${dir}/lib${mod}" ;;
350 EOF
351 # Generation of modules/**/Makefile.am
352 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353 # - L_ is for LIBRARIES_, D_ for DATA_, B_ for BUILT_SOURCES_, F_ for LDFLAGS_,
354 #   S_ for SOURCES_, _p is for _plugin, _b is for _builtin. This is to reduce
355 #   the resulting file size.
356 # - *_CFLAGS, *_CXXFLAGS etc. because per-object CPPFLAGS does not seem to
357 #   work properly with any automake version I tested.
358     cat >> "${makf}" << EOF
359 # The ${mod} plugin
360
361 EOF
362     if [ "${NODIST}" != "#" ]; then cat >> "${makf}" << EOF
363 clean_modules += clean-${mod}
364 clean-${mod}:
365         -test -z "\$(nodist_SOURCES_${mod})" || rm -f \$(nodist_SOURCES_${mod})
366
367 EOF
368     fi
369     if [ "${NODIST}" != "#" ]; then cat >> "${makf}" << EOF
370 BUILT_SOURCES += \$(B${mod})
371 EOF
372     fi
373     cat >> "${makf}" << EOF
374 lib${mod}_plugin_a_SOURCES = \$(SOURCES_${mod})
375 lib${mod}_plugin_la_SOURCES = \$(SOURCES_${mod})
376 EOF
377     if [ "${NODIST}" != "#" ]; then cat >> "${makf}" << EOF
378 nodist_lib${mod}_plugin_a_SOURCES = \$(nodist_SOURCES_${mod})
379 nodist_lib${mod}_plugin_la_SOURCES = \$(nodist_SOURCES_${mod})
380 EOF
381     fi
382     cat >> "${makf}" << EOF
383 lib${mod}_plugin_a_CFLAGS = \`\$(VLC_CONFIG) --cflags plugin ${mod}\`
384 lib${mod}_plugin_a_CXXFLAGS = \`\$(VLC_CONFIG) --cxxflags plugin ${mod}\`
385 lib${mod}_plugin_a_OBJCFLAGS = \`\$(VLC_CONFIG) --objcflags plugin ${mod}\`
386 lib${mod}_plugin_la_CFLAGS = \`\$(VLC_CONFIG) --cflags plugin ${mod}\`
387 lib${mod}_plugin_la_CXXFLAGS = \`\$(VLC_CONFIG) --cxxflags plugin ${mod}\`
388 lib${mod}_plugin_la_OBJCFLAGS = \`\$(VLC_CONFIG) --objcflags plugin ${mod}\`
389 lib${mod}_plugin_la_LDFLAGS = \`\$(VLC_CONFIG) --libs plugin ${mod}\` \\
390         -rpath '\$(libvlcdir)' -avoid-version -module -shrext \$(LIBEXT) \\
391         -export-symbol-regex ^\$(VLC_ENTRY)\$\$ -no-undefined
392 lib${mod}_plugin_la_LIBADD = \$(LTLIBVLC)
393
394 lib${mod}_a_SOURCES = \$(SOURCES_${mod})
395 EOF
396     if [ "${NODIST}" != "#" ]; then cat >> "${makf}" << EOF
397 nodist_lib${mod}_a_SOURCES = \$(nodist_SOURCES_${mod})
398 EOF
399     fi
400     cat >> "${makf}" << EOF
401 lib${mod}_a_CFLAGS = \`\$(VLC_CONFIG) --cflags builtin pic ${mod}\`
402 lib${mod}_a_CXXFLAGS = \`\$(VLC_CONFIG) --cxxflags builtin pic ${mod}\`
403 lib${mod}_a_OBJCFLAGS = \`\$(VLC_CONFIG) --objcflags builtin pic ${mod}\`
404
405 EOF
406   done
407 done
408
409 cat >> m4/private.m4-tmp1 << EOF
410 ])
411 EOF
412 cat m4/private.m4-tmp1 >> m4/private.m4 && rm -f m4/private.m4-tmp1
413 cat >> m4/private.m4-tmp2 << EOF
414 ])
415 EOF
416 cat m4/private.m4-tmp2 >> m4/private.m4 && rm -f m4/private.m4-tmp2
417 cat >> m4/private.m4-tmp3 << EOF
418 ])])
419 EOF
420 cat m4/private.m4-tmp3 >> m4/private.m4 && rm -f m4/private.m4-tmp3
421 cat >> m4/private.m4-tmp4 << EOF
422 BLAH
423 ])
424 EOF
425 cat m4/private.m4-tmp4 >> m4/private.m4 && rm -f m4/private.m4-tmp4
426
427 echo " done."
428
429 ###
430 ###  classic bootstrap stuff
431 ###
432 set -x
433
434 # remove autotools cruft
435 rm -f aclocal.m4 configure config.log config.h config.h.in
436 rm -Rf autom4te*.cache
437 # remove old autotools extra cruft
438 rm -f config.guess config.sub missing mkinstalldirs compile depcomp install-sh
439 # remove new autotools extra cruft
440 rm -Rf autotools
441 mkdir autotools
442 # remove libtool cruft
443 rm -f ltmain.sh libtool ltconfig
444 # remove gettext cruft
445 rm -f ABOUT-NLS
446 rm -Rf intl
447 # remove vlc cruft
448 rm -f stamp-builtin stamp-h* mozilla/stamp-pic
449
450 # Automake complains if these are not present
451 rm -f vlc-config.in && printf "" > vlc-config.in
452 if [ "$GETTEXT" != "yes" ]; then
453   test -d intl || mkdir intl
454   printf "" > intl/Makefile.am
455   printf "" > ABOUT-NLS
456 fi
457
458 # Libtoolize directory
459 ${libtoolize} --copy --force
460 if test -f "ltmain.sh"; then
461   echo "$0: working around a minor libtool issue"
462   mv ltmain.sh autotools/
463 fi
464
465 # patch for DLL link for libtool on cygwin (remove when fixed)
466 if test ".`uname -s|sed -n '/^CYGWIN/p'`" != "."; then
467 patch -s -p0 << 'EOF'
468 --- autotools/ltmain.orig       2006-12-05 15:15:42.064607000 +0000
469 +++ autotools/ltmain.sh 2006-12-05 15:16:24.705777800 +0000
470 @@ -4360,7 +4360,7 @@
471  
472      prog)
473        case $host in
474 -       *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;;
475 +       *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,;s,.dll.exe$,.dll,'` ;;
476        esac
477        if test -n "$vinfo"; then
478         $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2
479 EOF
480 fi
481
482 # Do the rest
483 ${autopoint} -f
484 ${aclocal} ${ACLOCAL_ARGS}
485 ${autoconf}
486 ${autoheader}
487 ${automake} --add-missing --copy -Wall
488
489 ##
490 ##  files which need to be regenerated
491 ##
492 rm -f vlc-config.in vlc-config
493 rm -f src/misc/modules_builtin.h
494
495 # Shut up
496 set +x
497
498 ##
499 ##  Tell the user about gettext, pkg-config and sed
500 ##
501 if [ "${GETTEXT}" = "old" ]; then
502   cat << EOF
503
504 ==========================================================
505 NOTE: you have an old version of gettext installed on your
506 system. The vlc build will work, but if your system does not
507 have libintl you will not have internationalization support.
508 We suggest upgrading to gettext 0.11.5 or later.
509 EOF
510 fi
511
512 if [ "$PKGCONFIG" = "no" ]; then
513   cat << EOF
514
515 ==============================================================
516 NOTE: you do not have the "pkg-config" utility on your system;
517 detection of the Gtk-2.0 and GNOME 2.0 libraries will not be
518 reliable.
519 EOF
520 fi
521