Functions in Makefile

后端 未结 2 1700
粉色の甜心
粉色の甜心 2021-01-30 04:16

I am writing a Makefile with a lot of repetitive stuff, e.g.

debug_ifort_Linux:
        if [ $(UNAME) = Linux ]; then                           \\
          $(MA         


        
2条回答
  •  无人共我
    2021-01-30 04:33

    You're looking for the call function.

    compile =                                                 \
            if [ $(UNAME) = $(1) ]; then                      \
              $(MAKE) FC=$(2) FFLAGS=$(3) PETSC_FFLAGS="..."  \
                      TARGET=$@ LEXT="$(4)_$(UNAME)" -e syst; \
            else                                              \
              echo $(err_arch);                               \
              exit 1;                                         \
            fi
    
    debug_ifort_Linux:
            $(call compile,Linux,ifort,$(difort),ifort)
    

    If you can restructure your Makefile a bit, though, you should see if you can use make's conditionals instead of sh's.

提交回复
热议问题