strange Make behavior

Sheldon E. Newhouse (sen@math.msu.edu)
Mon, 24 Jun 1996 21:19:50 -0400


While running the Byte benchmarks, I came across some strange Makefile
behavior. I don't know if it is a bug, but it is different from, say SUN
Solaris, and may lead to peculiar behavior.

Consider the two Makefiles (with your favorite simple source file source.c)

In Makefile-good, the variable TMPDIR is defined and everything works.
In Makefile-bad, the variable TMPDIR is undefined. It still creates the
file a.out, does not create the directory ./tmp. No error message. In
Solaris 2.5, it just bombs out (as it should).

#Makefile-good

SHELL = /bin/sh
CC=gcc
# local directories
TMPDIR = ./tmp

SOURCES = source.c
BINS = a.out

all: distr programs

distr:
@echo "Checking distribution of files"
# temporary work directory
@if test ! -d $(TMPDIR) \
; then \
mkdir $(TMPDIR) \
; else \
echo "$(TMPDIR) exists" \
; fi

programs: $(BINS)

a.out:
$(CC) -o a.out source.c

clean:
rm -f $(BINS)

#End of Makefile-good

########################################################################

#Makefile-bad

SHELL = /bin/sh
CC=gcc
# local directories
# TMPDIR = ./tmp

SOURCES = source.c
BINS = a.out

all: distr programs

distr:
@echo "Checking distribution of files"
# temporary work directory
@if test ! -d $(TMPDIR) \
; then \
mkdir $(TMPDIR) \
; else \
echo "$(TMPDIR) exists" \
; fi

programs: $(BINS)

a.out:
$(CC) -o a.out source.c

clean:
rm -f $(BINS)

#End of Makefile-bad

Any comments welcome,

-sen

---------------------------------------------------------------------------
| Sheldon E. Newhouse | mail: newhouse@math.msu.edu |
| Mathematics Department | www: http://www.mth.msu.edu/~sen |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------