Skip to content

Commit

Permalink
made linking with libc the default, as it's the most commonly used mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsiomb committed Jul 10, 2024
1 parent 39655f8 commit 7a10002
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ ifeq ($(sys), mingw)
alib = libminiglut-w32.a
bin = test.exe

# on windows/mingw we can build without linking to libc
CFLAGS += -DMINIGLUT_NO_LIBC
LDFLAGS = -mconsole -lopengl32 -lgdi32 -lwinmm
else
ifeq ($(sys)-$(isx86), Linux-x86)
CFLAGS += -I/usr/X11R6/include
# for Linux x86/x86-64 we can build without linking to libc
CFLAGS += -I/usr/X11R6/include -DMINIGLUT_NO_LIBC
LDFLAGS = -L/usr/X11R6/lib -lX11 -lGL
else
# for other UNIX or non-x86 where sys_ and trig functions are not
# implemented, just use libc
CFLAGS += -DMINIGLUT_USE_LIBC
LDFLAGS = -lX11 -lGL -lm
ifeq ($(sys), IRIX)
CC = gcc
Expand Down
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ A second reason to use MiniGLUT is to ease porting of UNIX OpenGL programs to
Windows, especially when using the microsoft compiler, where setting up and
linking with a proper 3rd-party library is an ordeal in itself. Even more so if
you decide to statically link, at which point you need to deal with the whole
"MSVC runtime" chaos. Even if you decide to link MiniGLUT as a static library,
instead of dropping it in your code, it still won't present any MSVC runtime
compatibility issues, since it doesn't call any C library functions whatsoever.
"MSVC runtime" chaos.

On GNU/Linux x86/x86-64 and 32bit Windows, MiniGLUT can be compiled to never
call any C library functions whatsoever (which is the default if you use the
included makefile/msvc project to build a static library). This is useful to
avoid dependencies on any specific libc or msvc runtime.

Download
--------
Expand All @@ -50,15 +53,27 @@ When building with MSVC, linking with the correct libraries is taken care by
pragmas in the header file. If you wish to avoid the winmm dependency, define
`MINIGLUT_NO_WINMM`.

To disable calling any C library functions, make sure to have `MINIGLUT_NO_LIBC`
defined when building `miniglut.c`. Either add that to your build system, or
just modify `miniglut.c` and define it at the top.

> Note: in previous versions (including v0.5), building without libc was the
> default, and you had to define `MINIGLUT_USE_LIBC` to make it use libc. But
> it turns out usually when you're building miniglut as part of your project,
> there's no real downside to using libc in most use cases, so I decided to
> change the default, and have the extra define go to the static library build
> files instead of *every* project which drops `miniglut.h`/`miniglut.c` in the
> source tree.
To avoid calling C library functions, MiniGLUT uses inline assembly code for
system calls and trigonometric operations. This makes the default build
incompatible with non-x86 systems, and with MSVC x64 builds. If you don't mind
linking with the C library, you can define `MINIGLUT_USE_LIBC` to lift these
limitations.
system calls and trigonometric operations. This is currently implemented only
on x86 (32 and 64bit), and only on 32bit when building with MSVC (which doesn't
support inline assembly on x86-64). For all other systems you need to link with
libc.

License
-------
Copyright (C) 2020-2022 John Tsiombikas <[email protected]>
Copyright (C) 2020-2024 John Tsiombikas <[email protected]>

MiniGLUT is free software. Feel free to use, modify and/or redistribute it,
under the terms of the GNU General Public License v3, or at your option any
Expand All @@ -74,6 +89,19 @@ To learn more about GPL-incompatible free software licenses where this might
be an issue, see:
https://www.gnu.org/licenses/license-list.en.html#GPLIncompatibleLicenses

Implementation Notes
--------------------
On UNIX systems, spaceball callbacks are supported by talking to a 6dof device
driver through the *Magellan X11 ClientMessage protocol*. This works with
either the free software *spacenavd* driver, or the proprietary *3dxsrv*.
Spacenavd supports all 6dof devices from the first serial ones to current
models.

On Windows, spaceball support relies on the 3Dconnexion driver and its old
siapp API. This should work on any version of the driver from very old ones
running on windows 9x and supporting serial devices, to the latest current
driver for USB and bluetooth spacemice.

Known Issues
------------
MiniGLUT being a subset of GLUT, is missing a number of features. Some of them
Expand Down
16 changes: 8 additions & 8 deletions miniglut.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MiniGLUT - minimal GLUT subset without dependencies
Copyright (C) 2020-2022 John Tsiombikas <[email protected]>
Copyright (C) 2020-2024 John Tsiombikas <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -2109,7 +2109,7 @@ static int handle_6dof(MSG* msg)
#if defined(unix) || defined(__unix__) || defined(__APPLE__)
#include <sys/time.h>

#ifdef MINIGLUT_USE_LIBC
#ifndef MINIGLUT_NO_LIBC
#define sys_gettimeofday(tv, tz) gettimeofday(tv, tz)
#else
static int sys_gettimeofday(struct timeval *tv, struct timezone *tz);
Expand Down Expand Up @@ -2156,7 +2156,7 @@ static void panic(const char *msg)
}


#ifdef MINIGLUT_USE_LIBC
#ifndef MINIGLUT_NO_LIBC
#include <stdlib.h>
#ifdef _WIN32
#include <io.h>
Expand All @@ -2174,7 +2174,7 @@ static int sys_write(int fd, const void *buf, int count)
return write(fd, buf, count);
}

#else /* !MINIGLUT_USE_LIBC */
#else /* MINIGLUT_NO_LIBC */

#ifdef __linux__
#ifdef __x86_64__
Expand Down Expand Up @@ -2247,11 +2247,11 @@ static int sys_write(int fd, const void *buf, int count)
return wrsz;
}
#endif /* _WIN32 */
#endif /* !MINIGLUT_USE_LIBC */
#endif /* MINIGLUT_NO_LIBC */


/* ----------------- primitives ------------------ */
#ifdef MINIGLUT_USE_LIBC
#ifndef MINIGLUT_NO_LIBC
#include <stdlib.h>
#include <math.h>

Expand All @@ -2266,7 +2266,7 @@ float mglut_atan(float x)
return atan(x);
}

#else /* !MINIGLUT_USE_LIBC */
#else /* MINIGLUT_NO_LIBC */

#ifdef __GNUC__
void mglut_sincos(float angle, float *sptr, float *cptr)
Expand Down Expand Up @@ -2339,7 +2339,7 @@ float mglut_atan(float x)
modify [8087];
#endif /* __WATCOMC__ */

#endif /* !MINIGLUT_USE_LIBC */
#endif /* MINIGLUT_NO_LIBC */

#define PI 3.1415926536f

Expand Down
2 changes: 1 addition & 1 deletion miniglut.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MiniGLUT - minimal GLUT subset without dependencies
Copyright (C) 2020-2022 John Tsiombikas <[email protected]>
Copyright (C) 2020-2024 John Tsiombikas <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 7a10002

Please sign in to comment.