Skip to content

Instantly share code, notes, and snippets.

@mohd-akram
Last active April 4, 2021 08:46
Show Gist options
  • Select an option

  • Save mohd-akram/0e35031179bac99a0ef564ce59a628cf to your computer and use it in GitHub Desktop.

Select an option

Save mohd-akram/0e35031179bac99a0ef564ce59a628cf to your computer and use it in GitHub Desktop.
A script to build a dynamic Nginx module with the correct configure options.
#!/bin/sh
# A script to build a dynamic Nginx module with the correct configure options.
set -eu
set -o pipefail 2>/dev/null || :
dir="$1"
if [ ! "$dir" ]; then
echo "usage: $0 module_dir" >&2
exit 1
fi
getconfopts() {
nginx -V 2>&1 |
sed -nE "s/^configure arguments: //; s/ (--[^' ]+('[^']*')?)/\n\1/pg;"
}
dist=`nginx -v 2>&1 | cut -d' ' -f3 | tr / -`
opts=`getconfopts | grep -- --with-compat || getconfopts`
name=`sed -n 's/^ngx_addon_name=//p' "$dir/config"`
keep=
if [ -d "$dist" ]; then
keep=1
else
curl "https://nginx.org/download/$dist.tar.gz" | tar -xz
fi
cd "$dir"
dir=`pwd`
cd -
cd "$dist"
echo "$opts" | xargs ./configure --add-dynamic-module="$dir"
make modules
cd -
cp "$dist/objs/$name.so" .
if [ ! "$keep" ]; then
rm -rf "$dist"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment