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

Make lite working on FreeBSD #127

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash
#!/usr/bin/env bash

cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc"
lflags="-lSDL2 -lm"
lflags="-lm"

if [[ $* == *windows* ]]; then
platform="windows"
outfile="lite.exe"
compiler="x86_64-w64-mingw32-gcc"
cflags="$cflags -DLUA_USE_POPEN -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include"
lflags="$lflags -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib"
lflags="$lflags -lSDL2 -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib"
lflags="-lmingw32 -lSDL2main $lflags -mwindows -o $outfile res.res"
x86_64-w64-mingw32-windres res.rc -O coff -o res.res
else
platform="unix"
outfile="lite"
compiler="gcc"
compiler="cc"
cflags="$cflags -DLUA_USE_POSIX"
lflags="$lflags -o $outfile"
if command -v pkgconf >/dev/null; then
cflags="$cflags $(pkgconf --cflags --silence-errors sdl2)"
lflags="$lflags $(pkgconf --libs --silence-errors sdl2)"
else
lflags="$lflags -lSDL2"
fi
fi

if command -v ccache >/dev/null; then
Expand Down
19 changes: 19 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <unistd.h>
#elif __APPLE__
#include <mach-o/dyld.h>
#elif __FreeBSD__
#include <sys/sysctl.h>
#include <unistd.h>
#endif


Expand Down Expand Up @@ -38,6 +41,17 @@ static void get_exe_filename(char *buf, int sz) {
#elif __APPLE__
unsigned size = sz;
_NSGetExecutablePath(buf, &size);
#elif __FreeBSD__
int items[] = {
CTL_KERN,
KERN_PROC,
KERN_PROC_PATHNAME,
getpid()
};

size_t len;
(void) sysctl(items, 4, buf, &len, NULL, 0);
buf[len] = '\0';
#else
strcpy(buf, "./lite");
#endif
Expand Down Expand Up @@ -111,7 +125,12 @@ int main(int argc, char **argv) {
lua_pushnumber(L, get_scale());
lua_setglobal(L, "SCALE");

#ifdef __FreeBSD__
char exename[PATH_MAX];
#else
char exename[2048];
#endif

get_exe_filename(exename, sizeof(exename));
lua_pushstring(L, exename);
lua_setglobal(L, "EXEFILE");
Expand Down