• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Used to check that ndk-build does a proper topological sort of
2# module dependencies.
3#
4# Here's how this works:
5#
6#   1/ First, define a static library module named 'foo' with two source
7#      files (foo.c and foo2.c), which implement two functions
8#      (foo and foo2 respectively).
9#
10#   2/ Second, define another static library named 'bar' that depends on
11#      module 'foo' but only uses the 'foo2' function from it.
12#
13#   3/ Third, define an executable that depends on both 'foo' and 'bar',
14#      but only calls the 'foo' and 'bar' function (i.e. not foo2).
15#      Order is important, i.e. it should have a line that says:
16#
17#       LOCAL_STATIC_LIBRARIES := foo bar
18#
19#      With NDK r8b and earlier, the final link command for the executable
20#      will be like:
21#
22#        <linker> -o <executable> main.o libfoo.a libbar.a
23#
24#      Due to the way the linker works, this will fail. More specifically,
25#      when trying to add bar.o to the final image, it will not be able to
26#      find an object file that contains foo2(), because the search starts
27#      _after_ libbar.a on the command-line.
28#
29#  With a NDK that implements correct topological dependency ordering,
30#  the link line should be instead:
31#
32#        <linker> -o <executable> main.o libbar.a libfoo.a
33#
34#  Which will link, and work, correctly.
35#
36
37LOCAL_PATH := $(call my-dir)
38
39include $(CLEAR_VARS)
40LOCAL_MODULE := foo
41LOCAL_SRC_FILES := \
42    foo.c \
43    foo2.c
44include $(BUILD_STATIC_LIBRARY)
45
46include $(CLEAR_VARS)
47LOCAL_MODULE := bar
48LOCAL_SRC_FILES := bar.c
49LOCAL_STATIC_LIBRARIES := foo
50include $(BUILD_STATIC_LIBRARY)
51
52include $(CLEAR_VARS)
53LOCAL_MODULE := test_topological_sort
54LOCAL_SRC_FILES := main.c
55# IMPORTANT: foo must appear before bar here.
56LOCAL_STATIC_LIBRARIES := foo bar
57include $(BUILD_EXECUTABLE)
58