Skip to content

Commit

Permalink
Add compilation methods in the NDK environment
Browse files Browse the repository at this point in the history
  • Loading branch information
leok committed Jun 29, 2018
1 parent 0aad65c commit 169e446
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 15 deletions.
78 changes: 78 additions & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := plist
LOCAL_SRC_FILES := ../libplist.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := usb1.0
LOCAL_SRC_FILES := ../libusb1.0.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := imobiledevice
LOCAL_SRC_FILES := ../libimobiledevice.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := usbmuxd_new
LOCAL_SRC_FILES := ../libusbmuxd_new.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := decrepit
LOCAL_SRC_FILES := ../libdecrepit.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := ../libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := ../libssl.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
USBMUXD_SRC := \
client.c \
conf.c \
device.c \
log.c \
main.c \
preflight.c \
usb.c \
utils.c


LOCAL_MODULE := usbmuxd

LOCAL_SRC_FILES := $(addprefix ../../src/, $(USBMUXD_SRC))

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../src/ \
$(LOCAL_PATH)/../../../libusb/libusb/os/ \
$(LOCAL_PATH)/../../../libusb/libusb/ \
$(LOCAL_PATH)/../../../libimobiledevice/src/ \
$(LOCAL_PATH)/../../../libimobiledevice/include/ \
$(LOCAL_PATH)/../../../libimobiledevice/include/libimobiledevice \
$(LOCAL_PATH)/../../../libimobiledevice/ \
$(LOCAL_PATH)/../../../libusbmuxd/include \
$(LOCAL_PATH)/../../../libusbmuxd/ \
$(LOCAL_PATH)/../../../libplist/libcnary/ \
$(LOCAL_PATH)/../../../libplist/libcnary/include \
$(LOCAL_PATH)/../../../libplist/include \
$(LOCAL_PATH)/../../../libimobiledevice/common \
$(LOCAL_PATH)/../../../boringssl/include

LOCAL_STATIC_LIBRARIES += libplist libimobiledevice libusbmuxd_new libusb1.0 libssl libcrypto libdecrepit
#LOCAL_SHARED_LIBRARIES += libssl libcrypto libdecrepit
LOCAL_CFLAGS += -pie -fPIE -DHAVE_CLOCK_GETTIME -DHAVE_LIBIMOBILEDEVICE -DHAVE_STPCPY -DHAVE_SYS_TYPES_H
LOCAL_LDFLAGS += -pie -fPIE -llog

#PRODUCI_COPY_FILES +=/home/wuli/work/ndk_develop/usbmuxd/android/jni/1:/home/wuli/work/ndk_develop/usbmuxd/android/jni/2

include $(BUILD_EXECUTABLE)
76 changes: 76 additions & 0 deletions android/jni/Android.mk.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := plist
LOCAL_SRC_FILES := ../libplist.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := usb1.0
LOCAL_SRC_FILES := ../libusb1.0.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := imobiledevice
LOCAL_SRC_FILES := ../libimobiledevice.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := usbmuxd_new
LOCAL_SRC_FILES := ../libusbmuxd_new.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := decrepit
LOCAL_SRC_FILES := ../libdecrepit.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := ../libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := ../libssl.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
USBMUXD_SRC := \
client.c \
conf.c \
device.c \
log.c \
main.c \
preflight.c \
usb.c \
utils.c


LOCAL_MODULE := usbmuxd

LOCAL_SRC_FILES := $(addprefix ../../src/, $(USBMUXD_SRC))

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../src/ \
$(LOCAL_PATH)/../../../libusb/libusb/os/ \
$(LOCAL_PATH)/../../../libusb/libusb/ \
$(LOCAL_PATH)/../../../libimobiledevice/src/ \
$(LOCAL_PATH)/../../../libimobiledevice/include/ \
$(LOCAL_PATH)/../../../libimobiledevice/include/libimobiledevice \
$(LOCAL_PATH)/../../../libimobiledevice/ \
$(LOCAL_PATH)/../../../libusbmuxd/include \
$(LOCAL_PATH)/../../../libusbmuxd/ \
$(LOCAL_PATH)/../../../libplist/libcnary/ \
$(LOCAL_PATH)/../../../libplist/libcnary/include \
$(LOCAL_PATH)/../../../libplist/include \
$(LOCAL_PATH)/../../../libimobiledevice/common \
$(LOCAL_PATH)/../../../boringssl/include

LOCAL_STATIC_LIBRARIES += libplist libimobiledevice libusbmuxd_new libusb1.0 libssl libcrypto libdecrepit
#LOCAL_SHARED_LIBRARIES += libssl libcrypto libdecrepit
LOCAL_CFLAGS += -pie -fPIE -DHAVE_CLOCK_GETTIME -DHAVE_LIBIMOBILEDEVICE -DHAVE_STPCPY -DHAVE_SYS_TYPES_H -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -O3 -fno-exceptions -fno-rtti
LOCAL_LDFLAGS += -pie -fPIE -llog -Wl,--gc-sections

include $(BUILD_EXECUTABLE)
1 change: 1 addition & 0 deletions android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ABI := armeabi-v7a
8 changes: 6 additions & 2 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ const char *config_get_config_dir()
#ifdef __APPLE__
base_config_dir = strdup("/var/db");
#else
base_config_dir = strdup("/var/lib");
//base_config_dir = strdup("/var/lib"); //leok
base_config_dir = strdup("/data/data/com.rockchip.inno.multiprojectionsystem/files/lib");
#endif
#endif
__config_dir = string_concat(base_config_dir, DIR_SEP_S, CONFIG_DIR, NULL);
Expand Down Expand Up @@ -253,8 +254,11 @@ static int internal_set_value(const char *config_file, const char *key, plist_t
} else {
usbmuxd_log(LL_DEBUG, "setting key %s in config_file %s", key, config_file);
}

#ifndef FUNC_RENAME //leok
int res = plist_write_to_filename(config, config_file, PLIST_FORMAT_XML);
#else
int res = plist_write_to_filename_new(config, config_file, PLIST_FORMAT_XML);
#endif

plist_free(config);

Expand Down
3 changes: 2 additions & 1 deletion src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "log.h"
#include "utils.h"

unsigned int log_level = LL_WARNING;
//unsigned int log_level = LL_WARNING;
unsigned int log_level = LL_FLOOD;

int log_syslog = 0;

Expand Down
1 change: 1 addition & 0 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef LOG_H
#define LOG_H


enum loglevel {
LL_FATAL = 0,
LL_ERROR,
Expand Down
14 changes: 11 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#define PACKAGE_NAME "usbmuxd"
#define PACKAGE_STRING "usbmuxd 1.1.1"
#define PACKAGE_VERSION "1.1.1"


#define _BSD_SOURCE
#define _GNU_SOURCE

Expand Down Expand Up @@ -49,8 +54,10 @@
#include "client.h"
#include "conf.h"

static const char *socket_path = "/var/run/usbmuxd";
static const char *lockfile = "/var/run/usbmuxd.pid";
//static const char *socket_path = "/var/run/usbmuxd";
//static const char *lockfile = "/var/run/usbmuxd.pid";
static const char *socket_path = "/data/data/com.rockchip.inno.multiprojectionsystem/files/run/usbmuxd"; //leok
static const char *lockfile = "/data/data/com.rockchip.inno.multiprojectionsystem/files/run/usbmuxd.pid";

int should_exit;
int should_discover;
Expand Down Expand Up @@ -483,7 +490,8 @@ int main(int argc, char *argv[])
verbose += LL_WARNING;
log_enable_syslog();
} else {
verbose += LL_NOTICE;
//verbose += LL_NOTICE;
verbose += LL_FLOOD;
}

/* set log level to specified verbosity */
Expand Down
4 changes: 3 additions & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* usb.c
*
* Copyright (C) 2009 Hector Martin <hector@marcansoft.com>
Expand Down Expand Up @@ -36,6 +36,7 @@
#include "device.h"
#include "utils.h"

#define HAVE_LIBUSB_HOTPLUG_API 1
#if (defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000102)) || (defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01000102))
#define HAVE_LIBUSB_HOTPLUG_API 1
#endif
Expand Down Expand Up @@ -395,6 +396,7 @@ static int usb_device_add(libusb_device* dev)
usbmuxd_log(LL_NOTICE, "Could not get old configuration descriptor for device %d-%d: %d", bus, address, res);
} else {
for(j=0; j<config->bNumInterfaces; j++) {
usbmuxd_log(LL_INFO, "------------------------------------------------------------");
const struct libusb_interface_descriptor *intf = &config->interface[j].altsetting[0];
if((res = libusb_kernel_driver_active(handle, intf->bInterfaceNumber)) < 0) {
usbmuxd_log(LL_NOTICE, "Could not check kernel ownership of interface %d for device %d-%d: %d", intf->bInterfaceNumber, bus, address, res);
Expand Down
2 changes: 1 addition & 1 deletion src/usbmuxd-proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#if defined(WIN32) || defined(__CYGWIN__)
#define USBMUXD_SOCKET_PORT 27015
#else
#define USBMUXD_SOCKET_FILE "/var/run/usbmuxd"
#define USBMUXD_SOCKET_FILE "/data/data/com.rockchip.inno.multiprojectionsystem/files/run/usbmuxd" //leok
#endif

#ifdef __cplusplus
Expand Down
40 changes: 39 additions & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ void collection_copy(struct collection *dest, struct collection *src)
memcpy(dest->list, src->list, sizeof(void*) * src->capacity);
}


#if 0

#ifndef HAVE_STPCPY
/**
* Copy characters from one string into another
Expand All @@ -149,7 +152,11 @@ void collection_copy(struct collection *dest, struct collection *src)
* @return a pointer to the terminating `\0' character of @s1,
* or NULL if @s1 or @s2 is NULL.
*/
#ifndef FUNC_RENAME //leok
char *stpcpy(char * s1, const char * s2)
#else
char *stpcpy_new(char * s1, const char * s2)
#endif
{
if (s1 == NULL || s2 == NULL)
return NULL;
Expand All @@ -171,7 +178,11 @@ char *stpcpy(char * s1, const char * s2)
* @return a newly allocated string, or NULL if @str is NULL. This will also
* return NULL and set errno to ENOMEM if memory is exhausted.
*/
#ifndef FUNC_RENAME //leok
char *string_concat(const char *str, ...)
#else
char *string_concat_new(const char *str, ...)
#endif
{
size_t len;
va_list args;
Expand Down Expand Up @@ -201,21 +212,33 @@ char *string_concat(const char *str, ...)
return NULL; /* errno remains set */

dest = result;


#ifndef FUNC_RENAME //leok
dest = stpcpy(dest, str);
#else
dest = stpcpy_new(dest, str);
#endif

va_start(args, str);
s = va_arg(args, char *);
while (s) {
#ifndef FUNC_RENAME //leok
dest = stpcpy(dest, s);
#else
dest = stpcpy_new(dest, s);
#endif
s = va_arg(args, char *);
}
va_end(args);

return result;
}

#ifndef FUNC_RENAME //leok
int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length)
#else
int buffer_read_from_filename_new(const char *filename, char **buffer, uint64_t *length)
#endif
{
FILE *f;
uint64_t size;
Expand Down Expand Up @@ -255,7 +278,11 @@ int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *len
return ret;
}

#ifndef FUNC_RENAME //leok
int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length)
#else
int buffer_write_to_filename_new(const char *filename, const char *buffer, uint64_t length)
#endif
{
FILE *f;

Expand All @@ -279,7 +306,11 @@ int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t
}
}

#ifndef FUNC_RENAME //leok
int plist_read_from_filename(plist_t *plist, const char *filename)
#else
int plist_read_from_filename_new(plist_t *plist, const char *filename)
#endif
{
char *buffer = NULL;
uint64_t length;
Expand All @@ -302,7 +333,11 @@ int plist_read_from_filename(plist_t *plist, const char *filename)
return 1;
}

#ifndef FUNC_RENAME //leok
int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format)
#else
int plist_write_to_filename_new(plist_t plist, const char *filename, enum plist_format_t format)
#endif
{
char *buffer = NULL;
uint32_t length;
Expand All @@ -324,6 +359,9 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form
return res;
}

#endif


#ifndef HAVE_CLOCK_GETTIME
typedef int clockid_t;
#define CLOCK_MONOTONIC 1
Expand Down
Loading

0 comments on commit 169e446

Please sign in to comment.