iot_programe Makefile hacking

/*****************************************************************************
 *                      iot_programe Makefile hacking
 * 说明:
 *     富林这边编写的demo,看一下其Makefile是怎么处理所有的源代码的,有生成动态、
 * 静态链接库,以及直接编译输出,其实模块化编译的模式还是很好的。
 *
 *                                           2017-8-12 深圳 龙华樟坑村 曾剑锋
 ****************************************************************************/


一、参考文档:
    1. Linux GCC编译使用动态、静态链接库
        http://blog.csdn.net/a600423444/article/details/7206015

二、Makefile
    all:
        make -C  gpio_led/main all
        ...

    clean:
        make -C  gpio_led/main   clean
        ...

三、gpio_led/main/Makefile
    CC = arm-linux-gnueabihf-gcc
    
    all:
        make -C ../src
        # use share library
        $(CC)      main.c   -o gpio_led -L ../src/ -lgpio_led

        # directory compile with source code
        $(CC)        main.c   ../src/gpio_led.c  -o my_gpio_led
    
    clean:
        rm gpio_led  my_gpio_led -rf
        make -C ../src clean
    
四、gpio_led/src/Makefile
    CC = arm-linux-gnueabihf-gcc
    AR = arm-linux-gnueabihf-ar

    all:
        # output share library
        $(CC)  gpio_led.c   -fPIC -shared -o   libgpio_led.so

        # output static library
        $(CC)  -c   gpio_led.c  -o  libgpio_led.o -I ../include
        $(AR)  rcv  libgpio_led.a  libgpio_led.o

    clean:
        rm *.so *.o *.a

 

posted on 2017-08-12 10:25  zengjf  阅读(255)  评论(0编辑  收藏  举报

导航