如何調用Makefile , enter to directory A and B,then make them

如何調用Makefile ,enter to directory A and B,then make them

1. it can work
must be a Makefile and use command make, .sh file maybe can not work!


all:
        cd ./A && make all
        cd ./B && make all
        gcc -c -o main.o main.c
        gcc -o math main.o ./A/add.o ./A/sub.o ./B/mul.o ./B/div.o

clean:
        rm *.o ./A/*.o ./B/*.o
2. not try      
假如在目錄M下執行makefile
target1:
     make -C A target_n  
     make -C B target_n


make -C A,進入A目錄,執行A目錄下的makefile,這時你的工作環境就在A目錄,你可以在目錄A下makefile中的target_n裏面echo `pwd`看下      

3. not try
進入到子文件夾運行
SUBDIRS = A B

$(EVERYTHING)::
    @for subdir in $(SUBDIRS); \
    do \
        echo "making $@ in $$subdir"; \
        ( cd $$subdir && $(MAKE) -f makefile $@ ) || exit 1; \
    done

大致就是如此  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章