summaryrefslogtreecommitdiffstats
path: root/toolbox/Android.mk
blob: 92674385098053e366c2d1e04dfd214db5db8137 (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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
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.
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

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 :=

        OUR_TOOLS := \
            newfs_msdos

        ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
            OUR_TOOLS += \
                iftop \
                ioctl \
                nandread \
                prlimit \
                sendevent \
                start \
                stop
        endif

        ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
            BSD_TOOLS += \
                dd \
                du \

            OUR_TOOLS += \
                df \
                ionice \
                log \
                ls \
                lsof \
                mount \
                ps \
                renice \
                top \
                uptime \
                watchprops
        endif
    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
    endif
endif

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
    # Special rules for 9.0
    OUR_TOOLS += getevent
    LOCAL_C_INCLUDES += $(TWRP_TOOLBOX_PATH)
    LOCAL_WHOLE_STATIC_LIBRARIES += libtoolbox_dd

    ifneq ($(TW_USE_TOOLBOX), true)
        OUR_TOOLS += newfs_msdos
    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

LOCAL_SHARED_LIBRARIES += libselinux

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.
ifneq ($(TW_USE_TOOLBOX), true)
    LOCAL_SRC_FILES += \
        ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
        ../../../$(TWRP_TOOLBOX_PATH)/ls.c
    OUR_TOOLS += setprop
    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
        # Special rules for <= 8.1
        LOCAL_SRC_FILES += \
            ../../../$(TWRP_TOOLBOX_PATH)/getprop.c
        OUR_TOOLS += getprop
    endif
endif
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; 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
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
    LOCAL_SRC_FILES += getprop.cpp
    LOCAL_SHARED_LIBRARIES += libbase
    LOCAL_STATIC_LIBRARIES += libpropertyinfoparser
    LOCAL_CPPFLAGS += -std=c++17
    OUR_TOOLS += getprop
endif

LOCAL_MODULE := toolbox_recovery
LOCAL_MODULE_STEM := toolbox
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-const-variable

# 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):
	$(transform-generated-source)

# 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)

# 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)
	@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

ifeq ($(TW_USE_TOOLBOX), true)
    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
        include $(CLEAR_VARS)
        LOCAL_MODULE := dd_twrp
        LOCAL_MODULE_STEM := dd
        LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
        LOCAL_MODULE_TAGS := optional
        LOCAL_CFLAGS := -include bsd-compatibility.h -DNO_CONV -Wno-unused-parameter
        LOCAL_C_INCLUDES := system/core/toolbox/upstream-netbsd/include/ system/core/toolbox/upstream-netbsd/bin/dd system/core/toolbox

        LOCAL_SHARED_LIBRARIES := \
	        libcutils \

        LOCAL_SRC_FILES += \
            upstream-netbsd/bin/dd/args.c \
            upstream-netbsd/bin/dd/conv.c \
            upstream-netbsd/bin/dd/dd.c \
            upstream-netbsd/bin/dd/dd_hostops.c \
            upstream-netbsd/bin/dd/misc.c \
            upstream-netbsd/bin/dd/position.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

        include $(BUILD_EXECUTABLE)
    endif
endif

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