SUMMARY: Question about make

From: Eiler, James A. <James.Eiler_at_alcoa.com>
Date: Wed, 07 Aug 2002 14:57:15 -0400

Many thanks to:

Paul Gallop
Peyton Bland
Steve J. Dyer
Joerg Bruehe

Original Question:

Trying to put together a Makefile. I've got some "customers" who need
FORTRAN and C modules in a library and I've got other customers who
emphatically don't want anything to do with FORTRAN - hence the library must
be only C.

I'd like to do something with make that automatically checks to see if the
FORTRAN compiler exists on a given system - then, if so, go ahead and
compile and generate the library.

I've currently got a macro that can be uncommented to get make to include
the FORTRAN stuff, but think you all could help me find a better way!

Final Solution:

Decided to use an approach suggested by Joerg Bruehe: Use a hierarchy of
makefiles.

My "first" makefile looks like this:

mkdepend:
        _at_-if ( type f95 >> /dev/null ) ; then \
           make -f Makefile.ara "FORTRAN=TRUE", "FOR=f95"; \
        elif ( type f90 >> /dev/null ); then \
           make -f Makefile.ara "FORTRAN=TRUE", "FOR=f90"; \
        elif ( type f77 >> /dev/null ); then \
           make -f Makefile.ara "FORTRAN=TRUE", "FOR=f77"; \
        else \
           make -f Makefile.ara; \
        fi

depend:
        make -f Makefile.ara depend

clean:
        make -f Makefile.ara clean

My "second" makefile (Makefile.ara) then uses the make macro substitution
feature to create my list of modules to be included in my library... here
are the salient parts of Makefile.ara:

###########################################################################
# Define objects to put into the ara library
###########################################################################
#
# The following is a macro substitution of the form:
#
# $(MACRO?string1:string2)
#
# If MACRO is defined, string1 is assigned to MACRO. Otherwise, string2
# is assigned to MACRO.
#
# So, if the macro FORTRAN has been defined (see Makefile), LIBARA_OBJECTS
# will be assigned all of the C and FORTRAN objects that make up the
# library. Otherwise, only the C objects will be used.
#
LIBARA_OBJECTS = $(FORTRAN?${LIBARA_OBJS_C}
${LIBARA_OBJS_F}:${LIBARA_OBJS_C})

LIBARA_OBJS_C=\
        ${OBJDIR}/bumpit.o \
        ${OBJDIR}/datestr.o \
        ${OBJDIR}/dump_ptbl_info.o \
        ${OBJDIR}/elapsed_time.o \
        .
        .
        .
        ${OBJDIR}/utimdat.o

LIBARA_OBJS_F=\
        ${OBJDIR}/asdate.o\
        ${OBJDIR}/astime.o\
        ${OBJDIR}/getargs_f.o\
        ${OBJDIR}/int2.o\
        ${OBJDIR}/int4.o\
        ${OBJDIR}/rbit.o\
        ${OBJDIR}/rjbit.o\
        ${OBJDIR}/sbit.o\
        ${OBJDIR}/sjbit.o\
        ${OBJDIR}/zbit.o\
        ${OBJDIR}/zjbit.o


libara.a: $(LIBDIR)/libara.a
$(LIBDIR)/libara.a : $(LIBARA_OBJECTS)
        $(AR) -r $_at_ $(LIBARA_OBJECTS)
Received on Wed Aug 07 2002 - 18:57:35 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:43 NZDT