Skip to content

Commit

Permalink
build: make cosmos relocatable
Browse files Browse the repository at this point in the history
  • Loading branch information
mochaaP committed Nov 14, 2024
1 parent afa663b commit 5abf54e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions build
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
#!/bin/sh -e

if ! command -v cosmocc > /dev/null
COSMOS="${COSMOS:-/opt/cosmos}"
if ! [ -d "${COSMOS}" ] && ! [ -f "${COSMOS}/bin/cosmocc" ]
then
echo "You need to add cosmopolitan toolchain to your path:"
echo "export PATH=\$PATH:<path-to-cosmopolitan>/bin"
exit 1
fi
if ! command -v cosmocc >/dev/null
then
echo "You need to add cosmopolitan toolchain to your environment variable:"
echo "export COSMOS=/opt/cosmos"
exit 1
fi

COSMO_HOME=$(dirname $(dirname $(which cosmocc)))
COSMOS="$(dirname "$(dirname "$(command -v cosmocc)")")"
fi
export COSMOS

FLAGS="-I deps/sokol \
-I deps/cimgui \
-mcosmo \
-mtiny \
-Wall \
-Werror"
-Werror \
-O2"

LINUX_FLAGS="${FLAGS} -Ishims/linux"

WIN32_FLAGS="${FLAGS} -Ishims/win32 -I ${COSMO_HOME}/include/libc/nt"
WIN32_FLAGS="${FLAGS} -Ishims/win32 -I${COSMOS}/include/libc/nt"

mkdir -p .build
mkdir -p bin
Expand Down Expand Up @@ -55,7 +61,7 @@ else
PARALLEL_FLAGS="--progress"
fi

cat .build/commands | parallel $PARALLEL_FLAGS --max-procs $(nproc)
parallel $PARALLEL_FLAGS --max-procs "$(nproc)" :::: .build/commands

objects=$(find .build -name '*.o' -not -path '*.aarch64/*')
cosmoc++ ${FLAGS} -o bin/cosmo-sokol $objects
objects="$(find .build -name '*.o' -not -path '*.aarch64/*')"
"$COSMOS"/bin/cosmoc++ ${FLAGS} -o bin/cosmo-sokol $objects
4 changes: 2 additions & 2 deletions scripts/compile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ then
mkdir -p $(dirname "$object")
case "$source" in
*.c)
exec cosmocc $flags -c "$source" -o "$object"
exec $COSMOS/bin/cosmocc $flags -c "$source" -o "$object"
;;
*.cpp)
exec cosmoc++ $flags -c "$source" -o "$object"
exec $COSMOS/bin/cosmoc++ $flags -c "$source" -o "$object"
;;
*)
echo "Cannot compile $source"
Expand Down

0 comments on commit 5abf54e

Please sign in to comment.