234 lines
6.1 KiB
Ruby
234 lines
6.1 KiB
Ruby
#!/usr/bin/ruby
|
|
|
|
# Android build system is complicated and does not allow to build
|
|
# separate parts easily.
|
|
# This script tries to mimic Android build rules.
|
|
|
|
def expand(dir, files)
|
|
files.map{|f| File.join(dir,f)}
|
|
end
|
|
|
|
# Compiles sources to *.o files.
|
|
# Returns array of output *.o filenames
|
|
def compile(sources, cflags)
|
|
outputs = []
|
|
for s in sources
|
|
ext = File.extname(s)
|
|
|
|
case ext
|
|
when '.c'
|
|
cc = 'cc'
|
|
lang_flags = '-std=gnu11 $CFLAGS $CPPFLAGS'
|
|
when '.cpp', '.cc'
|
|
cc = 'cxx'
|
|
lang_flags = '-std=gnu++17 $CXXFLAGS $CPPFLAGS'
|
|
else
|
|
raise "Unknown extension #{ext}"
|
|
end
|
|
|
|
output = s + '.o'
|
|
outputs << output
|
|
puts "build #{output}: #{cc} #{s}\n cflags = #{lang_flags} #{cflags}"
|
|
end
|
|
|
|
return outputs
|
|
end
|
|
|
|
# dir - directory where ninja file is located
|
|
# lib - static library path relative to dir
|
|
def subninja(dir, lib)
|
|
puts "subninja #{dir}build.ninja"
|
|
return lib.each{|l| dir + l}
|
|
end
|
|
|
|
# Links object files
|
|
def link(output, objects, ldflags)
|
|
puts "build #{output}: link #{objects.join(' ')}\n ldflags = #{ldflags} $LDFLAGS"
|
|
end
|
|
|
|
puts "# This set of commands generated by generate_build.rb script\n\n"
|
|
puts "CC = #{ENV['CC'] || 'clang'}"
|
|
puts "CXX = #{ENV['CXX'] || 'clang++'}\n\n"
|
|
puts "CFLAGS = #{ENV['CFLAGS']}"
|
|
puts "CXXFLAGS = #{ENV['CXXFLAGS']}"
|
|
puts "LDFLAGS = #{ENV['LDFLAGS']}"
|
|
puts "PKGVER = #{ENV['PKGVER']}\n\n"
|
|
|
|
|
|
puts """
|
|
rule cc
|
|
command = $CC $cflags -c $in -o $out
|
|
|
|
rule cxx
|
|
command = $CXX $cflags -c $in -o $out
|
|
|
|
rule link
|
|
command = $CXX $ldflags $LDFLAGS $in -o $out
|
|
|
|
|
|
"""
|
|
|
|
adbdfiles = %w(
|
|
adb.cpp
|
|
adb_io.cpp
|
|
adb_listeners.cpp
|
|
adb_trace.cpp
|
|
adb_utils.cpp
|
|
adb_unique_fd.cpp
|
|
sockets.cpp
|
|
transport.cpp
|
|
transport_local.cpp
|
|
transport_usb.cpp
|
|
fdevent.cpp
|
|
shell_service_protocol.cpp
|
|
)
|
|
libadbd = compile(expand('core/adb', adbdfiles), '-DADB_HOST=1 -Icore/diagnose_usb/include -Icore/include -Icore/base/include -Icore/adb -Icore/libcrypto_utils/include')
|
|
|
|
adbfiles = %w(
|
|
client/auth.cpp
|
|
client/console.cpp
|
|
socket_spec.cpp
|
|
client/bugreport.cpp
|
|
client/line_printer.cpp
|
|
client/commandline.cpp
|
|
client/adb_client.cpp
|
|
services.cpp
|
|
client/file_sync_client.cpp
|
|
sysdeps_unix.cpp
|
|
sysdeps/errno.cpp
|
|
sysdeps/posix/network.cpp
|
|
client/main.cpp
|
|
client/usb_dispatch.cpp
|
|
client/usb_linux.cpp
|
|
client/usb_libusb.cpp
|
|
client/transport_mdns.cpp
|
|
)
|
|
libadb = compile(expand('core/adb', adbfiles), '-D_GNU_SOURCE -DADB_HOST=1 -Icore/libcrypto_utils/include -Iboringssl/src/include -Icore/include -Icore/base/include -Icore/adb -Imdnsresponder/mDNSShared')
|
|
|
|
basefiles = %w(
|
|
file.cpp
|
|
threads.cpp
|
|
logging.cpp
|
|
parsenetaddress.cpp
|
|
stringprintf.cpp
|
|
strings.cpp
|
|
errors_unix.cpp
|
|
test_utils.cpp
|
|
)
|
|
libbase = compile(expand('core/base', basefiles), '-DADB_HOST=1 -Icore/base/include -Icore/include')
|
|
|
|
logfiles = %w(
|
|
log_event_write.c
|
|
fake_log_device.c
|
|
log_event_list.c
|
|
logger_write.c
|
|
config_write.c
|
|
config_read.c
|
|
logger_lock.c
|
|
local_logger.c
|
|
fake_writer.c
|
|
logger_name.c
|
|
stderr_write.c
|
|
logprint.c
|
|
)
|
|
liblog = compile(expand('core/liblog', logfiles), '-DLIBLOG_LOG_TAG=1006 -D_XOPEN_SOURCE=700 -DFAKE_LOG_DEVICE=1 -Icore/libsystem/include -Icore/liblog/include -Icore/include')
|
|
|
|
cutilsfiles = %w(
|
|
fs_config.cpp
|
|
canned_fs_config.cpp
|
|
android_get_control_file.cpp
|
|
socket_network_client_unix.cpp
|
|
socket_inaddr_any_server_unix.cpp
|
|
sockets.cpp
|
|
sockets_unix.cpp
|
|
socket_local_client_unix.cpp
|
|
socket_local_server_unix.cpp
|
|
)
|
|
libcutils = compile(expand('core/libcutils', cutilsfiles), '-D_GNU_SOURCE -Icore/libcutils/include -Icore/include -Icore/base/include')
|
|
|
|
diagnoseusbfiles = %w(
|
|
diagnose_usb.cpp
|
|
)
|
|
libdiagnoseusb = compile(expand('core/diagnose_usb', diagnoseusbfiles), '-Icore/diagnose_usb/include -Icore/include -Icore/base/include')
|
|
|
|
libcryptofiles = %w(
|
|
android_pubkey.c
|
|
)
|
|
libcrypto = compile(expand('core/libcrypto_utils', libcryptofiles), '-Icore/libcrypto_utils/include -Iboringssl/src/include')
|
|
|
|
utilfiles = %w(
|
|
FileMap.cpp
|
|
Unicode.cpp
|
|
SharedBuffer.cpp
|
|
String8.cpp
|
|
String16.cpp
|
|
)
|
|
libutil = compile(expand('core/libutils', utilfiles), '-Icore/include')
|
|
|
|
mdnsfiles = %w(
|
|
mDNSShared/dnssd_ipc.c
|
|
mDNSShared/dnssd_clientstub.c
|
|
)
|
|
mdns = compile(expand('mdnsresponder', mdnsfiles), '-D_GNU_SOURCE -DHAVE_IPV6 -DHAVE_LINUX -DNOT_HAVE_SA_LEN -DUSES_NETLINK -UMDNS_DEBUGMSGS -DMDNS_DEBUGMSGS=0 -Imdnsresponder/mDNSShared -Imdnsresponder/mDNSCore -Iinclude')
|
|
|
|
zipfiles = %w(
|
|
zip_archive_stream_entry.cc
|
|
zip_archive.cc
|
|
)
|
|
libzip = compile(expand('core/libziparchive', zipfiles), '-Icore/libziparchive/include -Icore/base/include -Icore/include')
|
|
|
|
boringcryptofiles = %w(
|
|
bn/cmp.c
|
|
bn/bn.c
|
|
bytestring/cbb.c
|
|
mem.c
|
|
buf/buf.c
|
|
bio/file.c
|
|
bn/convert.c
|
|
base64/base64.c
|
|
)
|
|
|
|
boringcrypto = compile(expand('boringssl/src/crypto', boringcryptofiles), '-Iboringssl/src/include -Iinclude')
|
|
|
|
link('adb', libbase + liblog + libcutils + libcrypto + libadbd + libadb + libdiagnoseusb + libutil + libzip + mdns + boringcrypto, '-lz -lcrypto -lpthread -lusb-1.0')
|
|
|
|
|
|
fastbootfiles = %w(
|
|
bootimg_utils.cpp
|
|
fs.cpp
|
|
socket.cpp
|
|
tcp.cpp
|
|
udp.cpp
|
|
usb_linux.cpp
|
|
util.cpp
|
|
main.cpp
|
|
engine.cpp
|
|
fastboot.cpp
|
|
fastboot_driver.cpp
|
|
)
|
|
libfastboot = compile(expand('core/fastboot', fastbootfiles), '-DFASTBOOT_VERSION="\"$PKGVER\"" -D_GNU_SOURCE -D_XOPEN_SOURCE=700 -DUSE_F2FS -Icore/base/include -Icore/include -Icore/adb -Icore/libsparse/include -Icore/mkbootimg/include/bootimg -Icore/libziparchive/include -Icore/diagnose_usb/include')
|
|
|
|
sparsefiles = %w(
|
|
backed_block.cpp
|
|
output_file.cpp
|
|
sparse.cpp
|
|
sparse_crc32.cpp
|
|
sparse_err.cpp
|
|
sparse_read.cpp
|
|
)
|
|
libsparse = compile(expand('core/libsparse', sparsefiles), '-Icore/libsparse/include -Icore/base/include')
|
|
|
|
link('fastboot', libsparse + libzip + libcutils + liblog + libutil + libbase + libfastboot + libdiagnoseusb, '-lz -lpcre2-8 -lpthread -ldl')
|
|
|
|
simg2imgfiles = %w(
|
|
simg2img.cpp
|
|
)
|
|
libsimg2img = compile(expand('core/libsparse', simg2imgfiles), '-Iinclude -Icore/libsparse/include')
|
|
link('simg2img', libbase + libsparse + libsimg2img, '-lz')
|
|
|
|
img2simgfiles = %w(
|
|
img2simg.cpp
|
|
)
|
|
libimg2simg = compile(expand('core/libsparse', img2simgfiles), '-Iinclude -Icore/libsparse/include')
|
|
link('img2simg', libbase + libsparse + libimg2simg, '-lz')
|
|
|