[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help needed for writing a rule

From: Patrick Begou
Subject: Re: Help needed for writing a rule
Date: Fri, 25 Nov 2022 18:06:45 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

Hi all,

Thanks for your suggestions.

@Paul: solution tested. Yes it works fine and is very near the initial syntax used in the original Makefile.

# building only the mod file
LIB/%_M.mod: $$(shell echo $$* | tr A-Z a-z)_m.f90
    @echo "building $*_M.mod from $<"
    touch $@

%.o:     %.f90
    @echo "building $@ from $<"
    touch $@

all: toto.o

    rm -f *.mod *.o LIB/*

toto.o :  toto.f90 LIB/TITI_M.mod titi_m.o
titi_m.o LIB/TITI_M.mod:        titi_m.f90

@kaz: Works fine for building the application but each make rebuilds everything as there are no dependency
 on the target. Each time I run make, FOO.out is built again.
%.out: UC = $$(echo $* | tr [a-z] [A-Z])

        @echo "making $*.out (upcased as $(UC).out)"
        touch $(UC).out


@David I think I'll have the same pitfall than with Kaz strategy. No ?


Le 25/11/2022 à 17:49, David Boyce a écrit :
Possibly this would be helpful?

# Usage: $(call toupper,<string>)
#   $1: string to be uppercased
toupper = $(strip \
  $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E, \
  $(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K, \   $(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q, \   $(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W, \
  $(subst x,X,$(subst y,Y,$(subst z,Z,$1)))))))))))))))))))))))))))

On Fri, Nov 25, 2022 at 11:33 AM Kaz Kylheku <> wrote:

    On 2022-11-25 06:26, Patrick Begou wrote:
    > Hi all,
    > I'm stuck for several hours in trying to write a rule for
    managing fortran modules. My difficulty is that the Cray compiler
    requires a  module name written in upper case.
    > example: if file is "toto_m.f90", it contains a module called
    "toto_m" and the module file will be "TOTO_M.mod".
    > How can I write a generic rule for building TOTO_M.mod from
    toto_m.f90 source and put it in the LIB folder ?
    > Of course,the following lines will not work as the "%" token
    will be in uppercase on the right hand side.
    > # building only the mod file
    > LIB/%_M.mod: %_m.f90
    >         @echo "building $*_M.mod"
    >         touch $@

    Can you make symbolic links that have the upper case, and feed
    them to the compiler?

      LIB/%_m.mod: %_m.f90
              @echo "building $*_m.mod"
              touch $@
              ln -sf $@ $$(echo $*_m | tr [a-z] [A-Z]).mod

    Here I have a working sample where I use a target-specific
    assignment to define
    a variable called $(UC) which holds the upper-cased stem:

      $ make
      make: *** No rule to make target ' <>',
    needed by 'foo.out'.  Stop.
      $ touch <>
      $ make
      making foo.out (upcased as FOO.out)


      $ cat Makefile
      %.out: UC = $$(echo $* | tr [a-z] [A-Z])

              @echo "making $*.out (upcased as $(UC).out)"

      foo.out: <>

    The $* is evaluated at the time the target is dispatched, because it's
    in a target-specific assignment. The $$ on $$(echo ...) ensures
    that we get a literal $(echo ...) passed to the shell during
    recipe execution.

    Hope I didn't do anything wrong that makes this inapplicable to
    your case!

    Cheers ...

reply via email to

[Prev in Thread] Current Thread [Next in Thread]