/*
 * src/post-glade
 *
 * Copyright 2007 by University of York
 * Author: Paul Emsley
 *
 * This file is part of Coot
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copies of the GNU General Public License and
 * the GNU Lesser General Public License along with this program; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA, 02110-1301, USA.
 * See http://www.gnu.org/licenses/
 *
 */
#!/bin/sh

./add-c-extern.sh support.h
./add-c-extern.sh interface.h

# Don't put the test too early (before gtk.h is loaded):
# need to put the test after support.h

# Francois says that in support.h, interface.c  we need to replace:
#
# #include <unistd.h>
#
# with
#
# #ifndef _MSC_VER
# #include <unistd.h>
# #endif

sed -e 's/#include .support.h./#include "support.h"\n\n#if (GTK_MAJOR_VERSION == 1) || defined (GTK_ENABLE_BROKEN)/' \
    -e 's/#include .unistd.h./#ifndef _MSC_VER\n#include <unistd.h>\n#endif/' \
    interface.c > tmp-interface.c
echo "#endif" >>  tmp-interface.c
mv tmp-interface.c interface.c

sed -e 's/#include <unistd.h>/#ifndef _MSC_VER\n#include <unistd.h>\n#else\n#define S_ISREG(m) (((m) \& S_IFMT) == S_IFREG)\n#endif/' \
    -e 's/static GList \*pixmaps_directories/GList \*pixmaps_directories/' \
    support.c > support-tmp.c
mv support-tmp.c support.c



# on reflection, try not to mess with gtk2-interface.c
#
# only add an endif if there wasn't one there already:
# If it is not there grep give status code 1.
# grep endif gtk2-interface.c > /dev/null
# grepstatus=$?
# if [ $grepstatus = 1 ] ; then
#    echo "#endif" >>  tmp-interface.c
# fi
# mv tmp-interface.c gtk2-interface.c


sh fix-gettext.sh support.h
if test -e main.c ; then 
	rm main.c
fi


# for gtk2 post glading, there is a lot less rebuilding.  We only
# need to edit gtk2-interface.c, adding a #if VERSION adn endif
# and also change support.h.gtk2 to support.h
