]> git.pld-linux.org Git - packages/android-tools.git/blob - generate_build.rb
up to 34.0.5
[packages/android-tools.git] / generate_build.rb
1 #!/usr/bin/ruby
2
3 # Android build system is complicated and does not allow to build
4 # separate parts easily.
5 # This script tries to mimic Android build rules.
6
7 def expand(dir, files)
8   files.map{|f| File.join(dir,f)}
9 end
10
11 # Compiles sources to *.o files.
12 # Returns array of output *.o filenames
13 def compile(sources, cflags)
14   outputs = []
15   for s in sources
16     ext = File.extname(s)
17     
18     case ext
19     when '.c'
20         cc = '${CC:-gcc}'
21         lang_flags = '-std=gnu11 $CFLAGS $CPPFLAGS'
22     when '.cpp', '.cc'
23         cc = '${CXX:-g++}'
24         lang_flags = '-std=gnu++14 $CXXFLAGS $CPPFLAGS'
25     else
26         raise "Unknown extension #{ext}"
27     end
28
29     output = s + '.o'
30     outputs << output
31     puts "#{cc} -o #{output} #{lang_flags} #{cflags} -c #{s}\n"
32   end
33
34   return outputs
35 end
36
37 # Links object files
38 def link(output, objects, ldflags)
39   puts "g++ -o #{output} #{ldflags} $LDFLAGS #{objects.join(' ')}"
40 end
41
42 minicryptfiles = %w(
43   dsa_sig.c
44   p256_ec.c
45   rsa.c
46   sha.c
47   p256.c
48   p256_ecdsa.c
49   sha256.c
50 )
51 libminicrypt = compile(expand('libmincrypt', minicryptfiles), '-Iinclude')
52
53 adbdfiles = %w(
54   adb.cpp
55   adb_auth.cpp
56   adb_io.cpp
57   adb_listeners.cpp
58   adb_utils.cpp
59   sockets.cpp
60   transport.cpp
61   transport_local.cpp
62   transport_usb.cpp
63   services.cpp
64   adb_trace.cpp
65   get_my_path_linux.cpp
66   usb_linux.cpp
67   diagnose_usb.cpp
68   adb_auth_host.cpp
69   sysdeps_unix.cpp
70 )
71 libadbd = compile(expand('adb', adbdfiles), '-DADB_REVISION=\"$PKGVER\" -DADB_HOST=1 -fpermissive -Iinclude -Ibase/include')
72
73 adbshfiles = %w(
74   fdevent.cpp
75   shell_service.cpp
76   shell_service_protocol.cpp
77 )
78 libadbsh = compile(expand('adb', adbshfiles), '-DADB_REVISION=\"$PKGVER\" -DADB_HOST=0 -D_Nonnull= -D_Nullable= -fpermissive -Iadb -Iinclude -Ibase/include')
79
80 adbfiles = %w(
81   console.cpp
82   commandline.cpp
83   adb_client.cpp
84   file_sync_client.cpp
85   line_printer.cpp
86   client/main.cpp
87 )
88 libadb = compile(expand('adb', adbfiles), '-DADB_REVISION=\"$PKGVER\" -D_GNU_SOURCE -DADB_HOST=1 -D_Nonnull= -D_Nullable= -fpermissive -Iadb -Iinclude -Ibase/include')
89
90 basefiles = %w(
91   file.cpp
92   logging.cpp
93   parsenetaddress.cpp
94   stringprintf.cpp
95   strings.cpp
96   errors_unix.cpp
97 )
98 libbase = compile(expand('base', basefiles), '-DADB_HOST=1 -D_GNU_SOURCE -Ibase/include -Iinclude')
99
100 logfiles = %w(
101   logger_write.c
102   config_write.c
103   logger_lock.c
104   logger_name.c
105   log_event_list.c
106   log_event_write.c
107   fake_log_device.c
108   fake_writer.c
109 )
110 liblog = compile(expand('liblog', logfiles), '-DLIBLOG_LOG_TAG=1005 -DFAKE_LOG_DEVICE=1 -D_GNU_SOURCE -Ilog/include -Iinclude')
111
112 cutilsfiles = %w(
113   load_file.c
114   socket_inaddr_any_server_unix.c
115   socket_local_client_unix.c
116   socket_local_server_unix.c
117   socket_loopback_client_unix.c
118   socket_loopback_server_unix.c
119   socket_network_client_unix.c
120   threads.c
121   sockets.cpp
122   sockets_unix.cpp
123 )
124 libcutils = compile(expand('libcutils', cutilsfiles), '-D_GNU_SOURCE -Iinclude')
125
126 link('adb/adb', libbase + liblog + libcutils + libadbd + libadbsh + libadb, '-lrt -ldl -lpthread -lcrypto -lutil')
127
128
129 fastbootfiles = %w(
130   socket.cpp
131   tcp.cpp
132   udp.cpp
133   protocol.cpp
134   engine.cpp
135   bootimg_utils.cpp
136   fastboot.cpp
137   util.cpp
138   fs.cpp
139   usb_linux.cpp
140   util_linux.cpp
141 )
142 libfastboot = compile(expand('fastboot', fastbootfiles), '-DFASTBOOT_REVISION=\"$PKGVER\" -D_GNU_SOURCE -Iadb -Iinclude -Imkbootimg -Ibase/include -Ilibsparse/include -Iextras/ext4_utils -Iextras/f2fs_utils')
143
144 sparsefiles = %w(
145   backed_block.c
146   output_file.c
147   sparse.c
148   sparse_crc32.c
149   sparse_err.c
150   sparse_read.c
151 )
152 libsparse = compile(expand('libsparse', sparsefiles), '-Ilibsparse/include')
153
154 zipfiles = %w(
155   zip_archive.cc
156 )
157 libzip = compile(expand('libziparchive', zipfiles), '-Ibase/include -Iinclude')
158
159 utilfiles = %w(
160   FileMap.cpp
161 )
162 libutil = compile(expand('libutils', utilfiles), '-Iinclude')
163
164 ext4files = %w(
165   make_ext4fs.c
166   ext4fixup.c
167   ext4_utils.c
168   allocate.c
169   contents.c
170   extent.c
171   indirect.c
172   sha1.c
173   wipe.c
174   crc16.c
175   ext4_sb.c
176 )
177 libext4 = compile(expand('extras/ext4_utils', ext4files), '-Ilibsparse/include -Iinclude')
178
179 link('fastboot/fastboot', libsparse + libzip + liblog + libutil + libcutils + libbase + libext4 + libfastboot + libadbsh + libadbd, '-lpthread -lselinux -lz -lcrypto -lutil')
180
181 simg2imgfiles = %w(
182   simg2img.c
183 )
184 libsimg2img = compile(expand('libsparse', simg2imgfiles), '-Iinclude -Ilibsparse/include')
185 link('libsparse/simg2img', libsparse + libsimg2img, '-lz')
186
187 img2simgfiles = %w(
188   img2simg.c
189 )
190 libimg2simg = compile(expand('libsparse', img2simgfiles), '-Iinclude -Ilibsparse/include')
191 link('libsparse/img2simg', libsparse + libimg2simg, '-lz')
This page took 0.159767 seconds and 3 git commands to generate.