Skip to content

Commit

Permalink
support esp32 build, move libmacor into libposix
Browse files Browse the repository at this point in the history
  • Loading branch information
gozfree committed Oct 17, 2020
1 parent ca05b76 commit 517fda3
Show file tree
Hide file tree
Showing 90 changed files with 582 additions and 2,447 deletions.
6 changes: 6 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### esp32
* toolchain: xtensa-esp32-elf
copy or softlink gear-lib to esp32 components dir
gear-lib/component.mk is makefile of esp32
`$ make`

### Windows
* Windows7 install "Microsoft Visual Studio 10.0"
open cmd.exe
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ esac
PLATFORM="[linux|pi|android|ios]"

#basic libraries
BASIC_LIBS="libposix libmacro libtime liblog libdarray libgevent libworkq libdict libhash libsort \
BASIC_LIBS="libposix libtime liblog libdarray libgevent libworkq libdict libhash libsort \
librbtree libringbuffer libthread libvector libbase64 libmedia-io \
libdebug libfile libconfig libuac libuvc libqueue libplugin libhal libsubmask"
FRAMEWORK_LIBS="libipc"
Expand Down
8 changes: 8 additions & 0 deletions gear-lib/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
COMPONENT_ADD_INCLUDEDIRS = . ./libposix ./libmacro ./libthread ./libdarray ./libmedia-io ./libqueue
COMPONENT_SRCDIRS = libposix libmacro libdarray libqueue libthread libmedia-io librtmpc liblog
COMPONENT_OBJEXCLUDE = libposix/test_libposix.o libmacro/test_libmacor.o libdarray/test_libdarray.o libqueue/test_libqueue.o libthread/test_libthread.o libmedia-io/test_libmedia-io.o librtmpc/test_librtmpc.o liblog/test_liblog.o
COMPONENT_DEPENDS := newlib
CFLAGS += -DFREERTOS #for libposix
CFLAGS += -DESP32 #for libposix4rtos
CFLAGS += -DNO_CRYPTO #for librtmpc
CFLAGS += -Wno-format-truncation
12 changes: 6 additions & 6 deletions gear-lib/libfile/libfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ struct file_desc {
char *name;
};

typedef struct file {
struct file_desc *fd;
const struct file_ops *ops;
uint64_t size;
} file;

typedef struct file_info {
uint64_t modify_sec;
uint64_t access_sec;
Expand All @@ -78,6 +72,12 @@ typedef struct file_info {
uint64_t size;
} file_info;

typedef struct file {
struct file_desc *fd;
const struct file_ops *ops;
struct file_info info;
} file;

typedef struct file_systat {
uint64_t size_total;
uint64_t size_avail;
Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libhash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ else
OUTLIBPATH :=$(OUTPUT)/$(LTYPE)
endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include
CFLAGS += -I$(OUTPUT)/include/gear-lib

SHARED := -shared

Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libhash/libhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
******************************************************************************/
#include "libhash.h"
#include <gear-lib/libmacro.h>
#include <libposix.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libipc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ifneq ($(driver), y)
EXTRA_CFLAGS += -fPIC
endif
EXTRA_CFLAGS += $($(ARCH)_CFLAGS)
EXTRA_CFLAGS += -I$(OUTPUT)/include
EXTRA_CFLAGS += -I$(OUTPUT)/include/gear-lib
EXTRA_CFLAGS += -I../libmacro/

SHARED := -shared
Expand Down
4 changes: 2 additions & 2 deletions gear-lib/libipc/libipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
******************************************************************************/
#include "libipc.h"
#include <libmacro.h>
#include <libposix.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -301,7 +301,7 @@ static int on_return(struct ipc *ipc, void *buf, size_t len)

struct ipc *ipc_create(enum ipc_role role, uint16_t port)
{
struct ipc *ipc = CALLOC(1, struct ipc);
struct ipc *ipc = calloc(1, sizeof(struct ipc));
if (!ipc) {
printf("malloc failed!\n");
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions gear-lib/libipc/libipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#ifndef LIBIPC_H
#define LIBIPC_H

#include <gear-lib/libdict.h>
#include <gear-lib/libgevent.h>
#include <libdict.h>
#include <libgevent.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down
3 changes: 1 addition & 2 deletions gear-lib/libipc/msgq_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
******************************************************************************/
#include "libipc.h"
#include <libmacro.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
Expand Down Expand Up @@ -201,7 +200,7 @@ static void on_connect(union sigval sv)
static void *_mq_init(struct ipc *ipc, uint16_t port, enum ipc_role role)
{
struct mq_attr attr;
struct mq_posix_ctx *ctx = CALLOC(1, struct mq_posix_ctx);
struct mq_posix_ctx *ctx = calloc(1, sizeof(struct mq_posix_ctx));
if (!ctx) {
printf("malloc failed!\n");
return NULL;
Expand Down
5 changes: 2 additions & 3 deletions gear-lib/libipc/msgq_sysv.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
******************************************************************************/
#include "libipc.h"
#include <libmacro.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -180,7 +179,7 @@ static void *client_thread(void *arg)

static void *_mq_init_client(struct ipc *ipc)
{
struct mq_sysv_ctx *ctx = CALLOC(1, struct mq_sysv_ctx);
struct mq_sysv_ctx *ctx = calloc(1, sizeof(struct mq_sysv_ctx));
if (!ctx) {
printf("malloc failed!\n");
return NULL;
Expand Down Expand Up @@ -235,7 +234,7 @@ static void _mq_deinit_client(struct mq_sysv_ctx *ctx)

static void *_mq_init_server(struct ipc *ipc)
{
struct mq_sysv_ctx *ctx = CALLOC(1, struct mq_sysv_ctx);
struct mq_sysv_ctx *ctx = calloc(1, sizeof(struct mq_sysv_ctx));
if (!ctx) {
printf("malloc failed!\n");
return NULL;
Expand Down
7 changes: 3 additions & 4 deletions gear-lib/libipc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
#include <sys/time.h>
#include <linux/netlink.h>
#include <semaphore.h>
#include <gear-lib/libmacro.h>
#include <gear-lib/libgevent.h>
#include <gear-lib/libthread.h>
#include <libgevent.h>
#include <libthread.h>
#include "libipc.h"
#include "netlink_driver.h"

Expand Down Expand Up @@ -112,7 +111,7 @@ static void *nl_init(struct ipc *ipc, uint16_t port, enum ipc_role role)
}
return NULL;
}
struct nl_ctx *ctx = CALLOC(1, struct nl_ctx);
struct nl_ctx *ctx = calloc(1, sizeof(struct nl_ctx));
if (!ctx) {
printf("malloc failed!\n");
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions gear-lib/libipc/unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
******************************************************************************/
#include "libipc.h"
#include <libmacro.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -107,7 +106,7 @@ static void *event_thread(void *arg)
static void *sk_init(struct ipc *ipc, uint16_t port, enum ipc_role role)
{
char stub_name[64];
struct sk_ctx *c = CALLOC(1, struct sk_ctx);
struct sk_ctx *c = calloc(1, sizeof(struct sk_ctx));
if (!c) {
printf("malloc failed!\n");
goto failed;
Expand Down
23 changes: 8 additions & 15 deletions gear-lib/liblog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,24 @@ OBJS_UNIT_TEST = test_$(LIBNAME).o
# cflags and ldflags
###############################################################################
ifeq ($(MODE), release)
CFLAGS := -O2 -Wall -Werror -Wno-format-truncation
CFLAGS := -O2 -Wall -Werror -fPIC -Wno-format-truncation
LTYPE := release
else
CFLAGS := -g -Wall -Wno-format-truncation
CFLAGS := -g -Wall -Werror -fPIC -Wno-format-truncation
LTYPE := debug
endif
ifeq ($(OUTPUT),/usr/local)
OUTLIBPATH := /usr/local
OUTLIBPATH :=/usr/local
else
OUTLIBPATH := $(OUTPUT)/$(LTYPE)
endif
ifeq ($(ARCH), win)
else
CFLAGS += -fPIC
OUTLIBPATH :=$(OUTPUT)/$(LTYPE)
endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(INC_DIR)
CFLAGS += -I$(OUTPUT)/include
SHARED := -shared -fPIC
CFLAGS += -I$(OUTPUT)/include/gear-lib

SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
ifeq ($(ARCH), win)
LDFLAGS += -L$(LIB_DIR)
endif
LDFLAGS += -lpthread
LDFLAGS += -pthread

###############################################################################
# target
Expand Down
24 changes: 17 additions & 7 deletions gear-lib/liblog/liblog.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include <libposix.h>
#include "liblog.h"
#include "color.h"

Expand All @@ -31,7 +32,7 @@
#include <time.h>
#include <fcntl.h>

#if defined (__linux__) || defined (__CYGWIN__)
#if defined (OS_LINUX)
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <pthread.h>
Expand All @@ -48,9 +49,9 @@

#define USE_SYSLOG

#elif defined (__WIN32__) || defined (WIN32) || defined (_MSC_VER)
#elif defined (OS_WINDOWS)
#include "libposix4win.h"
#elif defined (__ANDROID__)
#elif defined (OS_ANDROID)
#include <jni.h>
#include <android/log.h>
#endif
Expand Down Expand Up @@ -205,7 +206,11 @@ static unsigned long long get_file_size_by_fp(FILE *fp)
return size;
}

#if defined (__WIN32__) || defined (WIN32) || defined (_MSC_VER)
#if defined (OS_WINDOWS) || defined (OS_RTOS)
static int get_proc_name(char *name, size_t len)
{
return 0;
}

#else
static int get_proc_name(char *name, size_t len)
Expand Down Expand Up @@ -238,8 +243,13 @@ static int get_proc_name(char *name, size_t len)
}
#endif

#if defined (__APPLE__)
#elif defined (__linux__) || defined (__CYGWIN__)
#if defined (OS_APPLE) || defined (OS_RTOS)
static pid_t gettid(void)
{
return 0;
}

#elif defined (OS_LINUX)
static pid_t gettid(void)
{
#ifndef __CYGWIN__
Expand All @@ -253,7 +263,7 @@ static pid_t gettid(void)
static void log_get_time(char *str, int len, int flag_name)
{
char date_fmt[20];
char date_ms[4];
char date_ms[32];
struct timeval tv;
struct tm now_tm;
int now_ms;
Expand Down
18 changes: 0 additions & 18 deletions gear-lib/libmacro/Android.mk

This file was deleted.

Loading

0 comments on commit 517fda3

Please sign in to comment.