Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!ut-sally!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix Subject: Re: Using sh in makefiles Message-ID: <2196@umcp-cs.UUCP> Date: Sat, 28-Jun-86 07:15:05 EDT Article-I.D.: umcp-cs.2196 Posted: Sat Jun 28 07:15:05 1986 Date-Received: Mon, 30-Jun-86 03:10:36 EDT References: <1991@dalcs.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Distribution: net Organization: University of Maryland, Dept. of Computer Sci. Lines: 48 In article <1991@dalcs.UUCP> silvert@dalcs.UUCP (Bill Silvert) writes: >Would like advice on how to use shell commands (such as if...) in >makefiles. I know that it all has to be on one line, but the only way I >can make a command work is through a kludge like: > >test: > echo "if x;then y;fi" | sh > >which seems pretty roundabout. Is this the only way to do it? No. Here is an example of a series of shell commands I use in a particular Makefile: # make the distribution directory---assumes no RCS files in top level # `doc' is not yet ready dist: rm -rf ../ctex_dist -mkdir ../ctex_dist -set -x +e; \ for i in *; do \ if [ $$i != ctex -a $$i != doc -a $$i != misc ]; then \ if [ -d $$i ]; then \ cp -r $$i ../ctex_dist; \ (cd ../ctex_dist/$$i; \ co -q RCS/*,v; \ rm -rf RCS); \ else \ cp $$i ../ctex_dist; \ fi; \ fi; \ done -cd ../ctex_dist; \ echo '/MANDIR= /s,local/,,XwXq' | \ tr X '\012' | ed Makefile -cd ../ctex_dist; make clean -cd ../ctex_dist/dev; make dist Note in particular the `set +e' in the command containing the `for'. It runs various commands, in particular /bin/[, that exit with a nonzero status; this makes some `sh's exit even when the command is part of an `if'. The `set +e' avoids the problem in all `sh' variants. (The exit occurs because make runs `sh -ce "commands"', which sets -e: exit on error. Using `echo "string" | sh' avoids this problem as well, but at the expense of an extra process.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu