From 90a739181e23ccca16d6ca68cbc2a5178ef6aedb Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sun, 16 Jun 2024 10:13:01 +0200 Subject: [PATCH] improved lv2 Makefile --- templates/lv2-make/Makefile | 116 ++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/templates/lv2-make/Makefile b/templates/lv2-make/Makefile index 6806cb8..9e24679 100644 --- a/templates/lv2-make/Makefile +++ b/templates/lv2-make/Makefile @@ -21,29 +21,29 @@ include vars.mk ifeq ($(OS), Windows_NT) - DLL_SUFFIX = .dll - UI_TYPE = WindowsUI - LV2DIR = $(shell echo '${COMMONPROGRAMFILES}' | sed 's:\\:/:g')/LV2 - LV2DIR_USER = $(shell echo '${APPDATA}' | sed 's:\\:/:g')/LV2 - CC = gcc - CXX = g++ + DLL_SUFFIX := .dll + UI_TYPE := WindowsUI + LV2DIR := $(shell echo '$(COMMONPROGRAMFILES)' | sed 's:\\:/:g')/LV2 + LV2DIR_USER := $(shell echo '$(APPDATA)' | sed 's:\\:/:g')/LV2 + CC := gcc + CXX := g++ else UNAME_S = $(shell uname -s) ifeq ($(UNAME_S), Darwin) - DLL_SUFFIX = .dylib - UI_TYPE = CocoaUI - LV2DIR = /Library/Audio/Plug-Ins/LV2 - LV2DIR_USER = ${HOME}/Library/Audio/Plug-Ins/LV2 - CC = clang - CXX = clang++ + DLL_SUFFIX := .dylib + UI_TYPE := CocoaUI + LV2DIR := /Library/Audio/Plug-Ins/LV2 + LV2DIR_USER := $(HOME)/Library/Audio/Plug-Ins/LV2 + CC := clang + CXX := clang++ else - DLL_SUFFIX = .so - UI_TYPE = X11UI - PREFIX = /usr/local - LV2DIR = ${PREFIX}/lib/lv2 - LV2DIR_USER = ${HOME}/.lv2 - CC = gcc - CXX = g++ + DLL_SUFFIX := .so + UI_TYPE := X11UI + PREFIX := /usr/local + LV2DIR := $(PREFIX)/lib/lv2 + LV2DIR_USER := $(HOME)/.lv2 + CC := gcc + CXX := g++ endif endif @@ -51,59 +51,73 @@ COMMON_DIR := $(or $(COMMON_DIR),.) DATA_DIR := $(or $(DATA_DIR),.) PLUGIN_DIR := $(or $(PLUGIN_DIR),src) -CFLAGS = -O3 -Wall -Wpedantic -Wextra -CFLAGS_ALL = -I${DATA_DIR}/src -I${PLUGIN_DIR} -fPIC ${CFLAGS} ${CFLAGS_EXTRA} +CFLAGS := -O3 -Wall -Wpedantic -Wextra +CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -fPIC $(CFLAGS) $(CFLAGS_EXTRA) -LDFLAGS = -LDFLAGS_ALL = -shared ${LDFLAGS} ${LDFLAGS_EXTRA} +LDFLAGS := +LDFLAGS_ALL := -shared $(LDFLAGS) $(LDFLAGS_EXTRA) -CXXFLAGS = ${CFLAGS} -CXXFLAGS_ALL = -I${DATA_DIR}/src -I${PLUGIN_DIR} -fPIC ${CXXFLAGS} ${CXXFLAGS_EXTRA} +CXXFLAGS := $(CFLAGS) +CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -fPIC $(CXXFLAGS) $(CXXFLAGS_EXTRA) ifeq ($(UNAME_S), Darwin) -CFLAGS_ALL := ${CFLAGS_ALL} -arch arm64 -arch x86_64 -LDFLAGS_ALL := ${LDFLAGS_ALL} -arch arm64 -arch x86_64 -CXXFLAGS_ALL := ${CXXFLAGS_ALL} -arch arm64 -arch x86_64 +CFLAGS_ALL := $(CFLAGS_ALL) -arch arm64 -arch x86_64 +LDFLAGS_ALL := $(LDFLAGS_ALL) -arch arm64 -arch x86_64 +CXXFLAGS_ALL := $(CXXFLAGS_ALL) -arch arm64 -arch x86_64 endif -BUNDLE_DIR = ${BUNDLE_NAME}.lv2 +BUNDLE_DIR := $(BUNDLE_NAME).lv2 -DLL_FILE = ${BUNDLE_NAME}${DLL_SUFFIX} +DLL_FILE := $(BUNDLE_NAME)$(DLL_SUFFIX) -C_SRCS = ${COMMON_DIR}/src/lv2.c ${C_SRCS_EXTRA} -C_OBJS = $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o))) +C_SRCS := $(COMMON_DIR)/src/lv2.c $(C_SRCS_EXTRA) +C_OBJS := $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o))) -CXX_SRCS = ${CXX_SRCS_EXTRA} -CXX_OBJS = $(addprefix build/obj/, $(notdir $(CXX_SRCS:.cpp=.o))) +CXX_SRCS := $(CXX_SRCS_EXTRA) +CXX_OBJS := $(addprefix build/obj/, $(notdir $(CXX_SRCS:.cpp=.o))) -all: build/${BUNDLE_DIR}/manifest.ttl build/${BUNDLE_DIR}/${DLL_FILE} +ALL := build/$(BUNDLE_DIR)/manifest.ttl build/$(BUNDLE_DIR)/$(DLL_FILE) -build/${BUNDLE_DIR}/manifest.ttl: ${DATA_DIR}/data/manifest.ttl.in | build/${BUNDLE_DIR} - cat $^ | sed s/@DLL_SUFFIX@/${DLL_SUFFIX}/g | sed s/@UI_TYPE@/${UI_TYPE}/g > $@ +-include vars-extra.mk + +all: $(ALL) + +build/$(BUNDLE_DIR)/manifest.ttl: $(DATA_DIR)/data/manifest.ttl.in | build/$(BUNDLE_DIR) + cat $^ | sed s/@DLL_SUFFIX@/$(DLL_SUFFIX)/g | sed s/@UI_TYPE@/$(UI_TYPE)/g > $@ ifeq ($(CXX_OBJS),) -build/${BUNDLE_DIR}/${DLL_FILE}: ${C_OBJS} | build/${BUNDLE_DIR} - ${CC} $^ -o $@ ${CFLAGS_ALL} ${LDFLAGS_ALL} +build/$(BUNDLE_DIR)/$(DLL_FILE): $(C_OBJS) | build/$(BUNDLE_DIR) + $(CC) $^ -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) else -build/${BUNDLE_DIR}/${DLL_FILE}: ${C_OBJS} ${CXX_OBJS} | build/${BUNDLE_DIR} - ${CXX} $^ -o $@ ${CFLAGS_ALL} ${CXXFLAGS_ALL} ${LDFLAGS_ALL} +build/$(BUNDLE_DIR)/$(DLL_FILE): $(C_OBJS) $(CXX_OBJS) | build/$(BUNDLE_DIR) + $(CXX) $^ -o $@ $(CFLAGS_ALL) $(CXXFLAGS_ALL) $(LDFLAGS_ALL) endif -build/${BUNDLE_DIR} build/obj: +build/$(BUNDLE_DIR) build/obj: mkdir -p $@ clean: rm -fr build install: all - mkdir -p -m 0755 "${LV2DIR}/${BUNDLE_DIR}" - install -m 0644 build/${BUNDLE_DIR}/manifest.ttl "${LV2DIR}/${BUNDLE_DIR}" - install -m 0755 build/${BUNDLE_DIR}/${DLL_FILE} "${LV2DIR}/${BUNDLE_DIR}" + @for f in `find build/$(BUNDLE_DIR) -type f`; do \ + m=`[ -x $$f ] && echo 0755 || echo 0644`; \ + d=`echo $$f | sed 's:^build/::'` ; \ + d=`dirname $$d`; \ + echo install -m $$m -t "$(LV2DIR)/$$d" -D $$f; \ + install -m $$m -t "$(LV2DIR)/$$d" -D $$f; \ + done install-user: all - mkdir -p -m 0755 "${LV2DIR_USER}/${BUNDLE_DIR}" - install -m 0644 build/${BUNDLE_DIR}/manifest.ttl "${LV2DIR_USER}/${BUNDLE_DIR}" - install -m 0755 build/${BUNDLE_DIR}/${DLL_FILE} "${LV2DIR_USER}/${BUNDLE_DIR}" + @for f in `find build/$(BUNDLE_DIR) -type f`; do \ + m=`[ -x $$f ] && echo 0755 || echo 0644`; \ + d=`echo $$f | sed 's:^build/::'` ; \ + d=`dirname $$d`; \ + echo install -m $$m -t "$(LV2DIR_USER)/$$d" -D $$f; \ + install -m $$m -t "$(LV2DIR_USER)/$$d" -D $$f; \ + done + +-include rules-extra.mk .PHONY: all clean install install-user @@ -112,7 +126,9 @@ install-user: all PERCENT := % $(C_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).c,$$(C_SRCS)) | build/obj - ${CC} $^ -o $@ -c ${CFLAGS_ALL} + $(CC) $^ -o $@ -c $(CFLAGS_ALL) $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cpp,$$(CXX_SRCS)) | build/obj - ${CXX} $^ -o $@ -c ${CXXFLAGS_ALL} + $(CXX) $^ -o $@ -c $(CXXFLAGS_ALL) + +-include rules-secondexp-extra.mk