From 39c10018d639d498538e11ffe12cd2b71ecfbbc8 Mon Sep 17 00:00:00 2001 From: alex-s168 Date: Wed, 3 Sep 2025 16:36:18 +0200 Subject: [PATCH] got ninja system working --- configure | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++----- deps.sh | 12 ----------- 2 files changed, 54 insertions(+), 17 deletions(-) delete mode 100644 deps.sh diff --git a/configure b/configure index b3fd267..15f9e1f 100644 --- a/configure +++ b/configure @@ -6,6 +6,8 @@ OCAMLDEP=ocamldep OCAMLC_ARGS= OCAMLDEP_ARGS=-bytecode OBJEXT=cmo +OCAMLLD=ocamlc +OCAMLLD_ARGS= while [[ $# -gt 0 ]]; do case $1 in @@ -26,6 +28,8 @@ while [[ $# -gt 0 ]]; do echo " OCAMLDEP = $OCAMLDEP" echo " OCAMLC_ARGS = $OCAMLC_ARGS" echo " OCAMLDEP_ARGS = $OCAMLDEP_ARGS" + echo " OCAMLLD = $OCAMLLD" + echo " OCAMLLD_ARGS = $OCAMLLD_ARGS" exit 0 ;; @@ -38,7 +42,7 @@ done mkdir -p build -echo '# generated from ../configure +echo '# generated by ../configure OCAMLDEP=$1 shift echo ninja_dyndep_version = 1 @@ -53,6 +57,45 @@ $OCAMLDEP -one-line $@ | while read d; do done ' > 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 touch project echo "# ocaml project description" >> project @@ -60,7 +103,7 @@ if ! [ -f project ]; then echo "#" >> project echo "# functions:" >> 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 "# module [name]" >> project echo "# create module from \$name.ml and \$name.mli" >> project @@ -92,11 +135,14 @@ touch build.ninja echo "rule regen" >> build.ninja echo " command = ./configure $args" >> 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 "rule ocamlc" >> build.ninja echo " command = $OCAMLC $OCAMLC_ARGS -nocwd -I build -c \$in -o \$out" >> 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 " command = sh build/deps.sh $OCAMLDEP $OCAMLDEP_ARGS \$in > \$out" >> build.ninja @@ -110,8 +156,11 @@ module() { } application() { - echo > /dev/null - # TODO + echo "" >> build.ninja + 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() { diff --git a/deps.sh b/deps.sh deleted file mode 100644 index eb2ffe5..0000000 --- a/deps.sh +++ /dev/null @@ -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