Skip to content
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 <TSnake@Outlook.fr>
# 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
Copy Markdown
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
Copy Markdown
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
Comment thread
TSnake41 marked this conversation as resolved.
Outdated
}

package() {
source /opt/devkitpro/3dsvars.sh
mkdir -p $pkgdir$PORTLIBS_PREFIX/lib/ $pkgdir$PORTLIBS_PREFIX/include
Comment thread
TSnake41 marked this conversation as resolved.
Outdated
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;
Comment thread
TSnake41 marked this conversation as resolved.
Outdated
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;
Comment thread
TSnake41 marked this conversation as resolved.
Outdated
}

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__ */