3 ######################################################################
4 # Generate helper code for making builtin DSO plugins available.
6 # Sometimes it is necessary to split a plugin to several source
7 # files. Usually this is the case when the functionality provided
8 # by the plugin is complex enough to require subdividing the plugin
9 # into internal modules for the best maintainability.
11 # In these cases we cannot avoid making several functions and
12 # variables globally available within the plugin so we cannot just
13 # limit the scope of visibility by making them static. Still, we do
14 # want to avoid conflicts between these symbols of different plugins.
15 # To accomplish this we compile and link such plugins into shared
16 # libraries (with our normal symbol visibility conventions) and then
17 # link the murphy daemon against them.
19 # Since none of the code linked into murphy proper references
20 # any of the symbols in any of these plugins without any further
21 # special arrangements these plugins wouldn't be demand-loaded
22 # and consequently would be unavailable when the daemon starts up.
24 # To overcome this every such plugin gets automatically augmented
25 # by a plugin-specifig globally visible symbol and the murphy daemon
26 # gets augmented by a symbol that references these plugin-specific
27 # symbols. This forces the dynamic loader to load the plugins and
28 # the normal builtin-plugin autoregistration mechanism takes care of
31 # A bit too spaceship-ish, I admit... but nevertheless necessary
32 # unless we want to give up the idea of builtin/linkedin plugins...
45 echo "warning: $*" 1>&2
49 info "usage: $0 -p <plugin> -o <output-file>, or"
50 info "usage: $0 -o <output-file> -d <plugin-list>"
58 emit_plugin_loader () {
60 *.c) emit "int mrp_linkedin_plugin_${1//-/_}_symbol = 0;"
62 *.h) emit "extern int mrp_linkedin_plugin_${1//-/_}_symbol;"
67 emit_murphy_loader () {
71 emit "#include \"linkedin-$_p-loader.h\""
74 emit "int mrp_load_linkedin_plugins(void)"
78 emit " mrp_linkedin_plugin_${_p//-/_}_symbol + \\"
93 while [ -n "${1#-}" ]; do
96 if [ -z "$OUTPUT" ]; then
100 error "Multiple output files requested."
105 if [ -z "$PLUGIN" -a "$daemon" = "no" ]; then
109 if [ -n "$PLUGIN" ]; then
110 error "Multiple builtin plugins specified."
112 error "Both builtin plugin and plugin list specified."
129 error "Unknown option '$1'."
134 if [ "$daemon" = "yes" ]; then
135 PLUGIN_LIST="$PLUGIN_LIST $1"
137 error "Unexpected argument '$1'."
145 # check that we've got everything mandatory
146 if [ -z "$OUTPUT" ]; then
147 error "No output file specified (use the -o option)."
151 if [ -z "$PLUGIN" -a "$daemon" = "no" ]; then
152 error "Neither builtin plugin nor plugin list is specified."
156 # generate the output
159 if [ "$daemon" = "no" ]; then
160 emit_plugin_loader $PLUGIN
162 emit_murphy_loader $PLUGIN_LIST