Makefile CVS login with Expect

Posted by Peter Burkholder Sat, 19 Aug 2006 12:45:00 GMT

I haven’t used Expect in years, for some reason, but yesterday I need a Makefile that would, as part of a build process, checkout some project using anonymous CVS. Here’s the solution:


#Makefile
CVSROOT         = :pserver:anonymous@strandmapservic.cvs.sourceforge.net:/cvsroot/strandmapservic

BRANCH = HEAD
PROJECTS = smsdemo

define CVSlogin
  /usr/bin/expect -c 'spawn cvs login' -c 'expect "CVS password:"' -c 'send "\r"' -c 'expect eof'
endef

#...
checkout: 
        echo $(CVSROOT) | if grep -q pserver; then \
                 $(CVSlogin); \
            fi
        CVSROOT=$(CVSROOT) cvs co -r $(BRANCH) $(PROJECTS)
        touch $@

If some of this seems overly complicated, it’s because this same Makefile (or rather, the Makefile.in that’s processed by m4) is used for many other build.

Then ‘make checkout’ results in:

echo :pserver:anonymous@strandmapservic.cvs.sourceforge.net:/cvsroot/strandmapservic | if grep -q pserver; then \
           /usr/bin/expect -c 'spawn cvs login' -c 'expect "CVS password:"' -c 'send "\r"' -c 'expect eof'; \
    fi
spawn cvs login
Logging in to :pserver:anonymous@strandmapservic.cvs.sourceforge.net:2401/cvsroot/strandmapservic
CVS password: 
CVSROOT=:pserver:anonymous@strandmapservic.cvs.sourceforge.net:/cvsroot/strandmapservic cvs co -r HEAD smsdemo
cvs checkout: Updating smsdemo
U smsdemo/.classpath
...