BUNDLE_TAG=opengis
PYXB_ROOT=${PYXB_ROOT:-/home/pab/pyxb/dev}

. ${PYXB_ROOT}/maintainer/bundlesupport.sh

export PYXB_ARCHIVE_PATH=${RAW_DIR}//:+

(
mkdir -p ${SCHEMA_DIR}
cd ${SCHEMA_DIR} ; 
if [ ! -d gml ] ; then
  rm -rf [a-z]*
fi
if [ ! -f SCHEMAS_OPENGIS_NET.tgz ] ; then
  wget http://schemas.opengis.net/SCHEMAS_OPENGIS_NET.tgz
fi
if [ ! -d gml ] ; then
  echo "Unpacking schemas"
  tar xzf SCHEMAS_OPENGIS_NET.tgz
fi
)

find ${RAW_DIR} -name '*.wxs' | xargs rm -f

( cat <<EOText
${SCHEMA_DIR}/citygml/xAL/xAL.xsd misc.xAL
${SCHEMA_DIR}/xlink/1.0.0/xlinks.xsd misc.xlinks
EOText
) | generateBindings

pyxbgen \
  --location-prefix-rewrite=http://schemas.opengis.net/=${SCHEMA_DIR}/ \
  --schema-location=${SCHEMA_DIR}/gml/3.2.1/gml.xsd --module=gml_3_2 \
  --schema-location=${SCHEMA_DIR}/iso/19139/20070417/gmd/gmd.xsd --module=iso19139.gmd \
  --schema-location=${SCHEMA_DIR}/iso/19139/20070417/gts/gts.xsd --module=iso19139.gts \
  --schema-location=${SCHEMA_DIR}/iso/19139/20070417/gsr/gsr.xsd --module=iso19139.gsr \
  --schema-location=${SCHEMA_DIR}/iso/19139/20070417/gss/gss.xsd --module=iso19139.gss \
  --schema-location=${SCHEMA_DIR}/iso/19139/20070417/gco/gco.xsd --module=iso19139.gco \
  --module-prefix=${MODULE_PREFIX} \
  --write-for-customization \
  --archive-to-file=${ARCHIVE_DIR}/iso19139.core.wxs \
 || failure gml_3_2
  
( cat <<EOText
${SCHEMA_DIR}/iso/19139/20070417/gmx/gmx.xsd gmx
${SCHEMA_DIR}/gml/3.1.1/base/gml.xsd gml
${SCHEMA_DIR}/filter/1.1.0/filter.xsd filter
${SCHEMA_DIR}/sweCommon/1.0.0/swe.xsd swe_1_0_0
${SCHEMA_DIR}/sweCommon/1.0.1/swe.xsd swe_1_0_1
${SCHEMA_DIR}/citygml/1.0/cityGMLBase.xsd citygml.base
${SCHEMA_DIR}/kml/2.2.0/ogckml22.xsd ogckml22
${SCHEMA_DIR}/ic/2.1/IC-ISM-v2.1.xsd ic_ism_2_1
${SCHEMA_DIR}/sensorML/1.0.1/sensorML.xsd sensorML_1_0_1
${SCHEMA_DIR}/ows/1.0.0/owsAll.xsd ows
${SCHEMA_DIR}/ows/1.1.0/owsAll.xsd ows_1_1
${SCHEMA_DIR}/om/1.0.0/om.xsd om_1_0
${SCHEMA_DIR}/sos/1.0.0/sosAll.xsd sos_1_0 --pre-load-archive=${ARCHIVE_DIR}/filter.wxs
${SCHEMA_DIR}/sampling/1.0.0/sampling.xsd sampling_1_0
${SCHEMA_DIR}/tml/1.0.0/tml.xsd tml
${SCHEMA_DIR}/wfs/1.1.0/wfs.xsd wfs
${SCHEMA_DIR}/wcs/1.1/wcsAll.xsd wcs_1_1
${SCHEMA_DIR}/csw/2.0.2/record.xsd csw_2_0_2
${SCHEMA_DIR}/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsfLevels.xsd gmlsf
${SCHEMA_DIR}/citygml/appearance/1.0/appearance.xsd citygml.appearance
${SCHEMA_DIR}/citygml/building/1.0/building.xsd citygml.building
${SCHEMA_DIR}/citygml/cityfurniture/1.0/cityFurniture.xsd citygml.cityFurniture
${SCHEMA_DIR}/citygml/cityobjectgroup/1.0/cityObjectGroup.xsd citygml.cityObjectGroup
${SCHEMA_DIR}/citygml/generics/1.0/generics.xsd citygml.generics
${SCHEMA_DIR}/citygml/landuse/1.0/landUse.xsd citygml.landUse
${SCHEMA_DIR}/citygml/relief/1.0/relief.xsd citygml.relief
${SCHEMA_DIR}/citygml/texturedsurface/1.0/texturedSurface.xsd citygml.texturedSurface
${SCHEMA_DIR}/citygml/transportation/1.0/transportation.xsd citygml.transportation
${SCHEMA_DIR}/citygml/vegetation/1.0/vegetation.xsd citygml.vegetation
${SCHEMA_DIR}/citygml/waterbody/1.0/waterBody.xsd citygml.waterBody
EOText
) | generateBindings \
      --location-prefix-rewrite=http://schemas.opengis.net/=${SCHEMA_DIR}/

