summaryrefslogtreecommitdiffstats
path: root/toolbox/Android.mk
blob: 4c3e433c21ced6dfd8abdc8340f36b27bf5a6118 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
TWRP_TOOLBOX_PATH := $(call my-dir)
LOCAL_PATH := system/core/toolbox
include $(CLEAR_VARS)

OUR_TOOLS :=

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
    OUR_TOOLS := \
        start \
        stop
endif
    
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
    OUR_TOOLS += \
        getprop \
        setprop
endif

# If busybox does not have SELinux support, provide these tools with toolbox.
# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
ifeq ($(TWHAVE_SELINUX), true)
    TOOLS_FOR_SELINUX := \
        ls

    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
        TOOLS_FOR_SELINUX += \
            load_policy \
            getenforce \
            chcon \
            restorecon \
            runcon \
            getsebool \
            setsebool
    endif

    OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))

    # toolbox setenforce is used during init, so it needs to be included here
    # symlink is omitted at the very end if busybox already provides this
    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
       OUR_TOOLS += setenforce
    endif
endif

ifeq ($(TW_USE_TOOLBOX), true)
    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
        # These are the only toolbox tools in M. The rest are now in toybox.
        BSD_TOOLS := \
            dd \
            du \

        OUR_TOOLS := \
            df \
            iftop \
            ioctl \
            ionice \
            log \
            ls \
            lsof \
            mount \
            nandread \
            newfs_msdos \
            ps \
            prlimit \
            renice \
            sendevent \
            start \
            stop \
            top \
            uptime \
            watchprops \

    else
        ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
            OUR_TOOLS += \
                mknod \
                nohup
            BSD_TOOLS := \
                cat \
                chown \
                cp \
                dd \
                du \
                grep \
                kill \
                ln \
                mv \
                printenv \
                rm \
                rmdir \
                sleep \
                sync
        else
            OUR_TOOLS += \
                cat \
                chown \
                dd \
                du \
                kill \
                ln \
                mv \
                printenv \
                rm \
                rmdir \
                setconsole \
                sleep \
                sync
        endif

        OUR_TOOLS += \
            chmod \
            clear \
            cmp \
            date \
            df \
            dmesg \
            getevent \
            hd \
            id \
            ifconfig \
            iftop \
            insmod \
            ioctl \
            ionice \
            log \
            lsmod \
            lsof \
            md5 \
            mkdir \
            mkswap \
            mount \
            nandread \
            netstat \
            newfs_msdos \
            notify \
            ps \
            readlink \
            renice \
            rmmod \
            route \
            schedtop \
            sendevent \
            smd \
            swapoff \
            swapon \
            top \
            touch \
            umount \
            uptime \
            vmstat \
            watchprops \
            wipe
        ifneq ($(TWHAVE_SELINUX), true)
            OUR_TOOLS += ls
        endif
    endif
endif

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
    ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
        OUR_TOOLS += r
    endif
endif

LOCAL_SRC_FILES := \
    toolbox.c \
    $(patsubst %,%.c,$(OUR_TOOLS))

ifneq ($(wildcard system/core/toolbox/dynarray.c),)
    LOCAL_SRC_FILES += dynarray.c
endif

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
    LOCAL_SRC_FILES += \
        pwcache.c \
        upstream-netbsd/lib/libc/gen/getbsize.c \
        upstream-netbsd/lib/libc/gen/humanize_number.c \
        upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
        upstream-netbsd/lib/libc/string/swab.c \
        upstream-netbsd/lib/libutil/raise_default_signal.c
endif

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
    LOCAL_CFLAGS += \
        -std=gnu99 \
        -Werror -Wno-unused-parameter \
        -I$(LOCAL_PATH)/upstream-netbsd/include \
        -include bsd-compatibility.h
endif

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
    LOCAL_C_INCLUDES += external/openssl/include
else
    LOCAL_C_INCLUDES += bionic/libc/bionic
endif

LOCAL_SHARED_LIBRARIES += libcutils

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
    ifeq ($(TW_USE_TOOLBOX), true)
        LOCAL_SHARED_LIBRARIES += libcrypto
    endif
else
    LOCAL_SHARED_LIBRARIES += \
        libc \
        liblog
endif

ifeq ($(TWHAVE_SELINUX), true)
    LOCAL_SHARED_LIBRARIES += libselinux
endif

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
    # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
    # The linker strips out all the unused library code in the normal case.
    LOCAL_STATIC_LIBRARIES := libusbhost
    LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
endif

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
    # Rule to make getprop and setprop in M trees where toybox normally
    # provides these tools. Toybox does not allow for easy dynamic
    # configuration, so we would have to include the entire toybox binary
    # which takes up more space than is necessary so long as we are still
    # including busybox.
    LOCAL_SRC_FILES += \
        ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
        ../../../$(TWRP_TOOLBOX_PATH)/setprop.c
    OUR_TOOLS += getprop setprop
    ifneq ($(TW_USE_TOOLBOX), true)
        LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c
    endif
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
    # Rule for making start and stop in N trees
    LOCAL_SRC_FILES += \
        ../../../$(TWRP_TOOLBOX_PATH)/start.c \
        ../../../$(TWRP_TOOLBOX_PATH)/stop.c
    OUR_TOOLS += start stop
endif

LOCAL_MODULE := toolbox_recovery
LOCAL_MODULE_STEM := toolbox
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_MODULE_TAGS := optional

# Including this will define $(intermediates) below
include $(BUILD_EXECUTABLE)

$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h

ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
    ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
else
    ALL_TOOLS := $(OUR_TOOLS)
endif

TOOLS_H := $(intermediates)/tools.h
$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
$(TOOLS_H): $(LOCAL_PATH)/Android.mk
$(TOOLS_H):
	$(transform-generated-source)

ifeq ($(TWHAVE_SELINUX), true)
    # toolbox setenforce is used during init in non-symlink form, so it was
    # required to be included as part of the suite above. if busybox already
    # provides setenforce, we can omit the toolbox symlink
    TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
    ALL_TOOLS := $(TEMP_TOOLS)
endif

# Make /sbin/toolbox launchers for each tool
SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
	@echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
	@mkdir -p $(dir $@)
	@rm -rf $@
	$(hide) ln -sf $(TOOLBOX_BINARY) $@

include $(CLEAR_VARS)
LOCAL_MODULE := toolbox_symlinks
LOCAL_MODULE_TAGS := optional
LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
include $(BUILD_PHONY_PACKAGE)

ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
    # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
    ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
    ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
        $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
endif

SYMLINKS :=
ALL_TOOLS :=
BSD_TOOLS :=
OUR_TOOLS :=
TEMP_TOOLS :=
TOOLS_FOR_SELINUX :=