Using make to compile for sun3 and sun4
Kemp at dockmaster.ncsc.mil
Kemp at dockmaster.ncsc.mil
Wed Jun 28 01:22:00 AEST 1989
After watching the "make wars" on info-unix between GNU make and AT&T
toolchest make, I am convinced that we Sun users have a pretty good
product that has lots of good features that were added without breaking
compatibility or introducing lots of bugs.
That said, there is one thing I haven't been able to figure out from the
examples in the manual. I want to do the equivalent of:
if(sun3) CFLAGS = -f68881
else CFLAGS = (nothing)
A conditional macro seems to be the way to do it, but the syntax is
target-list := macro = value
i.e. the assignment is conditioned on the target, not on the value of
another macro (TARGET_ARCH). There is probably a gross solution like
defining identical targets PROGRAM.sun3 and PROGRAM.sun4, but an elegant
solution would be better.
I finally gave up and used a pattern replacement hack. Here is the
Makefile:
--------------
SOURCES= prog.c sub.c
ULIBS= ../lib/$(ARCH)/lib.a
PROGRAM= prog
CFLAGS= -O3 $(TARGET_ARCH:-sun3=-f68881) <<< Gross Hack!!!
OBJECTS= $(SOURCES:.c=.o)
ARCH= $(TARGET_ARCH:-%=%)
all debug profile: $(PROGRAM)
debug := CFLAGS= -g <<< This is where it should
profile := CFLAGS= -pg -O3 <<< really be done
$(PROGRAM): $(OBJECTS)
$(LINK.c) -o $@ $(OBJECTS) $(ULIBS)
---------------
This works for a sun3, (when not doing a make debug or profile), but on a
sun4 it gives an ugly but apparently harmless duplicate flag:
cc -O3 -sun4 -sun4 -c prog.c
It would not work in the general case of more than two alternatives (like
if I gave a hoot about -sun386i) or if the macro must have different
values for each alternative (i.e. the unmodified value -sun4 is not
acceptable). Surely this is an extremely common situation; I'm surprised
that Sun's otherwise good make manual has absolutely no examples of
variants depending on TARGET_ARCH.
If you have a concise, sophisticated solution, please mail it to me; I
will summarize for the group.
Dave Kemp <Kemp at dockmaster.ncsc.mil>
More information about the Comp.sys.sun
mailing list