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 ad1c3d9 commit ee4324e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ CompileFlags:
- -std=c11
- -Ideps/sokol
- -Ideps/cimgui
- -Invapi
- -D_COSMO_SOURCE
- -I/opt/cosmos/include
- -include libc/integral/normalize.inc
22 changes: 8 additions & 14 deletions build
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
#!/bin/sh -e

if ! command -v cosmocc > /dev/null
then
echo "You need to add cosmopolitan toolchain to your path:"
echo "export PATH=\$PATH:<path-to-cosmopolitan>/bin"
exit 1
fi

COSMO_HOME=$(dirname $(dirname $(which cosmocc)))
export COSMO="${COSMO:-/opt/cosmo}"
export COSMOS="${COSMOS:-/opt/cosmos}"

FLAGS="-I deps/sokol \
-I deps/cimgui \
-mcosmo \
-mtiny \
-g -ggdb \
-Wall \
-Werror"
-Wpedantic"

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 +49,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 ee4324e

Please sign in to comment.