Source

omy / OMyExternal2

# ==========================
# OMyExternal 
# ==========================
# Functions to integrate non-OMake projects

#| The prefix. Equal to the PREFIX environment variable
try
  PREFIX=$(getenv PREFIX)
default
  eprintln(Specify PREFIX environment variable.)
  exit 1 

#| Directories 
BUILD_DIR=_build
SOURCES_DIR=sources
DOWNLOADED_DIR=_downloaded

# Gggg need "declarations"
SOURCEPATHS[]=
REQUIRED_PACKS[]=
REQUIRED_FILES[]=

#| OCamlExternalPack(package)
#    Final goal: installed/$(package), md5 of files in site-lib/$(package)
#    Source: files in sources dir and _downloaded dir

# Downloading
# ============================

#| Run wget and retrieve $(url) to $(dir)
#  If the file is already downloaded, does nothing.
WGet(url, dir) =
    arc=$(basename $(url))
    dst=$(dir)$(DIRSEP)$(arc)
    # eprintln(RULE $(dst) : wget $(url))
    mkdir_if_not_exists($(dir))
    $(dst):
        if $(test -e $(dst))
          touch $(dst)
        else
          wget --no-check-certificate -O $(dst).tmp $(url); mv $(dst).tmp $(dst) # Damn it, ocamlcore.org!
    return $(dst)

#| Download dependency of a path/url.
DependPATH(file) =
    base=$(basename $(file))
    if $(is_url $(file))
        WGet($(file), $(DOWNLOADED_DIR))
        SOURCEPATHS+=$(DOWNLOADED_DIR)$(DIRSEP)$(base)        
        export        
    else
        SOURCEPATHS+=$(SOURCES_DIR)$(DIRSEP)$(base)
    export

# Files
# ============================

#| List up files in directory $(dir), without the prefix "$(dir)/"
Files(dir) =
    return $(removeprefix $(dir)/, $(find $(dir) -f {}))
    
#| Get the OCaml module paths from OCaml object and interface file names: x.cmo, y.cmx => x, y
OCamlModulesFromPath(files)=
    return $(set $(removesuffix $(filter %.cmi %.cmo %.cmx, $(files))))

# Functions for `External` projects
# ============================

#| SOURCES
OCamlExternalPack2(PACKS) =

    .PHONY: very-clean
    clean:
        rm -rf $(BUILD_DIR)

    installed=$(addprefix $(INSTALLED)/, $(PACKS))
    foreach(x, $(SOURCES))
        DependPATH($(x))
        export

    $(installed): $(SOURCEPATHS) $(Installed ocaml $(REQUIRED_PACKS)) $(REQUIRED_FILES)
        # CR jfuruse: todo: clear _build
	pwd
        mkdir_if_not_exists($(BUILD_DIR))
        ocamlfind remove $(PACKS)
        cd $(BUILD_DIR); ../install.sh
        cd $(BUILD_DIR); spotinstall $(PACKS)
	foreach(x, $(PACKS))
            CreateInstalled($(x), $(find $(OCAMLFIND_DESTDIR)$(DIRSEP)$(x) -f {}))

    install: $(installed)

    export

OCamlExternalTool(PATHS) =

    .PHONY: very-clean
    clean:
        rm -rf $(BUILD_DIR)

    foreach(x, $(SOURCES))
        DependPATH($(x))
        export

    $(PATHS): $(SOURCEPATHS) $(Installed $(REQUIRED_PACKS)) $(REQUIRED_FILES)
        # CR jfuruse: todo: clear _build
        mkdir_if_not_exists($(BUILD_DIR))
        cd $(BUILD_DIR); ../install.sh

    install: $(PATH)

    export

#| Returns true if $(file) has ://
is_url(file) =
  match $(file)
  case $'://'
    return true
  default
    return false
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.