Edit

thodg/patchwork13/pw13-makefile-am

Branch :

  • pw13-makefile-am
  • #! /bin/sh
    #
    #  This is part of Patchwork13! the real-time data synthesis toolkit.
    #  http://patchwork13.sourceforge.net/
    #
    #  pw13_std - the patchwork13 standard patches library
    #  Copyright (C) 2005 Thomas de Grivel <billitch@yahoo.fr>
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation; either version 2
    #  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 General Public License for more details.
    #
    #  You should have received a copy of the GNU General Public License
    #  along with this program; if not, write to the Free Software
    #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    #
    ##
    #
    #  pw13-makefile-am  -  Generate or update Makefile.am for a patch library dir
    #
    ##
    
    ME=$(basename $0)
    
    PW13=pw13-0
    SRC=.pw13src
    PREV_SRC=${SRC}'~'
    
    if [ -z "$1" ] || [ -z "$2" ]
    then {
        echo "Usage: $ME libname topdir [subdir]"
        exit 1
    }
    fi
    
    LIBNAME="$1"
    TOPDIR="$2"
    SUBDIR="$3"
    DIR=$(pwd)
    
    test -e $SRC && (
        cp -f $SRC $PREV_SRC || (
    	echo "${ME}: I need write access to ${PREV_SRC} !"
    	exit 2
        )
    )
    ls *.pw13*.[ch] 2>/dev/null > $SRC
    
    [ -e Makefile.am ] &&
    diff --brief $SRC $PREV_SRC 2>/dev/null >/dev/null && (
        echo "${ME}: Makefile.am is up to date.";
        rm -f ${PREV_SRC};
        true ) && exit 0
    
    rm -f ${PREV_SRC}
    
    PATCHES=$(echo $(ls *.pw13p.c *.pw13p.cc 2>/dev/null | awk -F . '{print $1"."$2".la"}'))
    DT_HEADERS=$(ls *.pw13dt.h *.pw13dt.hh 2> /dev/null)
    DT_LIBS=$(echo $(ls *.pw13dt.c *.pw13dt.cc 2>/dev/null | awk -F . '{print $1"."$2".la"}'))
    
    libname="`echo "$LIBNAME" | tr [a-z] [A-Z]`"
    
    {
        echo '# Makefile.am - generated by pw13-makefile-am'
        echo
        echo 'AUTOMAKE_OPTIONS = gnu'
    #   echo 'CONFIGURE_DEPENDENCIES = pw13sources'
        echo
        echo "patchdir=\$(libdir)/$PW13/$LIBNAME/$SUBDIR"
        echo 'patch_LTLIBRARIES =' $PATCHES $DT_LIBS
        echo
        echo "INCLUDES=\$(PW13_CFLAGS) \$(PW13_${libname}_CFLAGS)"
        echo
        if test -n ${DT_HEADERS}; then
    	echo 'library_include_HEADERS =' $DT_HEADERS
    	echo 'library_includedir=$(includedir)/'$PW13'/'$LIBNAME
    	echo
        fi
        echo 'pw13_patch_class.def:'
        echo '	echo "EXPORT" > pw13_patch_class.def'
        echo '	echo "	pw13_dl_patch_class_init" >> pw13_patch_class.def'
        echo
        echo 'if OS_WIN32'
        echo 'win32_cflags = -DWIN32'
        echo 'pw13_patch_class_win32_symbols = ' \
    	'-export-symbols pw13_patch_class.def'
        echo 'endif'
        echo 'INCLUDES += ${win32_cflags}'
        echo
        for PATCH_SRC in $(ls *.pw13p.c *.pw13p.cc *.pw13dt.c 2>/dev/null); do
    	PATCH_SRC_BASE=$(basename $PATCH_SRC .c)
    	PATCH_SRC_BASE=$(basename $PATCH_SRC_BASE .cc)
    	PATCH_SRC_=$(echo $PATCH_SRC_BASE | tr -c '[:alnum:][:space:]' '_')
    	PATCH_LDFLAGS=$(grep patch_class_LDFLAGS $PATCH_SRC \
    	    | awk -F '=' '{print $2}')
    	echo 'if OS_WIN32'
    	echo "${PATCH_SRC}: pw13_patch_class.def"
    	echo 'endif'
    	echo "${PATCH_SRC_}_la_SOURCES = ${PATCH_SRC}"
    #       echo "${PATCH_SRC_}_la_CFLAGS = -W -Wall"
    	echo "${PATCH_SRC_}_la_LDFLAGS = -module -no-undefined ${PATCH_LDFLAGS} "\
    	 '$(pw13_patch_class_win32_symbols)'
    	echo "${PATCH_SRC_}_la_LIBADD = \$(PW13_LIBS) \$(PW13_${libname}_LIBS)"
        done
        echo
        echo 'CLEANFILES = pw13_patch_class.def'
        echo
        echo 'Makefile.am: pw13sources'
        echo '.PHONY: pw13sources'
        echo 'pw13sources:'
        echo "	$0 $*; \\"
        echo "      R=$\$?; \\"
        echo "      if [ $\$R -ne 0 ]; then \\"
        echo "	  if [ $\$R -eq 42 ]; then \\"
        echo "	    echo \"pw13-makefile-am: updating $SUBDIR/Makefile\" && \\"
        echo "	    cd $TOPDIR && \\"
        echo "	    automake --gnu $SUBDIR/Makefile && \\"
        echo "	    ./config.status $SUBDIR/Makefile && \\"
        echo "	    \${MAKE} -C ${SUBDIR}; \\"
        echo "	  else \\"
        echo "	    exit $\$R; \\"
        echo "	  fi; \\"
        echo "	fi"
        echo
        echo "EXTRA_DIST = $SRC"
    } > Makefile.am
    
    echo "$ME: Updated Makefile.am"
    
    exit 42