multiple makefiles in one directory

后端 未结 4 1645
一个人的身影
一个人的身影 2020-12-13 03:28

I have a makefile in a directory of mine which builds scripts with certain environment variables set. What if I want to create another makefile in the same directory with di

相关标签:
4条回答
  • 2020-12-13 04:06

    Actually you can have two set of environment variables in the same make file. for example

    COMPILER = gcc
    CCFLAGS1 = -g
    CCFLAGS2 = -Wall
    
    a: main.c
            ${COMPILER} ${CCFLAGS1} main.c
    b: test.c
            ${COMPILER} ${CCFLAGS2} test.c
    

    then you can just say make a or make b. Depending on what you want.

    Also it is possible with -f flag to call which makefile you want to call.

    0 讨论(0)
  • 2020-12-13 04:10

    You can name makefile whatever you want. I usually name it like somename.mk. To use it later you need to tell make what makefile you want. Use -f option for this:

    make -f somename.mk
    
    0 讨论(0)
  • 2020-12-13 04:25

    You can do something like this rather than using multiple makefiles for the same purpose. You can pass the environment or set a flag to the same makefile. For eg:

    
    
        ifeq ($(ENV),ENV1)
         ENV_VAR = THIS
        else
         ENV_VAR = THAT
        endif
    
        default : test
    
        .PHONY : test
        test:
                @echo $(ENV_VAR)
    
    
    

    Then you can simply run the make command with arguments

    
    
        make ENV=ENV1
    
    
    
    0 讨论(0)
  • 2020-12-13 04:27

    You can give sensible names to the files like makefile.win and makefile.nix and use them:

    make -f makefile.win
    make -f makefile.nix
    

    or have a Makefile that contains:

    win:
      make -f makefile.win
    
    nix:
      make -f makefile.nix
    

    and use make win or make nix

    0 讨论(0)
提交回复
热议问题