]> git.sesse.net Git - vlc/blob - modules/genmf
Separate Makefile generation from bootstrap
[vlc] / modules / genmf
1 #! /bin/sh
2
3 ##  genmf file for the VLC media player
4 ##
5 ## Copyright (C) 2005-2007 the VideoLAN team
6 ##
7 ##  Authors: Sam Hocevar <sam@zoy.org>
8 ##           RĂ©mi Denis-Courmont <rem # videolan # org>
9
10 cd $(dirname "$0")/.. || exit 1
11
12 while test "$1"
13 do
14   printf "."
15   dir="$1"
16   modf="modules/${dir}/Modules.am"
17   makf="modules/${dir}/Makefile.am"
18   basedir="`echo "${dir}" | cut -f1 -d/`"
19   # automake will not recurse for make dist if we don't define SUBDIRS = .
20   subdirs="`sed -ne 's,'modules/${dir}'/\([^/]*\)/Makefile,\1,p' configure.ac | xargs`"
21   mods="`sed -n -e 's/^ *SOURCES_\([^ ]*\).*/\1/p' < "${modf}" | xargs`"
22   extra_ltlibs=""
23   for mod in $mods
24   do
25     extra_ltlibs="${extra_ltlibs} lib${mod}_plugin.la"
26   done
27   rm -f "${makf}" && cat > "${makf}" << EOF
28 # ${makf} automatically generated from ${modf} by bootstrap
29 # DO NOT EDIT - edit Modules.am or \$(top_srcdir)/bootstrap instead
30
31 basedir = ${basedir}
32 mods = ${mods}
33
34 NULL =
35 libvlc_LTLIBRARIES =
36 EXTRA_DIST = Modules.am
37 BUILT_SOURCES =
38 CLEANFILES =
39 SUBDIRS = ${subdirs}
40 SUFFIXES = _plugin\$(LIBEXT) _plugin.la
41
42 libvlcdir = \$(libdir)/vlc/\$(basedir)
43
44 EXTRA_LTLIBRARIES = ${extra_ltlibs}
45
46 include Modules.am
47
48 if HAVE_PLUGINS
49 LTLIBVLC = -L\$(top_builddir)/src -lvlc
50
51 AM_LDFLAGS = -rpath '\$(libvlcdir)' -avoid-version \\
52         -module -no-undefined -shrext \$(LIBEXT) 
53 if HAVE_COMPILER_EXPORT
54 AM_LDFLAGS += -export-dynamic
55 else
56 AM_LDFLAGS += -export-symbol-regex ^\$(VLC_ENTRY)\$\$
57 endif
58 AM_LIBADD = \$(LTLIBVLC)
59 endif
60
61 all: all-modules
62
63 nice:
64         \$(top_builddir)/compile
65
66 # Find out which modules were enabled and tell make to build them
67 all-modules:
68         @set fnord \$\$MAKEFLAGS; amf=\$\$2; targets=\`\\
69         z=\$\$(\$(VLC_CONFIG) --list plugin); for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo lib\$\${mod}_plugin.la;; esac; done; \\
70         \`; case "\$\$targets" in *lib*) \$(MAKE) \$(AM_MAKEFLAGS) \$\$targets || case "\$\$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; ;; esac; \\
71         test -z "\$\$fail"
72
73 # Build a plugin with the adequate linker and linker's flags
74 _plugin.la_plugin\$(LIBEXT):
75         @mod="\$*" ; mod=\$\${mod#lib} ; \
76         ldfl="\`\$(VLC_CONFIG) --libs plugin \$\$mod\` \$(LIBVLC) -u \$(SYMPREF)\$(VLC_ENTRY)" ; \
77         case \`\$(VLC_CONFIG) --linkage \$\$mod\` in \\
78           c++)  ld="\$(CXXLINK)" ;; \
79           objc) ld="\$(OBJCLINK)" ;; \
80           c|*)  ld="\$(LINK)" ;; \
81         esac ; \
82         echo \$\$ld \$< \$\$ldfl ; \
83         \$\$ld \$< \$\$ldfl
84
85 if MAINTAINER_MODE
86 \$(srcdir)/Makefile.am: \$(srcdir)/Modules.am \$(top_srcdir)/modules/genmf
87         cd \$(top_srcdir) && \$(SHELL) modules/genmf ${dir}
88 endif
89
90 mostlyclean-local:
91         -rm -f -- *.la
92
93 ### automake creates libvlcdir after running install-*-local
94 ### so we have to create it ourselves first
95 install-exec-local: all-modules
96         @if test -z "\$(libvlc_LTLIBRARIES)"; then \
97           z=\$\$(\$(VLC_CONFIG) --list plugin); \
98           m=\`for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo -n " lib\$\${mod}_plugin.la" ;; esac; done\` ; \
99           test -z "\$\$m" || \
100             \$(MAKE) \$(AM_MAKEFLAGS) libvlc_LTLIBRARIES="\$\$m" install-libvlcLTLIBRARIES || exit \$\$? ; \
101         fi
102
103 uninstall-local:
104         @if test -z "\$(libvlc_LTLIBRARIES)"; then \
105           z=\$\$(\$(VLC_CONFIG) --list plugin); \
106           m=\`for mod in \$(mods); do case "\$\$z " in *\ \$\${mod}\ *) echo -n " lib\$\${mod}_plugin.la" ;; esac; done\` ; \
107           test -z "\$\$m" || \
108             \$(MAKE) \$(AM_MAKEFLAGS) libvlc_LTLIBRARIES="\$\$m" uninstall-libvlcLTLIBRARIES || exit \$\$?; \
109         fi
110
111 EOF
112   for mod in $mods
113   do
114     if grep '^nodist_SOURCES_'${mod}'' < "${modf}" >/dev/null 2>&1; then
115         NODIST=''; else
116         NODIST='#'; fi
117     cat >> m4/private.m4 << EOF
118     ${mod}) list="\\\${list} ${dir}/lib${mod}" ;;
119 EOF
120 # Generation of modules/**/Makefile.am
121 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122 # - L_ is for LIBRARIES_, D_ for DATA_, B_ for BUILT_SOURCES_, F_ for LDFLAGS_,
123 #   S_ for SOURCES_, _p is for _plugin, _b is for _builtin. This is to reduce
124 #   the resulting file size.
125 # - *_CFLAGS, *_CXXFLAGS etc. because per-object CPPFLAGS does not seem to
126 #   work properly with any automake version I tested.
127     cat >> "${makf}" << EOF
128 # The ${mod} plugin
129
130 EOF
131     cat >> "${makf}" << EOF
132 lib${mod}_plugin_la_SOURCES = \$(SOURCES_${mod})
133 EOF
134     if [ "${NODIST}" != "#" ]; then cat >> "${makf}" << EOF
135 nodist_lib${mod}_plugin_la_SOURCES = \$(nodist_SOURCES_${mod})
136 CLEANFILES += \$(nodist_SOURCES_${mod})
137 BUILT_SOURCES += \$(B${mod})
138 EOF
139     fi
140     cat >> "${makf}" << EOF
141 lib${mod}_plugin_la_CFLAGS = \`\$(VLC_CONFIG) --cflags plugin ${mod}\`
142 lib${mod}_plugin_la_CXXFLAGS = \`\$(VLC_CONFIG) --cxxflags plugin ${mod}\`
143 lib${mod}_plugin_la_OBJCFLAGS = \`\$(VLC_CONFIG) --objcflags plugin ${mod}\`
144 lib${mod}_plugin_la_LDFLAGS = \`\$(VLC_CONFIG) --libs plugin ${mod}\` \$(AM_LDFLAGS)
145 lib${mod}_plugin_la_LIBADD = \$(AM_LIBADD)
146 EOF
147   done
148
149   shift
150 done
151 printf "\n"