Makefile: Move re-usable code into common.mk

tight-png
Andri Yngvason 2019-09-07 15:01:53 +00:00
parent 224d1f3804
commit 8374267955
2 changed files with 44 additions and 40 deletions

View File

@ -1,22 +1,3 @@
MACHINE := $(shell $(CC) -dumpmachine)
ARCH := $(firstword $(subst -, ,$(MACHINE)))
BUILD_DIR ?= build-$(MACHINE)
ifeq ($(ARCH),x86_64)
ARCH_CFLAGS := -mavx
else
ifeq ($(ARCH),arm)
ARCH_CFLAGS := -mfpu=neon
endif # end arm block
endif # end x86_64 block
CFLAGS ?= -g -O3 $(ARCH_CFLAGS) -flto -DNDEBUG
LDFLAGS ?= -flto
DSO_NAME=libneatvnc
DSO_MAJOR=0
DSO_MINOR=0
DEPENDENCIES := pixman-1 libuv DEPENDENCIES := pixman-1 libuv
SOURCES := \ SOURCES := \
@ -25,34 +6,20 @@ SOURCES := \
src/vec.c \ src/vec.c \
src/zrle.c \ src/zrle.c \
OBJECTS := $(SOURCES:src/%.c=$(BUILD_DIR)/%.o) $(BUILD_DIR)/miniz.o include common.mk
CFLAGS += -std=gnu11 -D_GNU_SOURCE -Iinc -fvisibility=hidden -Icontrib/miniz \ DSO_NAME=libneatvnc
$(foreach dep,$(DEPENDENCIES),$(shell pkg-config --cflags $(dep))) DSO_MAJOR=0
DSO_MINOR=0
LDFLAGS += $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --libs $(dep))) CFLAGS += -fvisibility=hidden -Icontrib/miniz
OBJECTS += $(BUILD_DIR)/miniz.o
DSO_PATH := $(BUILD_DIR)/$(DSO_NAME) DSO_PATH := $(BUILD_DIR)/$(DSO_NAME)
all: $(DSO_PATH).so.$(DSO_MAJOR).$(DSO_MINOR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(DSO_PATH).so.$(DSO_MAJOR).$(DSO_MINOR): $(OBJECTS) $(DSO_PATH).so.$(DSO_MAJOR).$(DSO_MINOR): $(OBJECTS)
$(CC) -fPIC -shared $^ $(LDFLAGS) -o $@ $(LINK_DSO)
ln -sf $(DSO_NAME).so.$(DSO_MAJOR).$(DSO_MINOR) $(DSO_PATH).so.$(DSO_MINOR) ln -sf $(DSO_NAME).so.$(DSO_MAJOR).$(DSO_MINOR) $(DSO_PATH).so.$(DSO_MINOR)
ln -sf $(DSO_NAME).so.$(DSO_MAJOR).$(DSO_MINOR) $(DSO_PATH).so ln -sf $(DSO_NAME).so.$(DSO_MAJOR).$(DSO_MINOR) $(DSO_PATH).so
CC_OBJ = $(CC) -c $(CFLAGS) $< -o $@ $(CC_DEP_ARGS) -MMD -MP -MF $(@:.o=.deps)
$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) ; $(CC_OBJ)
$(BUILD_DIR)/miniz.o: contrib/miniz/miniz.c | $(BUILD_DIR) ; $(CC_OBJ) $(BUILD_DIR)/miniz.o: contrib/miniz/miniz.c | $(BUILD_DIR) ; $(CC_OBJ)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
-include $(BUILD_DIR)/*.deps
.SUFFIXES:
.SECONDARY:

37
common.mk 100644
View File

@ -0,0 +1,37 @@
MACHINE := $(shell $(CC) -dumpmachine)
ARCH := $(firstword $(subst -, ,$(MACHINE)))
BUILD_DIR ?= build-$(MACHINE)
ifeq ($(ARCH),x86_64)
ARCH_CFLAGS := -mavx
else
ifeq ($(ARCH),arm)
ARCH_CFLAGS := -mfpu=neon
endif # end arm block
endif # end x86_64 block
CFLAGS ?= -g -O3 $(ARCH_CFLAGS) -flto -DNDEBUG
LDFLAGS ?= -flto
CFLAGS += -std=gnu11 -D_GNU_SOURCE -Iinc
CC_OBJ = $(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $(@:.o=.deps)
LINK_DSO = $(CC) -fPIC -shared $^ $(LDFLAGS) -o $@
CFLAGS += $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --cflags $(dep)))
LDFLAGS += $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --libs $(dep)))
OBJECTS := $(SOURCES:src/%.c=$(BUILD_DIR)/%.o)
$(BUILD_DIR): ; mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) ; $(CC_OBJ)
.PHONY: clean
clean: ; rm -rf $(BUILD_DIR)
-include $(BUILD_DIR)/*.deps
.SUFFIXES:
.SECONDARY:
# This clears the default target set by this file
.DEFAULT_GOAL :=