#5 configure script maintainability: flag definitions

open
nobody
None
5
2005-09-27
2005-09-27
Daniel Macks
No

Currently (xpaint-2.7.8.1) configure has a block like:

if test "$WIDGETS" = "XAW3DG" ; then
ln -sf /usr/include/X11/Xaw3d xaw_incdir
echo "XAWLIB_DEFINES = -DXAW3D -DXAW3DG"
echo "XAWLIB_DEFINES = -DXAW3D -DXAW3DG" > Local.xawdefs
echo "SYS_LIBRARIES = -lXaw3d -L."
echo "SYS_LIBRARIES = -lXaw3d -L." >> Local.xawdefs
echo ""
xmkmf ; echo "cd rw" ; cd rw ; xmkmf
exit
fi

repeated for each expected WIDGETS value, followed by a similar block to handle "an unexpected WIDGETS value". That's a lot of repeated code! Gotta keep the echo to user in sync with the echo to the file; if you want to alter that last xmkmf... line, you have to do it 5 places.

Why not make a single 'case' construct to handle the WIDGETS values? Because there is a distinct default handler, you don't need to "exit" from each block to avoid fallthrough to the default handler. Each case could set the directory to be linked and the flagsets to some variables. Then after the whole case set, you could have a single place where they (whatever they are) linked or are displayed to the user and recorded in the file. Because execution continues for all cases, you can move the common continuation code (xmkmf...) to a single place at the end instead of repeated in each case handler.

Discussion