123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264(******************************************************************************)(* OASIS: architecture for building OCaml libraries and applications *)(* *)(* Copyright (C) 2011-2016, Sylvain Le Gall *)(* Copyright (C) 2008-2011, OCamlCore SARL *)(* *)(* This library is free software; you can redistribute it and/or modify it *)(* under the terms of the GNU Lesser General Public License as published by *)(* the Free Software Foundation; either version 2.1 of the License, or (at *)(* your option) any later version, with the OCaml static compilation *)(* exception. *)(* *)(* This library is distributed in the hope that it will be useful, but *)(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more *)(* details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this library; if not, write to the Free Software Foundation, *)(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)(******************************************************************************)(** Generate standard development files
@author Sylvain Le Gall
*)openOASISFileTemplateopenOASISGettextopenOASISTypesopenOASISPluginopenOASISSchemaletplugin=`Extra,"DevFiles",SomeOASISConf.version_shortletself_id,all_id=Extra.createpluginletall_targets=["build";"doc";"test";"all";"install";"uninstall";"reinstall";"clean";"distclean";"configure";]typet={makefile_notargets:stringlist;enable_makefile:bool;enable_configure:bool;}letpivot_data=data_new_propertypluginletgenerator=letmakefile_notargets=new_fieldOASISPackage.schemaall_id"MakefileNoTargets"~default:[](OASISValues.comma_separated(OASISValues.choices(fun_->s_"target")(List.rev_map(funs->s,s)all_targets)))(fun()->s_"Targets to disable when generating Makefile")pivot_data(fun_t->t.makefile_notargets)inletenable_makefile=new_fieldOASISPackage.schemaall_id"EnableMakefile"~default:trueOASISValues.boolean(fun()->s_"Generate Makefile")pivot_data(fun_t->t.enable_makefile)inletenable_configure=new_fieldOASISPackage.schemaall_id"EnableConfigure"~default:trueOASISValues.boolean(fun()->s_"Generate configure script")pivot_data(fun_t->t.enable_configure)in(fundata->{makefile_notargets=makefile_notargetsdata;enable_makefile=enable_makefiledata;enable_configure=enable_configuredata;})letmainctxtpkg=lett=generatorpkg.schema_datainlet(makefile_setup_deps,packages)=matchctxt.updatewith|OASISSetupUpdate.Dynamic->(" _oasis"," -linkpkg -package oasis.dynrun")|OASISSetupUpdate.Weak->(" _oasis","")|OASISSetupUpdate.NoUpdate->("","")inletcompiled_setup_ml=OASISFeatures.package_testOASISFeatures.compiled_setup_mlpkginifcompiled_setup_ml&¬t.enable_makefilethenOASISMessage.error~ctxt:ctxt.ctxt"The alpha feature compiled_setup_ml doesn't work without a Makefile if \
DevFiles in enabled";letctxt=(* Generate Makefile (for standard dev. env.) *)ift.enable_makefilethenbeginletbuff=Buffer.create13inlettargets=letexcludes=OASISUtils.SetString.of_listt.makefile_notargetsinList.filter(funt->not(OASISUtils.SetString.memtexcludes))all_targetsinletadd_one_target?(need_configure=true)?(other_depends=[])nm=letsetup_depsl=ifcompiled_setup_mlthen"$(SETUP)"::lelselinletdeps=String.concat" "((ifneed_configurethen(funl->"setup.data"::setup_depsl)else(funl->setup_depsl))other_depends)inletdeps=ifdeps<>""then" "^depselsedepsinPrintf.bprintfbuff"%s:%s\n\
\t$(SETUP) -%s $(%sFLAGS)\n\n"nmdepsnm(OASISString.uppercase_asciinm)inBuffer.add_stringbuff(ifcompiled_setup_mlthen"\nSETUP = ./setup.exe\n\n"else"\nSETUP = ocaml setup.ml\n\n");List.iter(function|"distclean"whencompiled_setup_ml->Printf.bprintfbuff"distclean: $(SETUP)\n\
\t$(SETUP) -distclean $(DISTCLEANFLAGS)\n\
\t$(RM) $(SETUP)\n\n";|"all"|"clean"|"distclean"asnm->add_one_target~need_configure:falsenm|"test"|"doc"asnm->add_one_target~other_depends:["build"]nm|"configure"->letadd_configure_targetnm=Printf.bprintfbuff"%s:%s\n\
\t$(SETUP) -configure $(CONFIGUREFLAGS)\n\n"nm(ifcompiled_setup_mlthen" $(SETUP)"else"");inadd_configure_target"setup.data";add_configure_target"configure";|nm->add_one_targetnm)targets;ifcompiled_setup_mlthenbeginPrintf.bprintfbuff"setup.exe: setup.ml%s\n\
\tocamlfind ocamlopt -o $@%s setup.ml || ocamlfind ocamlc -o $@%s setup.ml || true\n\
\t$(RM) setup.cmi setup.cmo setup.cmx setup.o setup.cmt\n\n"makefile_setup_depspackagespackages;end;Buffer.add_stringbuff(".PHONY: "^(String.concat" "targets)^"\n");OASISPlugin.add_file{(template_make"Makefile"comment_sh[](OASISString.split_newline~do_trim:false(Buffer.contentsbuff))[])withimportant=true}ctxtendelsectxtinletctxt=(* Generate configure (for standard dev. env.) *)ift.enable_configurethenletocaml_setup_configure=letcmd=ifcompiled_setup_mlthenPrintf.sprintf"if [ ! -e setup.exe ] || [ _oasis -nt setup.exe ] || [ setup.ml -nt setup.exe ] || [ configure -nt setup.exe ]; then\n \
ocamlfind ocamlopt -o setup.exe%s setup.ml || ocamlfind ocamlc -o setup.exe%s setup.ml || exit 1\n \
rm -f setup.cmi setup.cmo setup.cmx setup.o setup.cmt\n\
fi\n\
./setup.exe -configure \"$@\""packagespackageselse"ocaml setup.ml -configure \"$@\""in["";cmd;"# OASIS_STOP"]inbeginlettmpl=template_of_string_list~ctxt:ctxt.OASISPlugin.ctxt~template:true"configure"comment_sh(DevFilesData.configure@ocaml_setup_configure)inOASISPlugin.add_file{tmplwithperm=0o755;important=true}ctxtendelsectxtinctxtletinit()=Extra.register_actself_idmain;register_helpplugin{(help_defaultDevFilesData.readme_template_mkd)withhelp_order=60};register_generator_packageall_idpivot_datagenerator