#!/bin/sh -e

mkdir -p "$1/usr/lib/pkgconfig/" "Xaw/include/X11/Xaw/"

mv */*.h Xaw/src/
mv */*.c Xaw/src/
rm Xaw/src/*demo* Xaw/src/*fileprompt*

cd Xaw 
./configure \
    --prefix=/usr \
    --disable-dependency-tracking \
    --disable-specs \
    --enable-static \
    --enable-shared \
    --enable-silent-rules 


cd src
comp="cc -DHAVE_CONFIG_H -I. -I.. -I../include -c %s -o %s"
link="cc *.o -shared -lXt -lX11 -lXpm -lXmu -o libXawPlus.so"
for src in *.c;do $(printf "$comp" $src "$src.o");done
$link

for dir in include/X11/XawPlus lib share/man/man3;do mkdir -p "$1/usr/$dir";done
for so in libXawPlus.so;do mv $so "$1/usr/lib/";done
cd ../include
make
cd X11/Xaw/
mv ../../../src/*.h ./
for header in *.h;do mv $header "$1/usr/include/X11/XawPlus/";done
cd ../
