pkg/archlinux: Add multilib package

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
cmake: add autodetection for waffle_has_egl, glx...

Silence the pkg_check_modules and check set the default
options depending on the packages found.

Error out if the user has selected an option and it's
requirements are not met.

v2:
 - Do not silence pkg_check_modules.
 - Explicitly list the failing requirements.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wflinfo: don't leak the current context

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
examples/gl_basic: don't leak the current context

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
core: Remove empty structs from core objects

Emil discovered that MSVC does rejects empty structs with the error
message "C requires that a struct or union has at least one member".

This patch removes all empty structs from the wcore objects, and
replaces each with a pair of safe typecast functions that provide
bidirectional casting waffle_OBJ <-> wcore_OBJ.

Reported-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cgl: Fix build error introduced by 0e1ae83

Commit 0e1ae83 added a fatal typo. Fix it with

  s/context_version_major/context_major_version/
  s/context_version_minor/context_mino_version/

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cmake: Fix Mac build error from commit 62a4aab9

Commit 62a4aab9 set the CMake property LINK_INTERFACE_LIBRARIES to empty
for libwaffle, because Debian's packaging tools complained otherwise.
Afterwards, Waffle's CMake neglected to declare the Cocoa library
dependencies for the executables wflinfo, gl_basic, gl_basic_test.
Post-commit, the executables were no longer satisying their Cocoa
dependency transitively through libwaffle.

Fix the build by linking *every* Waffle target to the Cocoa libraries
with a toplevel `link_libraries` directive.

Also, don't unset LINK_INTERFACE_LIBRARIES on the Mac. It causes a CMake
warning that I don't understand.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cgl: use wcore_calloc helper

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
cgl: print the libname on error at cgl_dl_close()

The compiler should have pointed out that there is a
modifier but the parameter is missing. This should
resolve the issue.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
cgl: avoid leaking the PixelFormat

According to apple developer page, starting with OS X v10.5 the
pixelformat is reference counted. The object is created at
CGLChoosePixelFormat and should be unrefeferenced via
CGLReleasePixelFormat/CGLDestroyPixelFormat.

The latter two are identical accoring to the documentation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
api: remove double NULL check

We check if the object is NULL before appending it to the
obj_list and a second time as we append it. Drop the latter
as it makes the code more confusing than it needs to be.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wflinfo: use waffle_dl_sym to get core functions

Unlike MacOS and Linux, Windows is less fortunate to people who
prefer to fetch core OpenGL symbols via  wglGetProcAddress.

Until we merge piglit's dispatch in one shape or the other, we'll
need to manually pick/set the correct function that is used for
each function.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
linux: plug a memory leak

In linux_platform_destroy we close all the handles for the different
libgl* providers, yet we do not free the memory for the base struct
linux_platform, causing a memory leak.

In reality the memory will never be freed ('still reachable' by valgrind)
as we do not have a API to call platform->destroy() and thus cleanup
this and other memory hunks.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
core: return false on failure in waffle_window_resize

The function return type is bool(ean) not a pointer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wflinfo: silence signed/unsigned comparison warning

The variable i is used as and compared vs unsigned int.
Change its type so silence the compiler warning.

Note: GLint is incorrectly typedeffed as unsigned and we're
using signed int where unsigned is required by the GL API
and vice versa. These will be addressed by followup patches.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
waffle_test: build as a static library

Will allow us to move the -fvisiblity=hidden flag to global scale,
without breaking the tests. It makes little sense to have a shared
library only for testing purposes anyway.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: move restrict keyword to c99_compat.h header

The header will be used to consolidate all the mayhem required in
order to get waffle building on compilers that are not fully c99
compliant (msvc 2013).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: define inline keyword and use it across waffle core

This brings us a step closer to getting waffle to build under msvc 2013.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: add snprintf and strcasecmp

Another two C99 functions missing from msvc 2013...

v2: Provide vsnprintf as well. Unused by waffle itself, yet
snprintf is implemented as a wrapper around it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com> [v1]
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: use strerror_s over strerror_r under Windows

Windows/MS has dropped strerror_r support due to it _not_ being
thread-safe. At the same time, every *nix man page claims the
opposite.

The recommendation is to use strerror_s, although when building with
mingw-w64 we link against msvcrt.dll which does not provide the symbol
under Windows XP.

The issue is resolved in mingw-w64 master branch (Rev.6559), and
stable (v3.x). Any version after mingw-w64-crt 3.1.0 should be OK
(Archlinux users need v3.1.0-3 or later).

v2: Update the commit message - Archlinux package 3.1.0-3 has the fix.
v3: Move the definition to c99_compat.h
v4: Explain what the function is (if not C99 standard).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>