Skip to content

Instantly share code, notes, and snippets.

@anatol
Created January 13, 2016 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatol/5ff0c44de39e6854087d to your computer and use it in GitHub Desktop.
Save anatol/5ff0c44de39e6854087d to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Android build system is ugly. It uses its own complicated Make-based system,
# mixes C and C++ in the project.
# This script generates a simple script to build the Android tools.
def expand(dir, files)
files.uniq.map{|f| File.join(dir,f)}
end
# Compile sources to *.o files. One *.o file per input.
# Returns array of *.o filenames
def compile(sources, cflags)
outputs = []
for s in sources
ext = File.extname(s)
case ext
when '.c'
cc = 'gcc'
lang_flags = '-std=c11'
when '.cpp'
cc = 'g++'
lang_flags = '-std=c++11'
else
raise "Unknown extension #{ext}"
end
output = s + '.o'
outputs << output
puts "#{cc} #{lang_flags} #{cflags} -o #{output} -c #{s}\n"
end
return outputs
end
# compiles and link
def link(output, objects, ldflags)
puts "g++ #{ldflags} -o #{output} #{objects.join(' ')}"
end
libminicrypt = compile(Dir['core/libmincrypt/*.c'], '-Icore/include')
libmkbootimg = compile(['core/mkbootimg/mkbootimg.c'], '-Icore/include')
link('mkbootimg', libminicrypt + libmkbootimg, nil)
adbdfiles = %w(
adb.cpp
adb_auth.cpp
adb_io.cpp
adb_listeners.cpp
adb_utils.cpp
sockets.cpp
transport.cpp
transport_local.cpp
transport_usb.cpp
fdevent.cpp
get_my_path_linux.cpp
usb_linux.cpp
adb_auth_host.cpp
)
libadbd = compile(expand('core/adb', adbdfiles), '-Icore/include -Icore/base/include -DADB_HOST=1 -fpermissive')
adbfiles = %w(
adb_main.cpp
console.cpp
commandline.cpp
adb_client.cpp
services.cpp
file_sync_client.cpp
)
libadb = compile(expand('core/adb', adbfiles), '-Icore/include -Icore/base/include -DADB_REVISION=\"5.1.1\" -D_GNU_SOURCE -DADB_HOST=1 -DWORKAROUND_BUG6558362 -fpermissive')
basefiles = %w(
file.cpp
stringprintf.cpp
strings.cpp
)
libbase = compile(expand('core/base', basefiles), '-Icore/base/include -Icore/include -DADB_HOST=1')
logfiles = %w(
logd_write.c
log_event_write.c
fake_log_device.c
)
liblog = compile(expand('core/liblog', logfiles), '-Icore/log/include -Icore/include -DLIBLOG_LOG_TAG=1005 -DFAKE_LOG_DEVICE=1 -D_GNU_SOURCE')
cutilsfiles = %w(
load_file.c
socket_inaddr_any_server.c
socket_local_client.c
socket_local_server.c
socket_loopback_client.c
socket_loopback_server.c
socket_network_client.c
)
libcutils = compile(expand('core/libcutils', cutilsfiles), '-Icore/include -D_GNU_SOURCE')
link('adb', libbase + liblog + libcutils + libadbd + libadb, '-lrt -ldl -lpthread -lcrypto')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment