2022-06-27 07:35:04 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-06-24 10:05:39 +02:00
|
|
|
|
2022-06-27 11:46:13 +02:00
|
|
|
# Copyright 2022, FOSS-VG Developers and Contributers
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# version 3 along with this program.
|
|
|
|
# If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
|
2022-06-24 10:23:12 +02:00
|
|
|
if [ -z "$CXX" ]; then
|
|
|
|
CXX="c++"
|
|
|
|
fi
|
|
|
|
if [ -z "$CXXFLAGS" ]; then
|
|
|
|
CXXFLAGS="-std=c++20 -Wall"
|
|
|
|
fi
|
|
|
|
CXX_WITH_FLAGS="$CXX $CXXFLAGS"
|
|
|
|
|
2022-06-24 12:36:15 +02:00
|
|
|
# `.cpp` files in src/lib will be automatically picked up and compiled into
|
|
|
|
# dynamically linked libraries.
|
2022-06-24 09:21:57 +02:00
|
|
|
echo "Building libs..."
|
|
|
|
mkdir -pv bin/lib
|
|
|
|
for lib in $(find ./src/lib -name "*.cpp"); do
|
2022-06-27 04:48:21 +02:00
|
|
|
COMPILE_COMMAND="$CXX_WITH_FLAGS -fPIC -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib"
|
2022-06-24 10:05:39 +02:00
|
|
|
echo $COMPILE_COMMAND
|
2022-06-24 12:36:15 +02:00
|
|
|
$COMPILE_COMMAND &
|
2022-06-24 09:21:57 +02:00
|
|
|
done
|
|
|
|
|
2022-06-24 16:36:57 +02:00
|
|
|
wait
|
2022-06-24 10:05:39 +02:00
|
|
|
|
2022-06-24 09:21:57 +02:00
|
|
|
# Commands for every program need to be given individually because we can't
|
|
|
|
# just add all shared libraries to all programs.
|
|
|
|
# Or can we? Idk, cba to find out.
|
2022-06-24 10:05:39 +02:00
|
|
|
|
|
|
|
# How to build a tool: Tell the compiler where to find shared libraries and
|
2022-06-24 16:50:41 +02:00
|
|
|
# which libraries to use.
|
2022-06-24 10:05:39 +02:00
|
|
|
# Example: shared libraries are in bin/lib => -Lbin/lib
|
2022-06-24 16:50:41 +02:00
|
|
|
# one of the libraries in that directory is nbt.so => use with -l:nbt.so
|
2022-06-24 10:05:39 +02:00
|
|
|
# How to run a tool: specify the library path to use for the dynamic linker
|
2022-06-24 16:50:41 +02:00
|
|
|
# when running a program
|
2022-06-24 10:05:39 +02:00
|
|
|
# Example: LD_LIBRARY_PATH=bin/lib bin/tools/dumpnbt
|
|
|
|
echo "Building tools..."
|
|
|
|
mkdir -pv bin/tools
|
2022-06-27 04:49:05 +02:00
|
|
|
# add compile commands to this array
|
|
|
|
COMPILE_COMMANDS=(
|
2022-06-28 18:54:50 +02:00
|
|
|
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -l:nbt.so -o bin/tools/dumpnbt"
|
2022-06-27 04:49:05 +02:00
|
|
|
)
|
|
|
|
for command in ${!COMPILE_COMMANDS[@]}; do
|
|
|
|
echo "${COMPILE_COMMANDS[command]}"
|
|
|
|
${COMPILE_COMMANDS[command]} &
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|