From a1d46a7ddd96cf800b5fe1409b83ef8e89e7882c Mon Sep 17 00:00:00 2001 From: Douglas Mencken Date: Sat, 31 Mar 2018 08:05:44 -0400 Subject: [PATCH 1/9] not every platform has ocamlopt suddenly obuild has no support for bytecode-only platforms this commit is the first step to have such support --- bootstrap-bytecode | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 bootstrap-bytecode diff --git a/bootstrap-bytecode b/bootstrap-bytecode new file mode 100755 index 0000000..382eefc --- /dev/null +++ b/bootstrap-bytecode @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +libs="unix.cma" + +OCAMLVER=`ocamlc -version` +echo $OCAMLVER + +rm -f ext/compat.ml +if [[ $OCAMLVER < "4.02.0" ]] ; then + echo "Using compat401.ml" + cp -f compat401.ml ext/compat.ml +else + echo "Using compat402.ml" + cp -f compat402.ml ext/compat.ml +fi + +extmodules="compat fugue filepath filesystem" +libmodules="types gconf filetype dag libname pp expr utils modname taskdep helper dagutils process findlibConf scheduler prog dependencies generators hier meta metacache target dist project analyze configure prepare buildprogs build exception" +mainmodules="sdist doc init help install path_generated main" + +set -e + +######################################################################## +######################################################################## +######################################################################## +# build ext +cd ext +rm -f *.cmi *.cmo *.o +APPEND="" +for mod in $extmodules +do + echo "COMPILING $mod" + [ -f ${mod}.mli ] && ocamlc -for-pack Ext -c ${mod}.mli + ocamlc -for-pack Ext -c ${mod}.ml + APPEND+="ext/${mod}.cmo " +done; +cd .. +echo "BUILDING library Ext.cmo" +ocamlc -pack -o Ext.cmo -I ext/ $APPEND + +######################################################################## +######################################################################## +######################################################################## +# build the library +cd obuild +rm -f *.cmi *.cmo *.o + +APPEND="" +for mod in $libmodules +do + echo "COMPILING $mod" + [ -f ${mod}.mli ] && ocamlc -for-pack Obuild -I ../ -c ${mod}.mli + ocamlc -for-pack Obuild -I ../ -c ${mod}.ml + APPEND+="obuild/${mod}.cmo " +done; +cd .. +echo "BUILDING library Obuild.cmo" +ocamlc -pack -o Obuild.cmo -I ext/ $APPEND + +# then bootstrap the main executable +# main needs the version number + +cat < src/path_generated.ml + +(* autogenerated file by bootstrap. do not modify *) + +let project_version = "0.0.0" + +EOF +cd src +APPEND="" +for mod in $mainmodules +do + echo "COMPILING $mod" + [ -f ${mod}.mli ] && ocamlc -I ../ -c ${mod}.mli + ocamlc -I ../ -c ${mod}.ml + APPEND+="${mod}.cmo " +done +echo "LINKING obuild.bootstrap" +ocamlc -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND +cd .. + +rm -f obuild/*.cmi obuild/*.cmo obuild/*.o +rm -f src/*.cmi src/*.cmo src/*.o +rm -f *.cmi *.o *a *.cmo +rm -f src/path_generated.ml + +######################################################################## +######################################################################## +######################################################################## + +# rebuild everything with the bootstraped version +export OCAMLRUNPARAM=b +./obuild.bootstrap clean +./obuild.bootstrap configure +time ./obuild.bootstrap build +if [ -x dist/build/obuild/obuild ]; then + rm obuild.bootstrap +fi From 3e25f6998b18fbe8f00ae4e01bb787a1c7fd7567 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Sat, 19 May 2018 23:38:09 +0800 Subject: [PATCH 2/9] Get OCaml config from ocamlc. Instead of from ocamlopt, which doesn't exist in bytecode-only platforms. --- obuild/prog.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obuild/prog.ml b/obuild/prog.ml index de13b8f..cc93621 100644 --- a/obuild/prog.ml +++ b/obuild/prog.ml @@ -60,7 +60,7 @@ let ocaml_config = ref None let getOcamlConfig () = match !ocaml_config with | None -> - (match Process.run [ getOcamlOpt (); "-config" ] with + (match Process.run [ getOcamlC (); "-config" ] with | Process.Success (s,_,_) -> let lines = string_lines_noempty s in let h = Hashtbl.create 32 in From 7a14c4d941e9c4646ebf55da5b2740f715864958 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Sat, 19 May 2018 23:38:55 +0800 Subject: [PATCH 3/9] enable only bytecode in bootstrap-bytecode --- bootstrap-bytecode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-bytecode b/bootstrap-bytecode index 382eefc..540143e 100755 --- a/bootstrap-bytecode +++ b/bootstrap-bytecode @@ -92,7 +92,7 @@ rm -f src/path_generated.ml # rebuild everything with the bootstraped version export OCAMLRUNPARAM=b ./obuild.bootstrap clean -./obuild.bootstrap configure +./obuild.bootstrap configure --disable-executable-native --disable-library-native --disable-library-plugin --enable-executable-bytecode --enable-library-bytecode time ./obuild.bootstrap build if [ -x dist/build/obuild/obuild ]; then rm obuild.bootstrap From 02c9be18eca94c554ebed2affdb6c72fc601bd0f Mon Sep 17 00:00:00 2001 From: Andy Li Date: Mon, 21 May 2018 10:13:39 +0800 Subject: [PATCH 4/9] replace bootstrap with bootstrap-bytecode --- bootstrap | 54 +++++++++++-------------- bootstrap-bytecode | 99 ---------------------------------------------- 2 files changed, 23 insertions(+), 130 deletions(-) delete mode 100755 bootstrap-bytecode diff --git a/bootstrap b/bootstrap index 8411cd4..540143e 100755 --- a/bootstrap +++ b/bootstrap @@ -1,13 +1,8 @@ #!/usr/bin/env bash -libs="unix.cmxa" -OCAMLOPT="ocamlopt -g" -# use faster ocamlopt, if available -OCAMLOPT_OPT=`which ocamlopt.opt` -if [[ $OCAMLOPT_OPT != "" ]] ; then - OCAMLOPT="ocamlopt.opt -g" -fi -OCAMLVER=`$OCAMLOPT -vnum` +libs="unix.cma" + +OCAMLVER=`ocamlc -version` echo $OCAMLVER rm -f ext/compat.ml @@ -30,40 +25,37 @@ set -e ######################################################################## # build ext cd ext -rm -f *.cmi *.cmx *.o +rm -f *.cmi *.cmo *.o APPEND="" for mod in $extmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLOPT -for-pack Ext -c ${mod}.mli - $OCAMLOPT -for-pack Ext -c ${mod}.ml - APPEND+="ext/${mod}.cmx " + [ -f ${mod}.mli ] && ocamlc -for-pack Ext -c ${mod}.mli + ocamlc -for-pack Ext -c ${mod}.ml + APPEND+="ext/${mod}.cmo " done; cd .. - -echo "BUILDING library obuild_ext.cmxa" -$OCAMLOPT -pack -o ext.cmx -I ext/ $APPEND -$OCAMLOPT -a -o obuild_ext.cmxa ext.cmx +echo "BUILDING library Ext.cmo" +ocamlc -pack -o Ext.cmo -I ext/ $APPEND ######################################################################## ######################################################################## ######################################################################## # build the library cd obuild -rm -f *.cmi *.cmx *.o +rm -f *.cmi *.cmo *.o APPEND="" for mod in $libmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLOPT -for-pack Obuild -I ../ -c ${mod}.mli - $OCAMLOPT -for-pack Obuild -I ../ -c ${mod}.ml - APPEND+="obuild/${mod}.cmx " + [ -f ${mod}.mli ] && ocamlc -for-pack Obuild -I ../ -c ${mod}.mli + ocamlc -for-pack Obuild -I ../ -c ${mod}.ml + APPEND+="obuild/${mod}.cmo " done; cd .. -echo "BUILDING library obuild.cmxa" -$OCAMLOPT -pack -o obuild.cmx -I ext/ $APPEND -$OCAMLOPT -a -o obuild.cmxa obuild.cmx +echo "BUILDING library Obuild.cmo" +ocamlc -pack -o Obuild.cmo -I ext/ $APPEND # then bootstrap the main executable # main needs the version number @@ -80,17 +72,17 @@ APPEND="" for mod in $mainmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLOPT -I ../ -c ${mod}.mli - $OCAMLOPT -I ../ -c ${mod}.ml - APPEND+="${mod}.cmx " + [ -f ${mod}.mli ] && ocamlc -I ../ -c ${mod}.mli + ocamlc -I ../ -c ${mod}.ml + APPEND+="${mod}.cmo " done echo "LINKING obuild.bootstrap" -$OCAMLOPT -o ../obuild.bootstrap -I ../ ${libs} obuild_ext.cmxa obuild.cmxa $APPEND +ocamlc -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND cd .. -rm -f obuild/*.cmi obuild/*.cmx obuild/*.o -rm -f src/*.cmi src/*.cmx src/*.o -rm -f *.cmi *.o *a *.cmx *.cmxa +rm -f obuild/*.cmi obuild/*.cmo obuild/*.o +rm -f src/*.cmi src/*.cmo src/*.o +rm -f *.cmi *.o *a *.cmo rm -f src/path_generated.ml ######################################################################## @@ -100,7 +92,7 @@ rm -f src/path_generated.ml # rebuild everything with the bootstraped version export OCAMLRUNPARAM=b ./obuild.bootstrap clean -./obuild.bootstrap configure +./obuild.bootstrap configure --disable-executable-native --disable-library-native --disable-library-plugin --enable-executable-bytecode --enable-library-bytecode time ./obuild.bootstrap build if [ -x dist/build/obuild/obuild ]; then rm obuild.bootstrap diff --git a/bootstrap-bytecode b/bootstrap-bytecode deleted file mode 100755 index 540143e..0000000 --- a/bootstrap-bytecode +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env bash - -libs="unix.cma" - -OCAMLVER=`ocamlc -version` -echo $OCAMLVER - -rm -f ext/compat.ml -if [[ $OCAMLVER < "4.02.0" ]] ; then - echo "Using compat401.ml" - cp -f compat401.ml ext/compat.ml -else - echo "Using compat402.ml" - cp -f compat402.ml ext/compat.ml -fi - -extmodules="compat fugue filepath filesystem" -libmodules="types gconf filetype dag libname pp expr utils modname taskdep helper dagutils process findlibConf scheduler prog dependencies generators hier meta metacache target dist project analyze configure prepare buildprogs build exception" -mainmodules="sdist doc init help install path_generated main" - -set -e - -######################################################################## -######################################################################## -######################################################################## -# build ext -cd ext -rm -f *.cmi *.cmo *.o -APPEND="" -for mod in $extmodules -do - echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -for-pack Ext -c ${mod}.mli - ocamlc -for-pack Ext -c ${mod}.ml - APPEND+="ext/${mod}.cmo " -done; -cd .. -echo "BUILDING library Ext.cmo" -ocamlc -pack -o Ext.cmo -I ext/ $APPEND - -######################################################################## -######################################################################## -######################################################################## -# build the library -cd obuild -rm -f *.cmi *.cmo *.o - -APPEND="" -for mod in $libmodules -do - echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -for-pack Obuild -I ../ -c ${mod}.mli - ocamlc -for-pack Obuild -I ../ -c ${mod}.ml - APPEND+="obuild/${mod}.cmo " -done; -cd .. -echo "BUILDING library Obuild.cmo" -ocamlc -pack -o Obuild.cmo -I ext/ $APPEND - -# then bootstrap the main executable -# main needs the version number - -cat < src/path_generated.ml - -(* autogenerated file by bootstrap. do not modify *) - -let project_version = "0.0.0" - -EOF -cd src -APPEND="" -for mod in $mainmodules -do - echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -I ../ -c ${mod}.mli - ocamlc -I ../ -c ${mod}.ml - APPEND+="${mod}.cmo " -done -echo "LINKING obuild.bootstrap" -ocamlc -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND -cd .. - -rm -f obuild/*.cmi obuild/*.cmo obuild/*.o -rm -f src/*.cmi src/*.cmo src/*.o -rm -f *.cmi *.o *a *.cmo -rm -f src/path_generated.ml - -######################################################################## -######################################################################## -######################################################################## - -# rebuild everything with the bootstraped version -export OCAMLRUNPARAM=b -./obuild.bootstrap clean -./obuild.bootstrap configure --disable-executable-native --disable-library-native --disable-library-plugin --enable-executable-bytecode --enable-library-bytecode -time ./obuild.bootstrap build -if [ -x dist/build/obuild/obuild ]; then - rm obuild.bootstrap -fi From 092337f9a3a02ea76450a0d04e2c9668257fa558 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Mon, 21 May 2018 11:05:29 +0800 Subject: [PATCH 5/9] bootstrap: use default config when ocamlopt is available --- bootstrap | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bootstrap b/bootstrap index 540143e..bd98abb 100755 --- a/bootstrap +++ b/bootstrap @@ -92,7 +92,16 @@ rm -f src/path_generated.ml # rebuild everything with the bootstraped version export OCAMLRUNPARAM=b ./obuild.bootstrap clean -./obuild.bootstrap configure --disable-executable-native --disable-library-native --disable-library-plugin --enable-executable-bytecode --enable-library-bytecode +if [ -x "$(command -v ocamlopt)" ]; then + ./obuild.bootstrap configure +else + ./obuild.bootstrap configure \ + --disable-executable-native \ + --disable-library-native \ + --disable-library-plugin \ + --enable-executable-bytecode \ + --enable-library-bytecode +fi time ./obuild.bootstrap build if [ -x dist/build/obuild/obuild ]; then rm obuild.bootstrap From 87045a49fc1dc9650356282f6b3ca55558a2f470 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Mon, 21 May 2018 11:10:42 +0800 Subject: [PATCH 6/9] bootstrap: use `-g` as the original bootstrap --- bootstrap | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bootstrap b/bootstrap index bd98abb..8f211bb 100755 --- a/bootstrap +++ b/bootstrap @@ -2,7 +2,8 @@ libs="unix.cma" -OCAMLVER=`ocamlc -version` +OCAMLC="ocamlc -g" +OCAMLVER=`$OCAMLC -version` echo $OCAMLVER rm -f ext/compat.ml @@ -30,13 +31,13 @@ APPEND="" for mod in $extmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -for-pack Ext -c ${mod}.mli - ocamlc -for-pack Ext -c ${mod}.ml + [ -f ${mod}.mli ] && $OCAMLC -for-pack Ext -c ${mod}.mli + $OCAMLC -for-pack Ext -c ${mod}.ml APPEND+="ext/${mod}.cmo " done; cd .. echo "BUILDING library Ext.cmo" -ocamlc -pack -o Ext.cmo -I ext/ $APPEND +$OCAMLC -pack -o Ext.cmo -I ext/ $APPEND ######################################################################## ######################################################################## @@ -49,13 +50,13 @@ APPEND="" for mod in $libmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -for-pack Obuild -I ../ -c ${mod}.mli - ocamlc -for-pack Obuild -I ../ -c ${mod}.ml + [ -f ${mod}.mli ] && $OCAMLC -for-pack Obuild -I ../ -c ${mod}.mli + $OCAMLC -for-pack Obuild -I ../ -c ${mod}.ml APPEND+="obuild/${mod}.cmo " done; cd .. echo "BUILDING library Obuild.cmo" -ocamlc -pack -o Obuild.cmo -I ext/ $APPEND +$OCAMLC -pack -o Obuild.cmo -I ext/ $APPEND # then bootstrap the main executable # main needs the version number @@ -72,12 +73,12 @@ APPEND="" for mod in $mainmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && ocamlc -I ../ -c ${mod}.mli - ocamlc -I ../ -c ${mod}.ml + [ -f ${mod}.mli ] && $OCAMLC -I ../ -c ${mod}.mli + $OCAMLC -I ../ -c ${mod}.ml APPEND+="${mod}.cmo " done echo "LINKING obuild.bootstrap" -ocamlc -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND +$OCAMLC -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND cd .. rm -f obuild/*.cmi obuild/*.cmo obuild/*.o @@ -103,6 +104,6 @@ else --enable-library-bytecode fi time ./obuild.bootstrap build -if [ -x dist/build/obuild/obuild ]; then +if [ -x dist/build/obuild/obuild ] || [ -x dist/build/obuild/obuild.byte ]; then rm obuild.bootstrap fi From c64238785cad037fa51706eee8b2938224282aa2 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Mon, 21 May 2018 11:23:28 +0800 Subject: [PATCH 7/9] bootstrap: make the binary names consistent such that opam install works --- bootstrap | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bootstrap b/bootstrap index 8f211bb..ee1442f 100755 --- a/bootstrap +++ b/bootstrap @@ -95,6 +95,7 @@ export OCAMLRUNPARAM=b ./obuild.bootstrap clean if [ -x "$(command -v ocamlopt)" ]; then ./obuild.bootstrap configure + time ./obuild.bootstrap build else ./obuild.bootstrap configure \ --disable-executable-native \ @@ -102,8 +103,10 @@ else --disable-library-plugin \ --enable-executable-bytecode \ --enable-library-bytecode + time ./obuild.bootstrap build + mv dist/build/obuild/obuild.byte dist/build/obuild/obuild + mv dist/build/obuild-simple/obuild-simple.byte dist/build/obuild-simple/obuild-simple fi -time ./obuild.bootstrap build -if [ -x dist/build/obuild/obuild ] || [ -x dist/build/obuild/obuild.byte ]; then +if [ -x dist/build/obuild/obuild ]; then rm obuild.bootstrap fi From 8f104092f778e38fd76553d9451a88af8bca32c4 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Mon, 21 May 2018 11:59:31 +0800 Subject: [PATCH 8/9] shellcheck bootstrap --- bootstrap | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bootstrap b/bootstrap index ee1442f..9c75978 100755 --- a/bootstrap +++ b/bootstrap @@ -3,8 +3,8 @@ libs="unix.cma" OCAMLC="ocamlc -g" -OCAMLVER=`$OCAMLC -version` -echo $OCAMLVER +OCAMLVER=$($OCAMLC -version) +echo "$OCAMLVER" rm -f ext/compat.ml if [[ $OCAMLVER < "4.02.0" ]] ; then @@ -26,37 +26,37 @@ set -e ######################################################################## # build ext cd ext -rm -f *.cmi *.cmo *.o -APPEND="" +rm -f ./*.cmi ./*.cmo ./*.o +FILES=() for mod in $extmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLC -for-pack Ext -c ${mod}.mli - $OCAMLC -for-pack Ext -c ${mod}.ml - APPEND+="ext/${mod}.cmo " + [ -f "${mod}.mli" ] && $OCAMLC -for-pack Ext -c "${mod}.mli" + $OCAMLC -for-pack Ext -c "${mod}.ml" + FILES+=("ext/${mod}.cmo") done; cd .. echo "BUILDING library Ext.cmo" -$OCAMLC -pack -o Ext.cmo -I ext/ $APPEND +$OCAMLC -pack -o Ext.cmo -I ext/ "${FILES[@]}" ######################################################################## ######################################################################## ######################################################################## # build the library cd obuild -rm -f *.cmi *.cmo *.o +rm -f ./*.cmi ./*.cmo ./*.o -APPEND="" +FILES=() for mod in $libmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLC -for-pack Obuild -I ../ -c ${mod}.mli - $OCAMLC -for-pack Obuild -I ../ -c ${mod}.ml - APPEND+="obuild/${mod}.cmo " + [ -f "${mod}.mli" ] && $OCAMLC -for-pack Obuild -I ../ -c "${mod}.mli" + $OCAMLC -for-pack Obuild -I ../ -c "${mod}.ml" + FILES+=("obuild/${mod}.cmo") done; cd .. echo "BUILDING library Obuild.cmo" -$OCAMLC -pack -o Obuild.cmo -I ext/ $APPEND +$OCAMLC -pack -o Obuild.cmo -I ext/ "${FILES[@]}" # then bootstrap the main executable # main needs the version number @@ -69,21 +69,21 @@ let project_version = "0.0.0" EOF cd src -APPEND="" +FILES=() for mod in $mainmodules do echo "COMPILING $mod" - [ -f ${mod}.mli ] && $OCAMLC -I ../ -c ${mod}.mli - $OCAMLC -I ../ -c ${mod}.ml - APPEND+="${mod}.cmo " + [ -f "${mod}.mli" ] && $OCAMLC -I ../ -c "${mod}.mli" + $OCAMLC -I ../ -c "${mod}.ml" + FILES+=("${mod}.cmo") done echo "LINKING obuild.bootstrap" -$OCAMLC -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo $APPEND +$OCAMLC -o ../obuild.bootstrap -I ../ ${libs} Ext.cmo Obuild.cmo "${FILES[@]}" cd .. rm -f obuild/*.cmi obuild/*.cmo obuild/*.o rm -f src/*.cmi src/*.cmo src/*.o -rm -f *.cmi *.o *a *.cmo +rm -f ./*.cmi ./*.o ./*a ./*.cmo rm -f src/path_generated.ml ######################################################################## From f047fcd7a346e2fe337dbce90481d2b2d2824737 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Tue, 22 May 2018 23:24:33 +0800 Subject: [PATCH 9/9] fix getOcamlConfig() error message --- obuild/prog.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obuild/prog.ml b/obuild/prog.ml index cc93621..9df4977 100644 --- a/obuild/prog.ml +++ b/obuild/prog.ml @@ -70,7 +70,7 @@ let getOcamlConfig () = ) lines; ocaml_config := Some h; h - | Process.Failure err -> raise (OCamlProgramError ("ocamlopt cannot get config " ^ err))) + | Process.Failure err -> raise (OCamlProgramError ("ocamlc cannot get config " ^ err))) | Some h -> h let getCamlp4Config () =