Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3ds-libdl. #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 3ds/libdl/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contributor: Teddy Astie <[email protected]>
# Maintainer:

pkgname=3ds-libdl
pkgver=1.0.0
pkgrel=1
pkgdesc='Extensible libdl library for projects that needs it.'
arch=('any')
options=(!strip)
makedepends=('devkitpro-pkgbuild-helpers')
source=('dlfcn.c' 'dlfcn.h')
sha256sums=('9c84be0ef4365a3b2ed3948426ecfbdf8116611d63d5ec42d4af8a551c20ef72' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336')
groups=('3ds-portlibs')

build() {
source /opt/devkitpro/3dsvars.sh

arm-none-eabi-gcc $CFLAGS -c -o dlfcn.o dlfcn.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use $(CC) here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CC} is currently not defined in 3dsvars.sh, however, ${TOOL_PREFIX} is defined to arm-none-eabi- and is actually used to define ${AR}, so to get ${CC}, and can use ${TOOL_PREFIX}gcc.

arm-none-eabi-ar rcu libdl.a dlfcn.o
TSnake41 marked this conversation as resolved.
Show resolved Hide resolved
}

package() {
source /opt/devkitpro/3dsvars.sh
mkdir -p $pkgdir$PORTLIBS_PREFIX/lib/ $pkgdir$PORTLIBS_PREFIX/include
TSnake41 marked this conversation as resolved.
Show resolved Hide resolved
cp libdl.a $pkgdir$PORTLIBS_PREFIX/lib/
cp dlfcn.h $pkgdir$PORTLIBS_PREFIX/include/
}
36 changes: 36 additions & 0 deletions 3ds/libdl/dlfcn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "dlfcn.h"

#include <stddef.h>

static dl_open open = NULL;
TSnake41 marked this conversation as resolved.
Show resolved Hide resolved
static dl_error error = NULL;
static dl_sym sym = NULL;
static dl_close close = NULL;

void dl_setfn(dl_open new_open, dl_error new_error, dl_sym new_sym, dl_close new_close)
{
open = new_open;
error = new_error;
sym = new_sym;
close = new_close;
}

void *dlopen(const char *module, int flag)
{
return open ? (*open)(module, flag) : NULL;
TSnake41 marked this conversation as resolved.
Show resolved Hide resolved
}

char *dlerror(void)
{
return error ? (*error)() : "";
}

void *dlsym(void *handle, const char *name)
{
return sym ? (*sym)(handle, name) : NULL;
}

int dlclose(void *handle)
{
return close ? (*close)(handle) : 0;
}
25 changes: 25 additions & 0 deletions 3ds/libdl/dlfcn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __DLFCN_H__
#define __DLFCN_H__

#define RTLD_LAZY 0
#define RTLD_NOW 1
#define RTLD_GLOBAL 2
#define RTLD_LOCAL 3

/* Defines a dlfcn.h compatible API. */
void *dlopen(const char *module, int flag);
char *dlerror(void);
void *dlsym(void *handle, const char *name);
int dlclose(void *handle);

/* Add a custom API to change builtin functions with user-provided ones.
* This is useful to expand dlfcn to something working when needed (e.g LuaJIT FFI).
*/
typedef void *(*dl_open)(const char *, int);
typedef char *(*dl_error)(void);
typedef void *(*dl_sym)(void *, const char *);
typedef int (*dl_close)(void *);

void dl_setfn(dl_open open, dl_error error, dl_sym sym, dl_close close);

#endif /* __DLFCN_H__ */