nuttx-apps/audioutils/lame/Makefile
Marco Casaroli 37a1f0e068 audioutils/lame: pin the checkout and build its AVX-512 sources
The bundled encoder was checked out from lame's trunk with no revision, so
every build took whatever trunk happened to be at that moment.  lame's trunk
grows vector tiers over time, and each one adds sources that the two build
files have to name:  r6655 offered AVX2 to the vector routines on 2026-07-25,
and r6718 and r6720 added an AVX-512 tier on 2026-07-30.  The AVX-512 sources
were never listed, so sim:alsa stopped linking on x86 hosts:

  takehiro.c:332:    undefined reference to `quantize_lines_xrpow_avx512'
  takehiro.c:533:    undefined reference to `ix_max_avx512'
  takehiro.c:569:    undefined reference to `count_bit_esc_avx512'
  vbrquantize.c:261: undefined reference to `calc_sfb_noise_x34_avx512'

Pin the checkout to r6720 through a LAME_VERSION variable, as the rest of
apps/ pins its third-party sources, and list the three AVX-512 files that
revision provides.  The pin is what keeps the two in step:  the source list is
maintained by hand, so it can only be correct for a known revision.

The checkout is also only performed when lame/configure is absent and is never
updated afterwards, so before this an unpinned tree was frozen at whatever
trunk was on the day it was first built.  Anyone who checked out before
2026-07-30 still links and cannot reproduce the failure, which is why this
surfaced only in CI.

Makefile named just vector/xmm_quantize_sub.c and none of the other vector
sources, so a Make build on an x86 host fails the same way with a longer list
of symbols, from SSE2 upwards.  CI builds sim:alsa through CMake only, so that
half was latent rather than visible.  Both files now list the same nine
sources under the same host condition.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 19:44:51 -03:00

132 lines
4.8 KiB
Makefile

############################################################################
# apps/audioutils/lame/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# The revision to check out. lame's trunk grows vector tiers over time --
# SSE2, then AVX2, then AVX-512 -- and each one adds sources that this file
# and CMakeLists.txt have to name, so an unpinned checkout stops linking on
# the day upstream adds the next one. Raise this deliberately, together with
# the vector source list below.
LAME_VERSION ?= 6720
# Download lame if no lame/configure found
lame-svn:
$(Q) echo "svn checkout lame ..."
$(Q) svn checkout -r $(LAME_VERSION) \
https://svn.code.sf.net/p/lame/svn/trunk/lame lame
ifeq ($(wildcard lame/configure),)
context:: lame-svn
distclean::
$(call DELDIR, lame)
endif
ifeq ($(DST_PATH),)
include $(APPDIR)/Make.defs
# configure in place
DST_PATH := lame
else
# configure out of tree
DST_PATH := $(realpath $(DST_PATH))
include $(DST_PATH)/Make.defs
BIN := $(DST_PATH)/libmp3lame.a
# enable Application.mk PREFIX
PREFIX := $(DST_PATH)$(DELIM)
endif
ifneq ($(CONFIG_ARCH),sim)
CFG_CMDS += --host=$(CONFIG_ARCH)
CFG_CMDS += --cross-prefix=$(CROSSDEV)
endif
SRC_PATH := lame
CFLAGS += -DHAVE_CONFIG_H -D'fast_log2=lame_fast_log2'
CFLAGS += $(INCDIR_PREFIX)$(DST_PATH) \
$(INCDIR_PREFIX)$(SRC_PATH)/include \
$(INCDIR_PREFIX)$(SRC_PATH)/libmp3lame
CFLAGS += -Wno-address -Wno-array-parameter \
-Wno-builtin-declaration-mismatch \
-Wno-incompatible-pointer-types \
-Wno-implicit-function-declaration -Wno-shadow \
-Wno-stringop-overflow -Wno-unused-variable \
-Wno-unused-but-set-variable \
-msse
CSRCS += $(SRC_PATH)/libmp3lame/bitstream.c \
$(SRC_PATH)/libmp3lame/encoder.c \
$(SRC_PATH)/libmp3lame/fft.c \
$(SRC_PATH)/libmp3lame/gain_analysis.c \
$(SRC_PATH)/libmp3lame/id3tag.c \
$(SRC_PATH)/libmp3lame/lame.c \
$(SRC_PATH)/libmp3lame/newmdct.c \
$(SRC_PATH)/libmp3lame/psymodel.c \
$(SRC_PATH)/libmp3lame/quantize.c \
$(SRC_PATH)/libmp3lame/quantize_pvt.c \
$(SRC_PATH)/libmp3lame/set_get.c \
$(SRC_PATH)/libmp3lame/vbrquantize.c \
$(SRC_PATH)/libmp3lame/reservoir.c \
$(SRC_PATH)/libmp3lame/tables.c \
$(SRC_PATH)/libmp3lame/takehiro.c \
$(SRC_PATH)/libmp3lame/util.c \
$(SRC_PATH)/libmp3lame/VbrTag.c \
$(SRC_PATH)/libmp3lame/version.c \
$(SRC_PATH)/libmp3lame/presets.c
# lame's configure enables the SSE2, AVX2 and AVX-512 dispatch paths whenever
# the host compiler accepts their per-function target attributes, and the
# scalar code then calls into them, so the whole group has to be built on an
# x86 host. Other hosts keep lame's scalar implementation.
ifneq ($(CONFIG_HOST_X86)$(CONFIG_HOST_X86_64),)
CSRCS += $(SRC_PATH)/libmp3lame/vector/xmm_quantize_sub.c \
$(SRC_PATH)/libmp3lame/vector/xmm_choose_table.c \
$(SRC_PATH)/libmp3lame/vector/xmm_quantize_lines.c \
$(SRC_PATH)/libmp3lame/vector/xmm_calc_sfb_noise.c \
$(SRC_PATH)/libmp3lame/vector/avx2_choose_table.c \
$(SRC_PATH)/libmp3lame/vector/avx2_quantize_lines.c \
$(SRC_PATH)/libmp3lame/vector/avx512_choose_table.c \
$(SRC_PATH)/libmp3lame/vector/avx512_quantize_lines.c \
$(SRC_PATH)/libmp3lame/vector/avx512_calc_sfb_noise.c
endif
LAME_CONFIG_SCRIPT := $(CURDIR)$(DELIM)lame$(DELIM)configure
$(DST_PATH)/config.h:
$(Q)echo "lame configure... $(CONFIG_ARCH)"
$(Q)cd $(DST_PATH) && $(LAME_CONFIG_SCRIPT) \
--disable-cpml --disable-decoder --disable-efence \
--disable-frontend --disable-mp3x --disable-gtktest \
--disable-ipv6 --disable-rpath --enable-static \
$(CFG_CMDS)
context:: $(DST_PATH)/config.h
ifneq ($(PREFIX),)
@$(eval ALL_SRCS = $(CSRCS))
@$(foreach src,$(ALL_SRCS),$(shell mkdir -p $(PREFIX)$(dir $(src))))
endif
distclean::
$(Q)if [ -d $(DST_PATH) ]; then cd $(DST_PATH) && $(MAKE) distclean; fi
include $(APPDIR)/Application.mk