got ninja system working

This commit is contained in:
2025-09-03 16:36:18 +02:00
parent 87e845cee5
commit 39c10018d6
2 changed files with 54 additions and 17 deletions

59
configure vendored
View File

@@ -6,6 +6,8 @@ OCAMLDEP=ocamldep
OCAMLC_ARGS= OCAMLC_ARGS=
OCAMLDEP_ARGS=-bytecode OCAMLDEP_ARGS=-bytecode
OBJEXT=cmo OBJEXT=cmo
OCAMLLD=ocamlc
OCAMLLD_ARGS=
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
@@ -26,6 +28,8 @@ while [[ $# -gt 0 ]]; do
echo " OCAMLDEP = $OCAMLDEP" echo " OCAMLDEP = $OCAMLDEP"
echo " OCAMLC_ARGS = $OCAMLC_ARGS" echo " OCAMLC_ARGS = $OCAMLC_ARGS"
echo " OCAMLDEP_ARGS = $OCAMLDEP_ARGS" echo " OCAMLDEP_ARGS = $OCAMLDEP_ARGS"
echo " OCAMLLD = $OCAMLLD"
echo " OCAMLLD_ARGS = $OCAMLLD_ARGS"
exit 0 exit 0
;; ;;
@@ -38,7 +42,7 @@ done
mkdir -p build mkdir -p build
echo '# generated from ../configure echo '# generated by ../configure
OCAMLDEP=$1 OCAMLDEP=$1
shift shift
echo ninja_dyndep_version = 1 echo ninja_dyndep_version = 1
@@ -53,6 +57,45 @@ $OCAMLDEP -one-line $@ | while read d; do
done done
' > build/deps.sh ' > build/deps.sh
echo "# generated by ../configure" > build/invokeld.sh
echo "OCAMLDEP=\"$OCAMLDEP\"" >> build/invokeld.sh
echo "OCAMLDEP_ARGS=\"$OCAMLDEP_ARGS\"" >> build/invokeld.sh
echo "OCAMLLD=\"$OCAMLLD\"" >> build/invokeld.sh
echo "OCAMLLD_ARGS=\"$OCAMLLD_ARGS\"" >> build/invokeld.sh
echo "OBJEXT=\"$OBJEXT\"" >> build/invokeld.sh
echo '
set -e
got=""
get() {
set -e
got+=" $1"
deps="$($OCAMLDEP $OCAMLDEP_ARGS -one-line -bytecode $1.ml | cut -d":" -f2)"
fixdeps=""
for dep in $deps; do
dep="$(basename $dep .cmi)"
if ! [ $dep = $1 ]; then
fixdeps+=" $dep"
fi
done
for dep in $fixdeps; do
echo "$dep $1"
done
for dep in $fixdeps; do
if ! [[ " $got " =~ " $dep " ]]; then
get "$dep"
fi
done
}
files=""
for dep in $(get "$(basename $1 .ml)" | tsort); do
files+=" build/$dep.$OBJEXT"
done
shift
$OCAMLLD $files $OCAMLLD_ARGS $@
' >> build/invokeld.sh
if ! [ -f project ]; then if ! [ -f project ]; then
touch project touch project
echo "# ocaml project description" >> project echo "# ocaml project description" >> project
@@ -60,7 +103,7 @@ if ! [ -f project ]; then
echo "#" >> project echo "#" >> project
echo "# functions:" >> project echo "# functions:" >> project
echo "# application [name]" >> project echo "# application [name]" >> project
echo "# create module from \$name.ml" >> project echo "# create module from \$name.ml, which will be linked with it's dependencies to an executable" >> project
echo "#" >> project echo "#" >> project
echo "# module [name]" >> project echo "# module [name]" >> project
echo "# create module from \$name.ml and \$name.mli" >> project echo "# create module from \$name.ml and \$name.mli" >> project
@@ -92,11 +135,14 @@ touch build.ninja
echo "rule regen" >> build.ninja echo "rule regen" >> build.ninja
echo " command = ./configure $args" >> build.ninja echo " command = ./configure $args" >> build.ninja
echo " generator = 1" >> build.ninja echo " generator = 1" >> build.ninja
echo "build build.ninja | build/deps.sh: regen | configure $project_files" >> build.ninja echo "build build.ninja | build/deps.sh build/invokeld.sh : regen | configure $project_files" >> build.ninja
echo "" >> build.ninja echo "" >> build.ninja
echo "rule ocamlc" >> build.ninja echo "rule ocamlc" >> build.ninja
echo " command = $OCAMLC $OCAMLC_ARGS -nocwd -I build -c \$in -o \$out" >> build.ninja echo " command = $OCAMLC $OCAMLC_ARGS -nocwd -I build -c \$in -o \$out" >> build.ninja
echo "" >> build.ninja echo "" >> build.ninja
echo "rule ocamlld" >> build.ninja
echo " command = bash build/invokeld.sh \$in -o \$out" >> build.ninja
echo "" >> build.ninja
echo "rule ocamldep" >> build.ninja echo "rule ocamldep" >> build.ninja
echo " command = sh build/deps.sh $OCAMLDEP $OCAMLDEP_ARGS \$in > \$out" >> build.ninja echo " command = sh build/deps.sh $OCAMLDEP $OCAMLDEP_ARGS \$in > \$out" >> build.ninja
@@ -110,8 +156,11 @@ module() {
} }
application() { application() {
echo > /dev/null echo "" >> build.ninja
# TODO echo "build build/$1.dd : ocamldep $1.ml || build/deps.sh" >> build.ninja
echo "build build/$1.$OBJEXT | build/$1.cmi : ocamlc $1.ml || build/$1.dd" >> build.ninja
echo " dyndep = build/$1.dd" >> build.ninja
echo "build build/$1 : ocamlld $1.ml | build/$1.$OBJEXT || build/invokeld.sh" >> build.ninja
} }
include() { include() {

12
deps.sh
View File

@@ -1,12 +0,0 @@
OCAMLDEP=$1
shift
echo ninja_dyndep_version = 1
$OCAMLDEP -one-line $@ | while read d; do
outs="$(echo "$d" | cut -d':' -f1)"
ins="$(echo "$d" | cut -d':' -f2)"
echo -ne "build build/$outs : dyndep |"
for f in $ins; do
echo -ne " build/$f"
done
echo
done