Script tidy-up, more in line with normal sysconfig scripts; lib/query.c compiles, work ongoing