Change build system to meson
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1 @@
|
||||
*.o
|
||||
build_state
|
||||
glava
|
||||
build/
|
||||
136
Makefile
136
Makefile
@@ -1,133 +1,11 @@
|
||||
SHELL := /bin/bash
|
||||
.SHELLFLAGS = -O extglob -c
|
||||
.PHONY: all install clean
|
||||
|
||||
src = $(wildcard *.c)
|
||||
obj = $(src:.c=.o)
|
||||
all:
|
||||
meson build
|
||||
ninja -C build
|
||||
|
||||
# Build type parameter
|
||||
|
||||
ifeq ($(BUILD),debug)
|
||||
CFLAGS_BUILD = -O0 -ggdb -Wall -DGLAVA_DEBUG
|
||||
GLAD_GEN = c-debug
|
||||
STRIP_CMD = $(info Skipping `strip` for debug builds)
|
||||
else
|
||||
CFLAGS_BUILD = -O2 -Wstringop-overflow=0
|
||||
GLAD_GEN = c
|
||||
STRIP_CMD = strip --strip-all glava
|
||||
endif
|
||||
|
||||
# Detect OS if not specified (OSX, Linux, BSD are supported)
|
||||
|
||||
ifndef INSTALL
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
INSTALL = osx
|
||||
else
|
||||
INSTALL = unix
|
||||
endif
|
||||
endif
|
||||
|
||||
ifndef EXECDIR
|
||||
EXECDIR = /usr/bin/
|
||||
endif
|
||||
|
||||
# Install type parameter
|
||||
|
||||
ifeq ($(INSTALL),standalone)
|
||||
CFLAGS_INSTALL = -DGLAVA_STANDALONE
|
||||
endif
|
||||
|
||||
ifeq ($(INSTALL),unix)
|
||||
CFLAGS_INSTALL = -DGLAVA_UNIX
|
||||
ifndef SHADERDIR
|
||||
ifdef XDG_CONFIG_DIRS
|
||||
SHADERDIR = /$(firstword $(subst :, ,$(XDG_CONFIG_DIRS)))/glava/
|
||||
ifeq ($(wildcard $(SHADERDIR)/..),)
|
||||
SHADERDIR = /etc/xdg/glava/
|
||||
endif
|
||||
else
|
||||
SHADERDIR = /etc/xdg/glava/
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef ENABLE_GLFW
|
||||
CFLAGS_GLFW = -DGLAVA_GLFW
|
||||
LDFLAGS_GLFW = -lglfw
|
||||
endif
|
||||
|
||||
ifndef DISABLE_GLX
|
||||
CFLAGS_GLX = -DGLAVA_GLX
|
||||
LDFLAGS_GLX = -lXrender
|
||||
endif
|
||||
|
||||
ifeq ($(INSTALL),osx)
|
||||
CFLAGS_INSTALL = -DGLAVA_OSX
|
||||
ifndef SHADERDIR
|
||||
SHADERDIR = /Library/glava
|
||||
endif
|
||||
endif
|
||||
|
||||
LDFLAGS += $(ASAN) -lpulse -lpulse-simple -pthread $(LDFLAGS_GLFW) -ldl -lm -lX11 -lXext $(LDFLAGS_GLX)
|
||||
|
||||
PYTHON = python
|
||||
|
||||
GLAVA_VERSION = \"$(shell git describe --tags 2>/dev/null)\"
|
||||
ifeq ($(GLAVA_VERSION),\"\")
|
||||
GLAVA_VERSION = \"unknown\"
|
||||
endif
|
||||
|
||||
ifdef DESTDIR
|
||||
DESTDIR += /
|
||||
endif
|
||||
|
||||
GLAD_INSTALL_DIR = glad
|
||||
GLAD_SRCFILE = glad.c
|
||||
GLAD_ARGS = --generator=$(GLAD_GEN) --extensions=GL_EXT_framebuffer_multisample,GL_EXT_texture_filter_anisotropic
|
||||
CFLAGS_COMMON = -DGLAVA_VERSION="$(GLAVA_VERSION)" -DSHADER_INSTALL_PATH="\"$(SHADERDIR)\""
|
||||
CFLAGS_USE = $(CFLAGS_COMMON) $(CFLAGS_GLX) $(CFLAGS_GLFW) $(CFLAGS_BUILD) $(CFLAGS_INSTALL) $(CFLAGS)
|
||||
|
||||
# Store relevant variables that may change depending on the environment or user input
|
||||
STATE = $(BUILD),$(INSTALL),$(PREFIX),$(ENABLE_GLFW),$(DISABLE_GLX),$(PYTHON),$(CC),$(CFLAGS_USE)
|
||||
# Only update the file if the contents changed, `make` just looks at the timestamp
|
||||
$(shell if [[ ! -e build_state ]]; then touch build_state; fi)
|
||||
$(shell if [ '$(STATE)' != "`cat build_state`" ]; then echo '$(STATE)' > build_state; fi)
|
||||
|
||||
all: glava
|
||||
|
||||
%.o: %.c build_state
|
||||
@$(CC) $(CFLAGS_USE) -o $@ -c $(firstword $<)
|
||||
@echo "CC $@"
|
||||
|
||||
glava: $(obj)
|
||||
@$(CC) -o glava $(obj) $(LDFLAGS)
|
||||
@echo "CC glava"
|
||||
$(STRIP_CMD)
|
||||
|
||||
.PHONY: glad
|
||||
glad: build_state
|
||||
@cd $(GLAD_INSTALL_DIR) && $(PYTHON) -m glad $(GLAD_ARGS) --local-files --out-path=.
|
||||
@cp glad/*.h .
|
||||
@cp glad/glad.c .
|
||||
|
||||
# Empty build state goal, used to force some of the above rules to re-run if `build_state` was updated
|
||||
build_state: ;
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(obj) glava glad.o build_state
|
||||
|
||||
EXECTARGET = $(shell readlink -m "$(DESTDIR)$(EXECDIR)/glava")
|
||||
SHADERTARGET = $(shell readlink -m "$(DESTDIR)$(SHADERDIR)")
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
install -Dm755 glava $(EXECTARGET)
|
||||
install -d $(SHADERTARGET)
|
||||
cp -Rv shaders/!(test|test_rc.glsl) $(SHADERTARGET)
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
rm $(EXECTARGET)
|
||||
rm -rf $(SHADERTARGET)
|
||||
cd build && meson install
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
13
README.md
13
README.md
@@ -8,12 +8,16 @@
|
||||
```bash
|
||||
$ git clone https://github.com/wacossusca34/glava
|
||||
$ cd glava
|
||||
$ CFLAGS="-march=native" make
|
||||
$ sudo make install
|
||||
$ CFLAGS="-march=native" meson build
|
||||
$ ninja -C build
|
||||
$ cd build
|
||||
$ sudo meson install
|
||||
$ glava
|
||||
```
|
||||
|
||||
You can pass `BUILD=debug` to the makefile for debug builds of both glad and glava, and you can manually specify install targets with `INSTALL=...`, possible arguments are `unix` for FHS compliant Linux and BSD distros, `osx` for Mac OSX, and `standalone` which allows you to run GLava in the build directory.
|
||||
You can run `meson configure` in the project directory to get a list of available compile-time configuration options.
|
||||
|
||||
You can pass `-DDEBUG` to meson for debug builds of both glad (only with `-Dglad`) and glava, `-Dstandalone` allows you to run GLava in the build directory.
|
||||
|
||||
**Requirements:**
|
||||
|
||||
@@ -23,6 +27,7 @@ You can pass `BUILD=debug` to the makefile for debug builds of both glad and gla
|
||||
|
||||
**Additional compile time requirements:**
|
||||
|
||||
- Meson
|
||||
- GCC (this program uses GNU C features)
|
||||
|
||||
**Optional requirements:**
|
||||
@@ -31,7 +36,7 @@ You can pass `BUILD=debug` to the makefile for debug builds of both glad and gla
|
||||
|
||||
**Ubuntu/Debian users:** the following command ensures you have all the needed packages and headers to compile GLava:
|
||||
```bash
|
||||
sudo apt-get install libpulse0 libpulse-dev libxext6 libxext-dev libxrender-dev libxcomposite-dev make gcc
|
||||
sudo apt-get install libpulse0 libpulse-dev libxext6 libxext-dev libxrender-dev libxcomposite-dev meson gcc
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
10
glad_generate.sh
Executable file
10
glad_generate.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
GLAD_GEN="${1:-c}"
|
||||
|
||||
pushd glad
|
||||
python -m glad --generator=${GLAD_GEN} --extensions=GL_EXT_framebuffer_multisample,GL_EXT_texture_filter_anisotropic --local-files --out-path=.
|
||||
popd
|
||||
cp glad/*.h glava/
|
||||
cp glad/glad.c glava/
|
||||
96
meson.build
Normal file
96
meson.build
Normal file
@@ -0,0 +1,96 @@
|
||||
project(
|
||||
'glava',
|
||||
'c',
|
||||
version: run_command('git', 'describe', '--tags').stdout().strip()
|
||||
)
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
if get_option('buildtype').startswith('debug')
|
||||
add_project_arguments(
|
||||
'-O0',
|
||||
'-ggdb',
|
||||
'-Wall',
|
||||
'-DGLAVA_DEBUG',
|
||||
language: 'c'
|
||||
)
|
||||
if get_option('glad')
|
||||
run_command('./glad_generate.sh', 'c-debug')
|
||||
endif
|
||||
else
|
||||
add_project_arguments(
|
||||
'-O2',
|
||||
'-Wstringpop-overflow=0',
|
||||
language: 'c'
|
||||
)
|
||||
if get_option('glad')
|
||||
run_command('./glad_generate.sh')
|
||||
endif
|
||||
endif
|
||||
|
||||
glava_dependencies = [
|
||||
dependency('threads'),
|
||||
cc.find_library('pulse'),
|
||||
cc.find_library('pulse-simple'),
|
||||
cc.find_library('dl'),
|
||||
cc.find_library('m'),
|
||||
cc.find_library('X11'),
|
||||
cc.find_library('Xext')
|
||||
]
|
||||
|
||||
glava_version = meson.project_version()
|
||||
if glava_version == ''
|
||||
glava_version = 'unknown'
|
||||
endif
|
||||
|
||||
shaderdir = get_option('shaderdir')
|
||||
if host_machine.system() == 'linux'
|
||||
add_project_arguments(
|
||||
'-DGLAVA_UNIX',
|
||||
language: 'c'
|
||||
)
|
||||
endif
|
||||
if host_machine.system() == 'darwin'
|
||||
add_project_arguments(
|
||||
'-DGLAVA_OSX',
|
||||
language: 'c'
|
||||
)
|
||||
shaderdir = '/Library/glava/'
|
||||
endif
|
||||
|
||||
if get_option('enable_glfw')
|
||||
add_project_arguments(
|
||||
'-DGLAVA_GLFW',
|
||||
language: 'c'
|
||||
)
|
||||
glava_dependencies += dependency('glfw')
|
||||
endif
|
||||
|
||||
if not get_option('disable_glx')
|
||||
add_project_arguments(
|
||||
'-DGLAVA_GLX',
|
||||
language: 'c'
|
||||
)
|
||||
glava_dependencies += cc.find_library('Xrender')
|
||||
endif
|
||||
|
||||
if get_option('standalone')
|
||||
add_project_arguments(
|
||||
'-DGLAVA_STANDALONE',
|
||||
language: 'c')
|
||||
endif
|
||||
|
||||
add_project_arguments(
|
||||
'-DGLAVA_VERSION="'+glava_version+'"',
|
||||
'-DSHADER_INSTALL_PATH="'+get_option('shaderdir')+'"',
|
||||
language: 'c'
|
||||
)
|
||||
|
||||
executable(
|
||||
'glava',
|
||||
sources: run_command('find', 'glava', '-type', 'f', '-name', '*.c', '-print').stdout().strip().split('\n'),
|
||||
dependencies: glava_dependencies,
|
||||
install: true
|
||||
)
|
||||
|
||||
install_subdir('shaders/glava', install_dir: shaderdir+'/../')
|
||||
5
meson_options.txt
Normal file
5
meson_options.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
option('shaderdir', type: 'string', value: '/etc/xdg/glava/', description: 'Default shader directory')
|
||||
option('enable_glfw', type: 'boolean', value: false, description: 'Enable GLFW backend')
|
||||
option('disable_glx', type: 'boolean', value: false, description: 'Disable GLX')
|
||||
option('standalone', type: 'boolean', value: false, description: 'OS-independent build')
|
||||
option('glad', type: 'boolean', value: false, description: 'Regenerate GLAD')
|
||||
Reference in New Issue
Block a user