This patch has been taken from the Void Linux distribution. https://github.com/voidlinux/void-packages/tree/master/srcpkgs/android-tools/patches/android-tools.patch diff --git a/Makefile b/Makefile new file mode 100644 index 000000000000..4644fc0b62ad --- /dev/null +++ Makefile @@ -0,0 +1,47 @@ +all: + $(MAKE) -C core/libcutils all + $(MAKE) -C libselinux all + $(MAKE) -C core/libziparchive all + $(MAKE) -C extras/ext4_utils all + $(MAKE) -C core/libsparse all + $(MAKE) -C core/libutils all + $(MAKE) -C core/liblog all + $(MAKE) -C core/base all + $(MAKE) -C gtest all + $(MAKE) -C extras/f2fs_utils all + $(MAKE) -C core/adb all + $(MAKE) -C core/fastboot all + +install: all + $(MAKE) -C core/adb install + $(MAKE) -C core/fastboot install + +clean: + $(MAKE) -C core/libcutils clean + $(MAKE) -C libselinux clean + $(MAKE) -C core/libziparchive clean + $(MAKE) -C extras/ext4_utils clean + $(MAKE) -C core/libsparse clean + $(MAKE) -C core/libutils clean + $(MAKE) -C core/liblog clean + $(MAKE) -C core/adb libdiagnose_usb + $(MAKE) -C core/base clean + $(MAKE) -C gtest clean + $(MAKE) -C extras/f2fs_utils clean + $(MAKE) -C core/adb clean + $(MAKE) -C core/fastboot clean + +mrproper: + $(MAKE) -C core/libcutils mrproper + $(MAKE) -C libselinux mrproper + $(MAKE) -C core/libziparchive mrproper + $(MAKE) -C extras/ext4_utils mrproper + $(MAKE) -C core/libsparse mrproper + $(MAKE) -C core/libutils mrproper + $(MAKE) -C core/liblog mrproper + $(MAKE) -C core/adb libdiagnose_usb + $(MAKE) -C core/base mrproper + $(MAKE) -C gtest mrproper + $(MAKE) -C extras/f2fs_utils mrproper + $(MAKE) -C core/adb mrproper + $(MAKE) -C core/fastboot mrproper diff --git core/adb/Makefile core/adb/Makefile new file mode 100644 index 0000000..8ef539b --- /dev/null +++ core/adb/Makefile @@ -0,0 +1,97 @@ +adb_version := $(shell git -C . rev-parse --short=12 HEAD 2>/dev/null)-android + +SRCS+= \ + adb_client.cpp \ + client/main.cpp \ + console.cpp \ + commandline.cpp \ + file_sync_client.cpp \ + line_printer.cpp \ + services.cpp \ + shell_service_protocol.cpp \ + +LIBADB_SRCS= \ + adb.cpp \ + adb_auth.cpp \ + adb_io.cpp \ + adb_listeners.cpp \ + adb_trace.cpp \ + adb_utils.cpp \ + fdevent.cpp \ + sockets.cpp \ + transport.cpp \ + transport_local.cpp \ + transport_usb.cpp \ + adb_auth_host.cpp \ + get_my_path_linux.cpp \ + sysdeps_unix.cpp \ + usb_linux.cpp \ + +LIBDIAGNOSE_USB_SRCS= \ + diagnose_usb.cpp + + +override CXXFLAGS+= \ + -I. \ + -I../include \ + -I../base/include \ + -D_Nonnull="" \ + -D_Nullable="" \ + -D_GNU_SOURCE \ + -Wall \ + -Wextra \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers \ + -Wvla \ + -DADB_REVISION='"$(adb_version)"' \ + -std=gnu++14 \ + -DADB_HOST=1 \ + -fpermissive \ + -fvisibility=hidden + + +LIBS= \ + ./libadb.a \ + ./libdiagnose_usb.a \ + ../base/libbase.a \ + ../libcutils/libcutils.a \ + ../liblog/liblog.a + +override LDFLAGS+= -lssl -lcrypto -lpthread + +OBJS= $(SRCS:.cpp=.o) +LIBADB_OBJS= $(LIBADB_SRCS:.cpp=.o) +LIBDIAGNOSE_USB_OBJS= $(LIBDIAGNOSE_USB_SRCS:.cpp=.o) + +BIN= adb + +all: $(BIN) + +adb: $(OBJS) libadb libdiagnose_usb + $(CXX) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + + +libadb: libadb.a + +libadb.a: $(LIBADB_OBJS) + $(AR) rcs $@ $(LIBADB_OBJS) + +libdiagnose_usb: libdiagnose_usb.a + +libdiagnose_usb.a: $(LIBDIAGNOSE_USB_OBJS) + $(AR) rcs $@ $(LIBDIAGNOSE_USB_OBJS) + +%.o: %.cpp + $(CXX) -c $< $(CXXFLAGS) -o $@ + +install: adb + install -Dm755 adb $(DESTDIR)$(PREFIX)/bin/adb + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) $(LIBADB_OBJS) $(LIBDIAGNOSE_USB_OBJS) + +mrproper: clean + rm -rf $(BIN) *.a + diff --git core/base/Makefile core/base/Makefile new file mode 100644 index 0000000..d3e7436 --- /dev/null +++ core/base/Makefile @@ -0,0 +1,37 @@ +SRCS+= \ + file.cpp \ + logging.cpp \ + parsenetaddress.cpp \ + stringprintf.cpp \ + strings.cpp \ + test_utils.cpp \ + errors_unix.cpp + +override CXXFLAGS+= \ + -I./include \ + -I../include \ + -D__GLIBC__ \ + -Wall \ + -Wextra \ + -Werror \ + -std=gnu++14 + +OBJS= $(SRCS:.cpp=.o) + +BIN= libbase.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.cpp + $(CXX) -c $< $(CXXFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/base/errors_unix.cpp core/base/errors_unix.cpp index 296995e..3b983d3 100644 --- core/base/errors_unix.cpp +++ core/base/errors_unix.cpp @@ -17,6 +17,7 @@ #include "android-base/errors.h" #include +#include namespace android { namespace base { diff --git core/base/logging.cpp core/base/logging.cpp index 1741871..0aaae2e 100644 --- core/base/logging.cpp +++ core/base/logging.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include diff --git core/fastboot/Makefile core/fastboot/Makefile new file mode 100644 index 0000000..6d81f7c --- /dev/null +++ core/fastboot/Makefile @@ -0,0 +1,70 @@ +fastboot_version := $(shell git -C . rev-parse --short=12 HEAD 2>/dev/null)-android + +SRCS+= \ + bootimg_utils.cpp \ + engine.cpp \ + fastboot.cpp \ + fs.cpp\ + protocol.cpp \ + socket.cpp \ + tcp.cpp \ + udp.cpp \ + util.cpp \ + usb_linux.cpp \ + util_linux.cpp + + +override CXXFLAGS+= \ + -I../mkbootimg/ \ + -I../base/include \ + -I../libsparse/include \ + -I../include \ + -I../adb \ + -I../../gtest/include \ + -I../../extras/ext4_utils \ + -I../../extras/f2fs_utils \ + -Wall \ + -Wextra \ + -Werror \ + -Wunreachable-code \ + -DFASTBOOT_REVISION='"$(fastboot_version)"' \ + -std=gnu++14 + +LIBS= \ + ../libziparchive/libziparchive.a \ + ../../extras/ext4_utils/libext4_utils.a \ + ../libsparse/libsparse.a \ + ../libutils/libutils.a \ + ../liblog/liblog.a \ + ../adb/libdiagnose_usb.a \ + ../base/libbase.a \ + ../libcutils/libcutils.a \ + ../../gtest/libgtest.a \ + ../../extras/f2fs_utils/libf2fs.a \ + ../libcutils/libcutils.a \ + ../../libselinux/libselinux.a + +override LDFLAGS+= -lz -lpcre -lpthread + +OBJS= $(SRCS:.cpp=.o) + +BIN= fastboot + +all: $(BIN) + +$(BIN): $(OBJS) + $(CXX) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + +%.o: %.cpp + $(CXX) -c $< $(CXXFLAGS) -o $@ + +install: fastboot + install -Dm755 fastboot $(DESTDIR)$(PREFIX)/bin/fastboot + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/include/cutils/atomic.h core/include/cutils/atomic.h index ded972a..2ff6fce 100644 --- core/include/cutils/atomic.h +++ core/include/cutils/atomic.h @@ -19,7 +19,12 @@ #include #include +#ifdef __cplusplus +#include +using namespace std; +#else #include +#endif #ifndef ANDROID_ATOMIC_INLINE #define ANDROID_ATOMIC_INLINE static inline @@ -114,6 +119,7 @@ int32_t android_atomic_or(int32_t value, volatile int32_t* addr) return atomic_fetch_or_explicit(a, value, memory_order_release); } +#ifndef __cplusplus /* * Perform an atomic load with "acquire" or "release" ordering. * @@ -208,6 +214,7 @@ int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue, memory_order_release, memory_order_relaxed)); } +#endif /* * Fence primitives. diff --git core/include/log/log.h core/include/log/log.h index e606a84..963347a 100644 --- core/include/log/log.h +++ core/include/log/log.h @@ -38,6 +38,7 @@ #include #ifdef __cplusplus +#include extern "C" { #endif diff --git core/libcutils/Makefile core/libcutils/Makefile new file mode 100644 index 0000000..ec9c573 --- /dev/null +++ core/libcutils/Makefile @@ -0,0 +1,59 @@ +CSRCS+= \ + config_utils.c \ + fs_config.c \ + canned_fs_config.c \ + hashmap.c \ + iosched_policy.c \ + load_file.c \ + native_handle.c \ + open_memstream.c \ + process_name.c \ + record_stream.c \ + sched_policy.c \ + strlcpy.c \ + threads.c \ + fs.c \ + multiuser.c \ + socket_inaddr_any_server_unix.c \ + socket_local_client_unix.c \ + socket_local_server_unix.c \ + socket_loopback_client_unix.c \ + socket_loopback_server_unix.c \ + socket_network_client_unix.c \ + str_parms.c \ + ashmem-host.c \ + trace-host.c \ + dlmalloc_stubs.c + +CXXSRCS+= \ + sockets_unix.cpp \ + sockets.cpp \ + strdup16to8.c \ + strdup8to16.c + +override CFLAGS+= -I../include + +override CXXFLAGS+= -I../include + +COBJS= $(CSRCS:.c=.o) +CXXOBJS= $(CXXSRCS:.cpp=.o) +BIN= libcutils.a + +all: $(BIN) + +$(BIN): $(COBJS) $(CXXOBJS) + $(AR) rcs $@ $(COBJS) $(CXXOBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +%.o: %.cpp + $(CXX) -c $< $(CXXFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(COBJS) $(CXXOBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/libcutils/fs.c core/libcutils/fs.c index 3f14de7..175df6a 100644 --- core/libcutils/fs.c +++ core/libcutils/fs.c @@ -79,7 +79,7 @@ static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t create: create_result = prepare_as_dir ? TEMP_FAILURE_RETRY(mkdir(path, mode)) - : TEMP_FAILURE_RETRY(open(path, O_CREAT | O_CLOEXEC | O_NOFOLLOW | O_RDONLY)); + : TEMP_FAILURE_RETRY(open(path, O_CREAT | O_CLOEXEC | O_NOFOLLOW | O_RDONLY, mode)); if (create_result == -1) { if (errno != EEXIST) { ALOGE("Failed to %s(%s): %s", diff --git core/liblog/Makefile core/liblog/Makefile new file mode 100644 index 0000000..75a0af3 --- /dev/null +++ core/liblog/Makefile @@ -0,0 +1,39 @@ +SRCS+= \ + log_event_list.c \ + log_event_write.c \ + logger_write.c \ + config_write.c \ + logger_name.c \ + logger_lock.c \ + fake_log_device.c \ + fake_writer.c \ + event_tag_map.c + + +override CFLAGS+= \ + -I../include \ + -DLIBLOG_LOG_TAG=1005 \ + -DSNET_EVENT_LOG_TAG=1397638484 \ + -DFAKE_LOG_DEVICE=1 \ + -Werror \ + -fvisibility=hidden + +OBJS= $(SRCS:.c=.o) + +BIN= liblog.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/libpackagelistparser/Makefile core/libpackagelistparser/Makefile new file mode 100644 index 0000000..38a0158 --- /dev/null +++ core/libpackagelistparser/Makefile @@ -0,0 +1,20 @@ +SRCS+= \ + packagelistparser.c + +override CFLAGS+= -I../include +override CFLAGS+= -I./include + +OBJS= $(SRCS:.c=.o) + +BIN= libpackagelistparser.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +clean: + rm -rf *.o diff --git core/libsparse/Makefile core/libsparse/Makefile new file mode 100644 index 0000000..418c028 --- /dev/null +++ core/libsparse/Makefile @@ -0,0 +1,31 @@ +SRCS+= \ + backed_block.c \ + output_file.c \ + sparse.c \ + sparse_crc32.c \ + sparse_err.c \ + sparse_read.c + +override CFLAGS+= \ + -I./include \ + -Werror + +OBJS= $(SRCS:.c=.o) + +BIN= libsparse.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/libutils/Makefile core/libutils/Makefile new file mode 100644 index 0000000..82a22b9 --- /dev/null +++ core/libutils/Makefile @@ -0,0 +1,50 @@ +SRCS+= \ + CallStack.cpp \ + FileMap.cpp \ + JenkinsHash.cpp \ + LinearTransform.cpp \ + Log.cpp \ + NativeHandle.cpp \ + Printer.cpp \ + PropertyMap.cpp \ + RefBase.cpp \ + SharedBuffer.cpp \ + Static.cpp \ + StopWatch.cpp \ + String8.cpp \ + String16.cpp \ + SystemClock.cpp \ + Threads.cpp \ + Timers.cpp \ + Tokenizer.cpp \ + Unicode.cpp \ + VectorImpl.cpp \ + misc.cpp \ + Looper.cpp \ + ProcessCallStack.cpp + +override CXXFLAGS+= \ + -I../include \ + -I../../safe-iop/include \ + -DLIBUTILS_NATIVE=1 \ + -std=gnu++14 + +OBJS= $(SRCS:.cpp=.o) + +BIN= libutils.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.cpp + $(CXX) -c $< $(CXXFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/libziparchive/Makefile core/libziparchive/Makefile new file mode 100644 index 0000000..4eef274 --- /dev/null +++ core/libziparchive/Makefile @@ -0,0 +1,34 @@ +SRCS+= \ + zip_archive.cc \ + zip_archive_stream_entry.cc \ + zip_writer.cc \ + +override CXXFLAGS+= \ + -I./include \ + -I../include \ + -I../base/include \ + -DZLIB_CONST \ + -Werror \ + -fno-strict-aliasing \ + -std=gnu++14 \ + -Wall + +OBJS= $(SRCS:.cc=.o) + +BIN= libziparchive.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CXX) -c $< $(CXXFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git core/libziparchive/zip_writer.cc core/libziparchive/zip_writer.cc index 1ebed30..5c622d0 100644 --- core/libziparchive/zip_writer.cc +++ core/libziparchive/zip_writer.cc @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git extras/ext4_utils/Makefile extras/ext4_utils/Makefile new file mode 100644 index 0000000..000aaca --- /dev/null +++ extras/ext4_utils/Makefile @@ -0,0 +1,38 @@ +SRCS+= \ + make_ext4fs.c \ + ext4fixup.c \ + ext4_utils.c \ + allocate.c \ + contents.c \ + extent.c \ + indirect.c \ + sha1.c \ + wipe.c \ + crc16.c \ + ext4_sb.c + +override CFLAGS+= \ + -I../../core/libsparse/include \ + -I../../core/include \ + -I../../libselinux/include \ + -fno-strict-aliasing + +OBJS= $(SRCS:.c=.o) + +BIN= libext4_utils.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git extras/f2fs_utils/Makefile extras/f2fs_utils/Makefile new file mode 100644 index 0000000..d81ac9a --- /dev/null +++ extras/f2fs_utils/Makefile @@ -0,0 +1,34 @@ +SRCS+= \ + f2fs_utils.c \ + f2fs_ioutils.c \ + f2fs_dlutils.c + + +override CFLAGS+= \ + -I../../f2fs-tools/include \ + -I../../f2fs-tools/mkfs \ + -I../../core/libsparse/include \ + -I../../libselinux/include \ + -Wno-unused-parameter + +OBJS= $(SRCS:.c=.o) + +BIN= libf2fs.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) + + diff --git extras/f2fs_utils/f2fs_utils.c extras/f2fs_utils/f2fs_utils.c index 6254c08..05ec599 100644 --- extras/f2fs_utils/f2fs_utils.c +++ extras/f2fs_utils/f2fs_utils.c @@ -53,7 +53,7 @@ static void reset_f2fs_info() { config.fd = -1; if (f2fs_sparse_file) { sparse_file_destroy(f2fs_sparse_file); - f2fs_sparse_file = NULL; + f2fs_sparse_file = 0; } } @@ -73,6 +73,6 @@ int make_f2fs_sparse_fd(int fd, long long len, sparse_file_write(f2fs_sparse_file, fd, /*gzip*/0, /*sparse*/1, /*crc*/0); sparse_file_destroy(f2fs_sparse_file); flush_sparse_buffs(); - f2fs_sparse_file = NULL; + f2fs_sparse_file = 0; return 0; } diff --git libselinux/Makefile libselinux/Makefile new file mode 100644 index 0000000..52ef5cc --- /dev/null +++ libselinux/Makefile @@ -0,0 +1,31 @@ +SRCS+= \ + src/callbacks.c \ + src/check_context.c \ + src/freecon.c \ + src/init.c \ + src/label.c \ + src/label_file.c \ + src/label_android_property.c \ + src/label_support.c + +override CFLAGS+= -I./include + +OBJS= $(SRCS:.c=.o) + +BIN= libselinux.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) diff --git gtest/Makefile gtest/Makefile new file mode 100644 index 0000000..49a50aa --- /dev/null +++ gtest/Makefile @@ -0,0 +1,36 @@ +SRCS+= \ + src/gtest-all.cc \ + src/gtest-filepath.cc \ + src/gtest-printers.cc \ + src/gtest-typed-test.cc \ + src/gtest_main.cc \ + src/gtest-death-test.cc \ + src/gtest-port.cc \ + src/gtest-test-part.cc \ + src/gtest.cc + + +override CXXFLAGS+= \ + -I./include \ + -I. + +OBJS= $(SRCS:.cc=.o) + +BIN= libgtest.a + +all: $(BIN) + +$(BIN): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.cc + $(CXX) -c $< $(CXXFLAGS) -o $@ + +.PHONY: clean mrproper + +clean: + rm -rf $(OBJS) + +mrproper: clean + rm -rf $(BIN) +