2

メイクファイルの書き方を学んでいますが、メイクファイルの階層をどのように設計すればよいかはっきりとはわかりません。説明するのは簡単ではないので、私が今持っているものを正確に投稿します。提案は大歓迎です.

そこで私が聞きたいのは

1. Does my common.mk a general practice to contain TOP_DIR variable?
2. How can I make makefile(1) call makefile(2) if l_util objects are missing. 

私はC++アルゴリズムを学ぶために使用したようなフォルダ階層を持っています:

-learning
    - introduction_to_algorithms
        - insertion_sort
            - insertion_sort.cpp
            - makefile(1)
    - l_util
        - include
            - l_util_stlutil.h
            - l_util_numberutil.h
        - l_util_stlutil.cpp
        - l_util_numberutil.cpp
        - makefile(2)
    - common.mk

ここで、input_sort.cpp には l_util ファイルが含まれます。これが私のmakeファイルです:

common.mk:

1 # This must be the first this in Makefile.common
2 TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
3
4 CC := g++

メイクファイル (1):

1 include ../../common.mk
2
3 CPP_SRCS := \
4 insertion_sort.cpp \
5
6 LIBS := \
7
8 OBJS := \
9 insertion_sort.o \
10
11 OTHER_OBJS := \
12 $(TOP_DIR)l_util/l_util_stlutil.o \
13 $(TOP_DIR)l_util/l_util_numberutil.o \
14
15 INCLUDE_PATH := \
16 $(TOP_DIR)l_util/include
17
18 TASK := insertion_sort.tsk
19
20 # Tool invocations
21 $(TASK): $(OBJS) $(OTHER_OBJS)
22     $(CC) -o $(TASK) $(OBJS) $(OTHER_OBJS) $(LIBS)
23     @echo 'Finished building target: $@'
24
25 $(OBJS): $(CPP_SRCS)
26     $(CC) -c -Wall -I$(INCLUDE_PATH) $(CPP_SRCS)
27     @echo 'Finished building target: $@'
28
29 # Other Targets
30 .PHONY: clean
31 clean:
32     -$(RM) $(OBJS) $(OTHER_OBJS) $(TASK)

メイクファイル (2):

1 include ../common.mk
2
3 CPP_SRCS := \
4 l_util_stlutil.cpp \
5 l_util_numberutil.cpp \
6
7 LIBS := \
8
9 OBJS := \
10 l_util_numberutil.o \
11 l_util_stlutil.o \
12
13 $(OBJS): $(CPP_SRCS)
14     $(CC) -c -Wall $(CPP_SRCS)
15     @echo 'Finished building target: $@'
16
17 # Other Targets
18 .PHONY: clean
19 clean:
20     -$(RM) $(OBJS)

insert_sort フォルダーで make を実行すると、次のようになります。

1 g++ -c -Wall -I../../l_util/include insertion_sort.cpp
2 Finished building target: insertion_sort.o
3 c++    -c -o ../../l_util/l_util_stlutil.o ../../l_util/l_util_stlutil.cpp
4 c++    -c -o ../../l_util/l_util_numberutil.o ../../l_util/l_util_numberutil.cpp
5 g++ -o insertion_sort.tsk insertion_sort.o  ../../l_util/l_util_stlutil.o   
  ../../l_util/l_util_numberutil.o
6 Finished building target: insertion_sort.tsk

3行目と4行目はmakefile(2)によって生成されたものではないと思います.makefile(2)を呼び出さずに自動的に呼び出されたようです.

4

2 に答える 2

1

makefile1 にいくつかのコードを追加します: $(OTHER_OBJS): make -C "The absolute dir of your makefile2"

あなたのmakefile2はどこにあるのか、makefile1に伝える必要があります。

于 2013-08-21T03:24:02.543 に答える