Makefile的使用方法

    技术2025-06-10  51

    test.c源码:

        #include <stdio.h>

         void main(void)    {          int sunhao = 9;          #ifdef KT7208                  sunhao = 7208;          #endif          #ifdef KT7216                  sunhao = 7216;           #endif          printf("%d/n", sunhao);

              char *p;          #ifdef CsEn                  p = "CsEn";          #endif          #ifdef M-L                  p = "M-L";          #endif          printf("%s/n", p);     }

     

    Makeile源码:

    ifeq ($(DEVICE),KT7216)         CFLAGS += -D$(DEVICE)     // "-D"的作用就类似源码中 "#define $(DEVICE)" 的作用。endififeq ($(DEVICE),KT7208)         CFLAGS += -D$(DEVICE)endif CFLAGS   += -D$(L)sunhao:          gcc $(CFLAGS) test.c -o $@clean:          rm sunhao

     

     

    ~:make DEVICE=KT7208 L=CsEn

     

    执行结果为:

             7208

             CsEn

     

     

    最新回复(0)