Skip to content

Commit

Permalink
Mkefiles: Add controls for building on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaZulberti committed Sep 8, 2023
1 parent 3f5fcd4 commit 78e179f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# dispatches external builds and calls our main makefile in src.
# also handles some global settings for compilers and debug flags.

# OS detect
UNAME := $(shell uname)

.PHONY:all ext src clean distclean bin install release cli
include bin/config.mk.defaults
sinclude bin/config.mk
Expand Down Expand Up @@ -88,7 +91,11 @@ CLI=../bin/vkdt-cli ../bin/vkdt-fit
cli: Makefile bin ext
$(MAKE) -C src/ ${CLI} tools modules

ifneq ($(UNAME),Darwin)
LIB=../bin/libvkdt.so
else
LIB=../bin/libvkdt.dylib
endif
lib: Makefile bin ext
$(MAKE) -C src/ ${LIB} modules

Expand Down
35 changes: 26 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# flat makefile for everything, -j friendly.

# OS detect
UNAME := $(shell uname)

VKDT_GLFW_CFLAGS := $(shell pkg-config --cflags glfw3)
VKDT_GLFW_LDFLAGS := $(shell pkg-config --libs glfw3)

ifneq ($(UNAME),Darwin)
OS_CFLAGS = -D_GNU_SOURCE
OS_CXXFLAGS = -D_GNU_SOURCE

SHARED_FLAGS = -shared -nostartfiles -Wl,-soname,libvkdt.so
SHARED_LIB = libvkdt.so
else

SHARED_FLAGS = -dynamiclib -Wl,-install_name,libvkdt.dylib
SHARED_LIB = libvkdt.dylib
endif

# modules which need a dso have flat.mk, collect all these.
# generate list of all modules (the * in pipe/modules/*/flat.mk)
FLATMK:=$(notdir $(patsubst %/,%,$(dir $(wildcard pipe/modules/*/flat.mk))))
Expand Down Expand Up @@ -58,11 +76,10 @@ clean: Makefile
rm -f pipe/modules/*/{ctooltips,ptooltips}

# GNU_SOURCE for sched_affinity
CFLAGS=-Wall -pipe -I. -D_GNU_SOURCE -std=c11 -DVK_ENABLE_BETA_EXTENSIONS
CXXFLAGS=-Wall -pipe -I. -D_GNU_SOURCE
EXE_CFLAGS?=-fPIC
LDFLAGS=
VK_CFLAGS:=$(shell pkg-config --cflags vulkan)
CFLAGS = -Wall -pipe -I. -std=c11 -DVK_ENABLE_BETA_EXTENSIONS $(OS_CFLAGS)
CXXFLAGS = -Wall -pipe -I. -std=c++11 $(OS_CXXFLAGS)
VK_CFLAGS = $(shell pkg-config --cflags vulkan)
EXE_CFLAGS ?= -fPIC

qvk/%.o: qvk/%.c Makefile $(QVK_H) qvk/flat.mk
$(CC) $(CFLAGS) $(EXE_CFLAGS) $(OPT_CFLAGS) $(VK_CFLAGS) $(QVK_CFLAGS) -c $< -o $@
Expand Down Expand Up @@ -117,8 +134,8 @@ ext/imgui/examples/%.o: ext/imgui/examples/%.cpp Makefile

# library
# ======================
../bin/libvkdt.so: $(QVK_O) $(CORE_O) $(PIPE_O) $(DB_O) Makefile core/version.h
$(CC) -shared -nostartfiles -Wl,-soname,libvkdt.so -o $@ $(QVK_O) $(CORE_O) $(PIPE_O) $(DB_O)
../bin/$(SHARED_LIB): $(QVK_O) $(CORE_O) $(PIPE_O) $(DB_O) Makefile core/version.h
$(CC) $(SHARED_FLAGS) $(QVK_LDFLAGS) -o $@ $(QVK_O) $(CORE_O) $(PIPE_O) $(DB_O)

# modules
# ======================
Expand Down Expand Up @@ -149,13 +166,13 @@ $(foreach MOD,$(FLATMK),\

define MOD_RULE
pipe/modules/$1/lib$1.so: pipe/modules/$1/main.c pipe/modules/$1/flat.mk $(MOD_$(1)_DEPS) $(MOD_GLOBAL_DEPS)
$(CC) $(CFLAGS) $(MOD_GLOBAL_CFLAGS) $(OPT_CFLAGS) $(VK_CFLAGS) $(MOD_$(1)_CFLAGS) -shared $$< $(MOD_$(1)_C) -o $$@ $(LDFLAGS) $(OPT_LDFLAGS) $(MOD_$(1)_LDFLAGS)
$(CC) $(CFLAGS) $(MOD_GLOBAL_CFLAGS) $(OPT_CFLAGS) $(VK_CFLAGS) $(MOD_$(1)_CFLAGS) -shared $$< $(MOD_$(1)_C) -o $$@ $(LDFLAGS) $(OPT_LDFLAGS) -lvkdt -L../bin $(MOD_$(1)_LDFLAGS)
endef
$(foreach mod,$(MODULES),$(eval $(call MOD_RULE,$(mod))))

define MOD_RULEXX
pipe/modules/$1/lib$1.so:pipe/modules/$1/main.cc pipe/modules/$1/flat.mk $(MOD_$(1)_DEPS) $(MOD_GLOBAL_DEPS)
$(CXX) $(CXXFLAGS) $(MOD_GLOBAL_CFLAGS) $(OPT_CFLAGS) $(VK_CFLAGS) $(MOD_$(1)_CFLAGS) -shared $$< $(MOD_$(1)_C) -o $$@ $(LDFLAGS) $(OPT_LDFLAGS) $(MOD_$(1)_LDFLAGS)
$(CXX) $(CXXFLAGS) $(MOD_GLOBAL_CFLAGS) $(OPT_CFLAGS) $(VK_CFLAGS) $(MOD_$(1)_CFLAGS) -shared $$< $(MOD_$(1)_C) -o $$@ $(LDFLAGS) $(OPT_LDFLAGS) -lvkdt -L../bin $(MOD_$(1)_LDFLAGS)
endef
$(foreach mod,$(MODULESXX),$(eval $(call MOD_RULEXX,$(mod))))

Expand Down

0 comments on commit 78e179f

Please sign in to comment.