Skip to content

Commit

Permalink
Add exports for BSD/Linux/Mac/Win32/Win64.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Mar 30, 2024
1 parent 3d863a9 commit 9cc0ca9
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 7 deletions.
16 changes: 16 additions & 0 deletions citrine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "citrine.h"

#ifdef EMBED
#include "misc/opt/embed.h"
#endif

int ctr_argc;
char** ctr_argv;

Expand Down Expand Up @@ -28,6 +32,16 @@ void ctr_cli_welcome() {
printf("\n");
}

void* ctr_data_blob(unsigned int* len) {
#ifdef EMBED
*len = CtrBlob_len;
return CtrBlob;
#else
*len = 0;
return NULL;
#endif
}

/**
* CommandLine Read Arguments
* Parses command line arguments and sets global settings accordingly.
Expand Down Expand Up @@ -112,6 +126,7 @@ int ctr_init() {
* Bootstraps the Citrine Application.
*
*/
#ifndef EMBED
int main(int argc, char* argv[]) {
char* prg;
char ctr_pool_share;
Expand Down Expand Up @@ -168,3 +183,4 @@ int main(int argc, char* argv[]) {
exit(0);
return 0;
}
#endif
1 change: 1 addition & 0 deletions citrine.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,4 @@ int ctr_init();

/* for exports */
void init_embedded_media_plugin();
void* ctr_data_blob(unsigned int* blob_len);
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ctr: $(OBJS)
cp ctr bin/${OS}/ctr${ISO}

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
2 changes: 1 addition & 1 deletion makefile.bsd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ctr: $(OBJS)
cp ctr bin/${OS}/ctr${ISO}

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
2 changes: 1 addition & 1 deletion makefile.haiku
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ctr: $(OBJS)
cp ctr bin/${OS}/ctr${ISO}

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
2 changes: 1 addition & 1 deletion makefile.mac
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ctr: $(OBJS)
cp ctr bin/${OS}/ctr${ISO}

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
2 changes: 1 addition & 1 deletion makefile.win32
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ctr: $(OBJS)
$(CC) ctr${ISO}exports.o $(OBJS) -g -lm -o bin/Win32/ctr${ISO}.exe

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
2 changes: 1 addition & 1 deletion makefile.win64
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ctr: $(OBJS)
$(CC) ctr${ISO}exports.o $(OBJS) -g -lm $(LFLAGS) $(EXTRA) -o bin/Win64/ctr${ISO}.exe

.c.o:
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
$(CC) $(CFLAGS) $(EXTRACFLAGS) -I i18n/${ISO} -c $<

clean:
rm -rf ${OBJS} ctr
Expand Down
24 changes: 24 additions & 0 deletions misc/export/pc/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#/bin/bash

# usage (from rootdir):
# Linux:
# MEDIALIB="libctrmedia.so" MAKEFILE="makefile" ISO="nl" bash misc/export/pc/export.sh
# Win64:
# MEDIALIB="libctrmedia.dll" MAKEFILE="makefile.win64" ISO="nl" CC=x86_64-w64-mingw32-gcc-win32 DLLTOOL=x86_64-w64-mingw32-dlltool bash misc/export/pc/export.sh
# don't forget to copy libs!

# create embed file
cat misc/opt/preface.h > misc/opt/embed.h
xxd -i -n CtrBlob data >> misc/opt/embed.h

# compile media plugin
PACKAGE="media" \
NAME=$MEDIALIB \
make -f $MAKEFILE clean

PACKAGE="media" NAME=$MEDIALIB \
make -f $MAKEFILE plugin

# compile Citrine with embed options
EXTRACFLAGS=" -D EMBED " \
make -f $MAKEFILE
9 changes: 8 additions & 1 deletion plugins/media/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,14 @@ SDL_RWops* ctr_internal_media_load_asset(char* asset_name, char asset_type) {
SDL_RWops* asset_file = SDL_RWFromFile(path, "rb");
ctr_heap_free(path);
if (!asset_file) {
return NULL;
unsigned int blob_len;
void* blob;
//No asset file? then maybe embedded data blob?
blob = ctr_data_blob(&blob_len);
if (blob == NULL) {
return NULL;
}
asset_file = SDL_RWFromMem(blob, blob_len);
}
SDL_RWseek(asset_file, 0, RW_SEEK_SET);
char* buffer = malloc(500);
Expand Down

0 comments on commit 9cc0ca9

Please sign in to comment.