216 lines
7.2 KiB
Zig
216 lines
7.2 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const upstream = b.dependency("alsa-lib", .{});
|
|
|
|
// Create config header matching autotools output
|
|
const config = b.addConfigHeader(.{
|
|
.style = .blank,
|
|
.include_path = "config.h",
|
|
}, .{
|
|
.PACKAGE_NAME = "alsa-lib",
|
|
.VERSION = "1.2.14",
|
|
.HAVE_USELOCALE = 1,
|
|
.HAVE_EACCESS = 1,
|
|
.HAVE_ENDIAN_H = 1,
|
|
.HAVE_SYS_SHM_H = 1,
|
|
.HAVE_MALLOC_H = 1,
|
|
.HAVE_LFS = 1,
|
|
.HAVE_LIBDL = 1, // Match native build
|
|
// .PIC = 0, // Remove PIC entirely to enable builtin symbols
|
|
.BUILD_PCM = "1",
|
|
.BUILD_MIXER = "1",
|
|
.BUILD_HWDEP = "1",
|
|
.ENABLE_STATIC = 1, // Match --enable-static=yes
|
|
.ENABLE_SHARED = 0, // Match --enable-shared=no
|
|
.ALSA_DEVICE_DIRECTORY = "/dev/snd/",
|
|
.ALSA_CONFIG_DIR = "/usr/share/alsa",
|
|
.ALSA_PLUGIN_DIR = "/usr/lib/alsa-lib",
|
|
.SND_MAX_CARDS = 32,
|
|
.BUILD_PCM_PLUGIN_ADPCM = "1",
|
|
.BUILD_PCM_PLUGIN_ALAW = "1",
|
|
.BUILD_PCM_PLUGIN_IEC958 = "1",
|
|
.BUILD_PCM_PLUGIN_LFLOAT = "1",
|
|
.BUILD_PCM_PLUGIN_MMAP_EMUL = "1",
|
|
.BUILD_PCM_PLUGIN_MULAW = "1",
|
|
.BUILD_PCM_PLUGIN_RATE = "1",
|
|
.BUILD_PCM_PLUGIN_ROUTE = "1",
|
|
.__SYMBOL_PREFIX = "",
|
|
._GNU_SOURCE = 1,
|
|
.HAVE_GNU_LD = 1,
|
|
.HAVE_ELF = 1,
|
|
.HAVE_ASM_PREVIOUS_DIRECTIVE = 1,
|
|
.BUILD_STATIC = 1,
|
|
.BUILD_PCM_PLUGIN_HW = 1,
|
|
.SND_PCM_BUILTIN = 1,
|
|
});
|
|
|
|
// Create version.h
|
|
const version_h = b.addWriteFiles();
|
|
_ = version_h.add("version.h",
|
|
\\/*
|
|
\\ * version.h
|
|
\\ */
|
|
\\
|
|
\\#define SND_LIB_MAJOR 1 /**< major number of library version */
|
|
\\#define SND_LIB_MINOR 2 /**< minor number of library version */
|
|
\\#define SND_LIB_SUBMINOR 14 /**< subminor number of library version */
|
|
\\#define SND_LIB_EXTRAVER 1000000 /**< extra version number, used mainly for betas */
|
|
\\/** library version */
|
|
\\#define SND_LIB_VER(maj, min, sub) (((maj)<<16)|((min)<<8)|(sub))
|
|
\\#define SND_LIB_VERSION SND_LIB_VER(SND_LIB_MAJOR, SND_LIB_MINOR, SND_LIB_SUBMINOR)
|
|
\\/** library version (string) */
|
|
\\#define SND_LIB_VERSION_STR "1.2.14"
|
|
\\
|
|
);
|
|
|
|
// Generate asoundlib.h
|
|
const asoundlib_h = b.addWriteFiles();
|
|
_ = asoundlib_h.add("asoundlib.h",
|
|
\\/*
|
|
\\ * ALSA library - main header file
|
|
\\ */
|
|
\\
|
|
\\#ifndef __ALSA_ASOUNDLIB_H
|
|
\\#define __ALSA_ASOUNDLIB_H
|
|
\\
|
|
\\#include <stdio.h>
|
|
\\#include <stdlib.h>
|
|
\\#include <string.h>
|
|
\\#include <fcntl.h>
|
|
\\#include <assert.h>
|
|
\\#include <endian.h>
|
|
\\#include <sys/poll.h>
|
|
\\#include <errno.h>
|
|
\\#include <stdint.h>
|
|
\\#include <sys/types.h>
|
|
\\#include <unistd.h>
|
|
\\
|
|
\\#include <alsa/asoundef.h>
|
|
\\#include <alsa/version.h>
|
|
\\#include <alsa/global.h>
|
|
\\#include <alsa/input.h>
|
|
\\#include <alsa/output.h>
|
|
\\#include <alsa/error.h>
|
|
\\#include <alsa/conf.h>
|
|
\\#include <alsa/control.h>
|
|
\\#include <alsa/pcm.h>
|
|
\\
|
|
\\#endif /* __ALSA_ASOUNDLIB_H */
|
|
\\
|
|
);
|
|
|
|
const lib = b.addLibrary(.{
|
|
.name = "asound",
|
|
.linkage = .static,
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
|
|
lib.addConfigHeader(config);
|
|
lib.addIncludePath(upstream.path("include"));
|
|
lib.addIncludePath(upstream.path("src/pcm")); // For pcm_rate.h etc
|
|
lib.addIncludePath(b.path(".")); // For our pcm_symbols_list.c
|
|
lib.addIncludePath(version_h.getDirectory());
|
|
lib.addIncludePath(asoundlib_h.getDirectory());
|
|
|
|
// Create alsa as symlink for the include directory. Not sure why upstream
|
|
// does this, but since we're not using their scripts, we need to do that
|
|
// as well
|
|
const create_symlink = b.addSystemCommand(&.{ "sh", "-c", "rm -f alsa; ln -sf . alsa" });
|
|
create_symlink.setCwd(upstream.path("include"));
|
|
lib.step.dependOn(&create_symlink.step);
|
|
|
|
lib.addCSourceFiles(.{
|
|
.root = upstream.path(""),
|
|
.files = &.{
|
|
"src/conf.c",
|
|
"src/confeval.c",
|
|
"src/confmisc.c",
|
|
"src/input.c",
|
|
"src/output.c",
|
|
"src/async.c",
|
|
"src/error.c",
|
|
"src/dlmisc.c",
|
|
"src/socket.c",
|
|
"src/shmarea.c",
|
|
"src/userfile.c",
|
|
"src/names.c",
|
|
"src/control/control.c",
|
|
"src/control/control_hw.c",
|
|
"src/control/cards.c",
|
|
"src/control/namehint.c",
|
|
"src/control/hcontrol.c",
|
|
"src/control/tlv.c",
|
|
"src/control/setup.c",
|
|
"src/control/ctlparse.c",
|
|
"src/control/eld.c",
|
|
"src/control/control_empty.c", // Empty control
|
|
"src/pcm/pcm.c",
|
|
"src/pcm/pcm_hw.c",
|
|
"src/pcm/pcm_params.c",
|
|
"src/pcm/pcm_misc.c",
|
|
"src/pcm/pcm_mmap.c",
|
|
"src/pcm/pcm_generic.c",
|
|
"src/pcm/pcm_simple.c",
|
|
"src/pcm/pcm_plug.c",
|
|
"src/pcm/mask.c",
|
|
"src/pcm/interval.c",
|
|
// Core PCM plugins - must match native build
|
|
"src/pcm/pcm_copy.c",
|
|
"src/pcm/pcm_linear.c",
|
|
"src/pcm/pcm_null.c",
|
|
"src/pcm/pcm_empty.c",
|
|
"src/pcm/pcm_adpcm.c",
|
|
"src/pcm/pcm_alaw.c",
|
|
"src/pcm/pcm_mulaw.c",
|
|
"src/pcm/pcm_iec958.c",
|
|
"src/pcm/pcm_lfloat.c",
|
|
"src/pcm/pcm_mmap_emul.c",
|
|
"src/pcm/pcm_route.c",
|
|
"src/pcm/pcm_plugin.c", // Plugin support functions
|
|
"src/pcm/pcm_symbols.c", // Builtin plugin registration
|
|
"src/control/control_symbols.c", // Control symbols
|
|
"src/timer/timer_symbols.c", // Timer symbols
|
|
"src/timer/timer.c",
|
|
"src/timer/timer_hw.c",
|
|
"src/timer/timer_query.c",
|
|
"src/timer/timer_query_hw.c",
|
|
},
|
|
.flags = &.{
|
|
"-D_GNU_SOURCE",
|
|
"-D_LARGEFILE64_SOURCE", // Enable 64-bit file operations
|
|
"-D_FILE_OFFSET_BITS=64", // Use 64-bit file offsets
|
|
"-DALSA_LIBRARY_BUILD",
|
|
"-DALSA_STATIC",
|
|
"-DBUILD_STATIC_ONLY",
|
|
"-UPIC", // Explicitly undefine PIC to enable builtin symbols
|
|
},
|
|
});
|
|
|
|
lib.installHeadersDirectory(upstream.path("include"), "alsa", .{
|
|
.include_extensions = &.{
|
|
"asoundef.h",
|
|
"version.h",
|
|
"global.h",
|
|
"input.h",
|
|
"output.h",
|
|
"error.h",
|
|
"conf.h",
|
|
"control.h",
|
|
"pcm.h",
|
|
},
|
|
});
|
|
|
|
// Install generated asoundlib.h and version.h
|
|
lib.installHeader(asoundlib_h.getDirectory().path(b, "asoundlib.h"), "alsa/asoundlib.h");
|
|
lib.installHeader(version_h.getDirectory().path(b, "version.h"), "alsa/version.h");
|
|
|
|
b.installArtifact(lib);
|
|
}
|