Przemysław Pawełczyk commited on
Commit
3a69cdf
·
unverified ·
1 Parent(s): 4dcdfda

ggml : do not use _GNU_SOURCE gratuitously (#1027)

Browse files

* Do not use _GNU_SOURCE gratuitously.

What is needed to build whisper.cpp and examples is availability of
stuff defined in The Open Group Base Specifications Issue 6
(https://pubs.opengroup.org/onlinepubs/009695399/) known also as
Single Unix Specification v3 (SUSv3) or POSIX.1-2001 + XSI extensions.

There is no need to penalize musl libc which simply follows standards.

Not having feature test macros in source code gives greater flexibility
to those wanting to reuse it in 3rd party app, as they can build it with
minimal FTM (_XOPEN_SOURCE=600) or other FTM depending on their needs.

It builds without issues in Alpine (musl libc), Ubuntu (glibc), MSYS2.

* examples : include SDL headers before other headers

This is an attempt at fixing macOS build error coming from SDL2 relying
on Darwin extension memset_pattern4/8/16 coming from Apple's string.h.

Makefile CHANGED
@@ -36,11 +36,12 @@ CFLAGS = -I. -O3 -DNDEBUG -std=c11 -fPIC
36
  CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC
37
  LDFLAGS =
38
 
39
- # ref: https://github.com/ggerganov/whisper.cpp/issues/37
40
- ifneq ($(wildcard /usr/include/musl/*),)
41
- CFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
42
- CXXFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
43
- endif
 
44
 
45
  # OS specific
46
  # TODO: support Windows
 
36
  CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC
37
  LDFLAGS =
38
 
39
+ # clock_gettime came in POSIX.1b (1993)
40
+ # CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
41
+ # posix_memalign came in POSIX.1-2001 / SUSv3
42
+ # M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
43
+ CFLAGS += -D_XOPEN_SOURCE=600
44
+ CXXFLAGS += -D_XOPEN_SOURCE=600
45
 
46
  # OS specific
47
  # TODO: support Windows
examples/command/command.cpp CHANGED
@@ -6,8 +6,8 @@
6
  // ref: https://github.com/ggerganov/whisper.cpp/issues/171
7
  //
8
 
9
- #include "common.h"
10
  #include "common-sdl.h"
 
11
  #include "whisper.h"
12
 
13
  #include <sstream>
 
6
  // ref: https://github.com/ggerganov/whisper.cpp/issues/171
7
  //
8
 
 
9
  #include "common-sdl.h"
10
+ #include "common.h"
11
  #include "whisper.h"
12
 
13
  #include <sstream>
examples/stream/stream.cpp CHANGED
@@ -3,8 +3,8 @@
3
  // A very quick-n-dirty implementation serving mainly as a proof of concept.
4
  //
5
 
6
- #include "common.h"
7
  #include "common-sdl.h"
 
8
  #include "whisper.h"
9
 
10
  #include <cassert>
 
3
  // A very quick-n-dirty implementation serving mainly as a proof of concept.
4
  //
5
 
 
6
  #include "common-sdl.h"
7
+ #include "common.h"
8
  #include "whisper.h"
9
 
10
  #include <cassert>
examples/talk-llama/llama.cpp CHANGED
@@ -1,11 +1,3 @@
1
- // Defines fileno on msys:
2
- #ifndef _GNU_SOURCE
3
- #define _GNU_SOURCE
4
- #include <cstddef>
5
- #include <cstdint>
6
- #include <cstdio>
7
- #endif
8
-
9
  #include "llama-util.h"
10
  #include "llama.h"
11
 
 
 
 
 
 
 
 
 
 
1
  #include "llama-util.h"
2
  #include "llama.h"
3
 
examples/talk-llama/talk-llama.cpp CHANGED
@@ -1,8 +1,8 @@
1
  // Talk with AI
2
  //
3
 
4
- #include "common.h"
5
  #include "common-sdl.h"
 
6
  #include "whisper.h"
7
  #include "llama.h"
8
 
 
1
  // Talk with AI
2
  //
3
 
 
4
  #include "common-sdl.h"
5
+ #include "common.h"
6
  #include "whisper.h"
7
  #include "llama.h"
8
 
examples/talk/talk.cpp CHANGED
@@ -1,8 +1,8 @@
1
  // Talk with AI
2
  //
3
 
4
- #include "common.h"
5
  #include "common-sdl.h"
 
6
  #include "whisper.h"
7
  #include "gpt-2.h"
8
 
 
1
  // Talk with AI
2
  //
3
 
 
4
  #include "common-sdl.h"
5
+ #include "common.h"
6
  #include "whisper.h"
7
  #include "gpt-2.h"
8
 
ggml.c CHANGED
@@ -1,4 +1,3 @@
1
- #define _GNU_SOURCE // Defines CLOCK_MONOTONIC on Linux
2
  #define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
3
 
4
  #include "ggml.h"
 
 
1
  #define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
2
 
3
  #include "ggml.h"