Skip to content

Instantly share code, notes, and snippets.

@Jomy10
Last active December 21, 2023 14:56
Show Gist options
  • Save Jomy10/add2f655fe27b16d917b9c16946dba38 to your computer and use it in GitHub Desktop.
Save Jomy10/add2f655fe27b16d917b9c16946dba38 to your computer and use it in GitHub Desktop.
Beaver 3.0 example
require 'beaver'
project = Project.new("MyProject")
project.set_configs("Debug", "Release")
# Set configuration options for the C language
project.c_configs = {
"Debug" => C::Configuration.new(cflags: ["-DDEBUG"]),
"Release" => C::Configuration.new(cflags: ["-DRELEASE"])
}
project.default_config = "Debug"
C::Library.system("pthread")
C::Library.pkg_config("SDL2")
C::Library.new(
name: "MyLibrary",
language: "C", # default: based on files
sources: ["lib/*.c", "lib/inner/*.c"],
include: { :internal => "lib", :public => "lib/include" },
cflags: ["-DNO_ARM", "-DTEST"],
dependencies: ["SDL2", "pthread"]
)
main_exec = C::Executable.new(
name: "Main",
sources: "src/*.c",
include: "src/include",
# static(LibraryName) means force statically link this library
dependencies: [static("MyLibrary"), "MyOtherLibrary", dynamic("MyDynLibrary")]
)
if project.config == "Debug"
main_exec.cflags << "-DNO_OPT"
end
# Build "Main" (with configuration == Debug):
# 1. Build MyLibrary
# for file in MyLibrary.sources
# clang -c $file \
# -DDEBUG \ # --> cflag of selected configuration
# -DNO_ARM -DTEST \ # --> cflags of MyLibrary
# -Ilib \ # --> internal include of MyLibrary
# -Ilib/include \ # --> include dir of MyLibrary
# $(pkg-config SDL2 --cflags) \ # cflags of SDL2 dependency
# -o OUT/MyLibrary/obj/$file
# end
# ar OU/MyLibrary/libMyLibrary.a OUT/MyLibrary/obj/**/*.o
# # also build dyn lib depending on configurationm
#
# 2. Build Main executable:
# # Compile into objs
# for file in Main.sources
# clang -c $file \
# -DDEBUG \ # --> cflag of selected configuration
# -DNO_OPT \ # --> cflag of Main
# -Ilib/include \ # --> public include dir of MyLibrary
# -Isrc/include \ # --> include dir of Main
# -o OUT/Main/obj/$file
# end
# # Soft links to force static/dyn libs
# ln -s OUT/MyLibrary/libMyLibrary.a OUT/Main/deps/static/libMyLibrary.a
# ln -s OUT/MyDynLibrary/libMyDynLibrary.so OUT/Main/deps/dynamic/libMyDynLibrary.so
# # Linking
# clang OUT/Main/obj/**/*.o \
# $(pkg-config SDL2 --libs) -lpthread \ # --> ldflags of "MyLibrary" (= ldflags of SDL2 and pthread)
# -LOUT/Main/deps/static -lMyLibrary -LOUT/MyOtherLibrary -lMyOtherLibrary -LOUT/Main/deps/dynamic -lMyDynLibrary \ # --> ldflags of "Main"
# -o OUT/main/main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment