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.

Revisions

  1. Jomy10 revised this gist Dec 21, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions make.rb
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@

    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"],
  2. Jomy10 revised this gist Dec 21, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions make.rb
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,7 @@
    # 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
  3. Jomy10 revised this gist Dec 21, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions make.rb
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,7 @@
    # clang -c $file \
    # -DDEBUG \ # --> cflag of selected configuration
    # -DNO_ARM -DTEST \ # --> cflags of MyLibrary
    # -Ilib/include \ # --> include dir of MyLibrary
    # $(pkg-config SDL2 --cflags) \ # cflags of SDL2 dependency
    # -o OUT/MyLibrary/obj/$file
    # end
    @@ -49,6 +50,8 @@
    # 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
  4. Jomy10 created this gist Dec 21, 2023.
    61 changes: 61 additions & 0 deletions make.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    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",
    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
    # $(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
    # -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