james woodyatt avatar james woodyatt committed 505a1dd

Checkpoint. We are building and installing the Oni findlib package.

Comments (0)

Files changed (5)

 #   sasl    Simple Application Security Layer (SASL)
 #   beep    The BEEP Core and TCP transport profile
 
-### Emphemeral targets
-.PHONY: clean test install remove
-
 ### Verbose warnings
 CC.OBJFLAGS+=-Wall
 CXX.OBJFLAGS+=-Wall
 OCAMLC.OPTIONS+=-w Ae -principal
 OCAMLOPT.OPTIONS+=-w Ae -principal
 
+### The findlib package
+PKG.=
+    NAME=oni
+    VERSION=1.00rc1
+    DESCRIPTION= $"Oni - assorted components for low-level networking"
+PKG=$(OCaml_findlib_package.new $(PKG))
+export PKG
+
 ### Subdirectories
 .SUBDIRS: cf nx
 
+### Compose package
+section
+    PKG.REQUIRES=oni.cf
+    install: $(PKG.install-target)
+    remove: $(PKG.remove-target)
+    
+    clean:
+        rm -rf $(AUXROOT)
+
 # End $File$
 ### Define the project root directory
 public.ROOT= $(dir .)
 
+### Emphemeral targets
+.PHONY: clean test install remove
+
 ### Include OMakefile from top directory
 .SUBDIRS: .
 
     ### Construct the composition unit for the cf library
     unit=$(OCaml_library.new cf, $(src))
     unit.compose($(component))
+    
+    ### Packaging
+    sub.=
+        NAME=cf
+        DESCRIPTION=$"Oni core foundation"
+        ARCHIVES=$(unit.package-archives)
+        REQUIRES=unix
+    PKG=$(PKG.add-subpackage $(sub))
+    PKG.FILES+=$(unit.package-files $(component))
+    export PKG
 
 ### Compose the cf library test
 section
     ### Construct the composition unit for the cf library
     unit=$(OCaml_library.new nx, $(src))
     unit.compose($(M.nx))
+    
+    ### Packaging
+    sub.=
+        NAME=nx
+        DESCRIPTION=$"Oni network extensions"
+        REQUIRES=unix oni.cf
+        ARCHIVES=$(unit.package-archives)
+    PKG=$(PKG.add-subpackage $(sub))
+    PKG.FILES+=$(unit.package-files $(M.nx))
+    export PKG
 
 ### Compose the cf library test
 section

project/lang/OCaml.om

                 export j
                 match $j
                 case $"\.cmi"
-                    if $(defined this.CMIDIR)
+                    if $(this.object-mem CMIDIR)
                         j=$(addprefix $(CMIDIR)/, $j)
                     else
                         j=$(addprefix $d/, $j)
             throw($"OCaml unit has no MLFILES member [$(context)]")
         this.MLFILES=$(file $(src.MLFILES))
         this.MLIFILES[]=
-        if $(defined src.MLIFILES)
+        if $(src.object-mem MLIFILES)
             this.MLIFILES=$(file $(src.MLIFILES))
             export
         this.MLLFILES[]=
         this.MLYFILES[]=
+        if $(src.object-mem MLLFILES)
+            this.MLLFILES=$(file $(src.MLLFILES))
+            export
+        if $(src.object-mem MLYFILES)
+            this.MLYFILES=$(file $(src.MLYFILES))
+            export
         this.PACKAGES[]=
         this.PREDICATES[]=
-        if $(defined src.PACKAGES)
+        if $(src.object-mem PACKAGES)
             this.PACKAGES=$(src.PACKAGES)
-            if $(defined src.PREDICATES)
+            if $(src.object-mem PREDICATES)
                 this.PREDICATES=$(src.PREDICATES)
                 export
             export
             outputs+=$(this.compose-aux $(config), $(cmo), $(cmx), $(dst))
         return $(outputs)
     
+    ### Final configuration
+    protected.final-configuration()=
+        if $(mem release, $(CONFIGURATIONS))
+            return release
+        else
+            return $(nth 0, $(CONFIGURATIONS))
+    
     ### Construct a new composer
     protected.new(name, src, context)=
         src.NAME=$(name)
     protected.source(src, context)=
         this=$(OCaml_unit::source $(src), $(context))
         this.CFILES[]=
-        if $(defined src.CFILES)
+        if $(src.object-mem CFILES)
             this.CFILES=$(src.CFILES)
             export
         return $(this)
     
-    ### Configuration-specific C-language library name
-    protected.specialized-name(config)=
-        if $(equal $(config), $"release")
-            return $(this.NAME)
-        else
-            return $(this.NAME)-$(config)
-    
     ### Auxillary composition method
     protected.compose-aux(config, cmo, cmx, dst)=
         private.outputs=
         private.olibs=
         private.clibs=
         export clibs outputs
-        if $(defined this.CFILES)
-            dst=$(dirname $(dst))
+        if $(this.CFILES)
             private.po=$(this.OCAMLC.c-primitives $(this.CFILES), $(dst))
-            private.name=$(specialized-name $(config))
-            clibs=$(this.OCAMLMKLIB.c-library $(name), $(po), $(dst))
+            clibs=$(this.OCAMLMKLIB.c-library $(this.NAME), $(po), $(dst))
             outputs+=$(clibs)
         olibs=$(this.OCAMLMKLIB.byte-library $(this.NAME), $(cmo), $(dst))
         $(olibs): $(clibs)
         $(c.ck libraries): $(libs)
         
         return $(libs)
+    
+    ### Package files
+    package-files(c)=
+        c=$(OCaml_component.assert $c, $"OCaml_library $(NAME)")
+        private.cdir=$(dir $(c.STAGE.DIR)/$(final-configuration))
+        private.mli=$(basename $(this.MLIFILES))
+        private.cmi=$(replacesuffixes .mli, .cmi, $(mli))
+        private.cmi=$(file $(addprefix $(c.STAGE.DIR)/, $(cmi)))
+        private.ml=$(basename $(this.MLFILES))
+        private.cmx=$(replacesuffixes .ml, .cmx, $(ml))
+        private.cmx=$(file $(addprefix $(cdir)/, $(cmx)))
+        private.libs=$(addprefix $(this.NAME), .cma .cmxa .a)
+        export libs
+        if $(this.CFILES)
+            libs+=dll$(this.NAME).so lib$(this.NAME).a
+        libs=$(file $(addprefix $(cdir)/, $(libs)))
+        return $(this.MLIFILES) $(cmi) $(cmx) $(libs)
+    
+    ### Package archive specifiers
+    package-archives()=
+        private.byte=$(this.NAME).cma
+        private.native=$(this.NAME).cmxa
+        s.=
+            extends $(Map)
+            $|byte|=$(byte)
+            $|native|=$(native)
+        return $s
 
 ### OCaml library composition units
 OCaml_program.=
     protected.source(src, context)=
         this=$(OCaml_unit::source $(src), $(context))
         this.LIBREFS[]=
-        if $(defined src.LIBREFS)
+        if $(src.object-mem LIBREFS)
             this.LIBREFS=$(src.LIBREFS)
             export
         return $(this)
         search=
         export search
         foreach(r, $(this.LIBREFS))
-            search+=$(dir $(r.DIR))
+            search+=$(dir $(r.DIR)/$(config))
         return $(search)
     
     ### Auxillary composition method
         
         return $(progs)
 
+### OCaml findlib package composition
+OCaml_findlib_subpackage.=
+    class OCaml_findlib_subpackage
+    
+    ### Raise an exception
+    protected.throw(m)=
+        x.=
+            message=$"Ocaml_findlib_subpackage [$m]"
+        raise $x
+    
+    ### Constructor helper
+    protected.subpackage(i)=
+        if $(not $(i.object-mem NAME))
+            throw($"undefined package name")
+        if $(not $(i.object-mem DESCRIPTION))
+            throw($"no description for package $(i.NAME)")
+        o.=
+            NAME=$(i.NAME)
+            DESCRIPTION=$(i.DESCRIPTION)
+            REQUIRES[]=
+            ARCHIVES[]=
+            SUBPKGS[]=
+        export o
+        if $(this.object-mem NAME)
+            o.NAME=$(this.NAME)/$(o.NAME)
+        if $(i.object-mem REQUIRES)
+            o.REQUIRES=$(i.REQUIRES)
+        if $(i.object-mem ARCHIVES)
+            o.ARCHIVES=$(i.ARCHIVES)
+        return $o
+    
+    ### Construction invariant
+    protected.new(src)=
+        private.src=$(subpackage $(src))
+        this.NAME=$(src.NAME)
+        this.DESCRIPTION=$(src.DESCRIPTION)
+        this.REQUIRES=$(src.REQUIRES)
+        this.ARCHIVES=$(src.ARCHIVES)
+        this.SUBPKGS=$(src.SUBPKGS)
+        return $(this)
+    
+    ### Add a subpackage
+    add-subpackage(src)=
+        this.SUBPKGS+=$(this.subpackage $(src))
+        return $(this)
+
+### OCaml findlib package composition
+OCaml_findlib_package.=
+    class OCaml_findlib_package
+    extends $(OCaml_findlib_subpackage)
+    
+    ### Generate the META file text
+    protected.generate-meta()=
+        fp=$(open-out-string)
+        fprint($(fp), $""# META file generated for $(this.NAME) package
+
+name="$(this.NAME)"
+version="$(this.VERSION)"
+description="$(this.DESCRIPTION)"
+"")
+        if $(this.REQUIRES)
+            fprintln($(fp), $""requires="$(this.REQUIRES)" "")
+        foreach(p, $(this.SUBPKGS))
+            fprintln($(fp), $(EMPTY))
+            fprintln($(fp), $""package "$(basename $(p.NAME))" ("")
+            if $(p.REQUIRES)
+                fprintln($(fp), $""  requires="$(p.REQUIRES)" "")
+            foreach(v, $(p.ARCHIVES))
+                private.byte=$(v.find byte)
+                private.native=$(v.find native)
+                fprintln($(fp), $"  archive(byte)=" "$(byte)")
+                fprintln($(fp), $"  archive(native)=" "$(native)")
+            fprintln($(fp), $")")
+        private.text=$(out-contents $(fp))
+        close($(fp))
+        return $(text)
+    
+    ### The META file target
+    protected.meta-target()=
+        private.meta=$(file $(this.STAGE.DIR)/META)
+        private.text=$(generate-meta)
+            
+        $(meta): $(this.STAGE.DIR) $(this.FILES)
+            fprint($@, $(text))
+        return $(meta)
+    
+    ### Constructor
+    new(src)=
+        this=$(OCaml_findlib_subpackage::new $(src))
+        if $(not $(src.object-mem VERSION))
+            throw($"no version for package $(this.NAME)")
+        private.stage=$(Stage)
+        stage.DIR=$(AUXROOT)
+        this.STAGE=$(stage.push $(this.NAME).package)
+        this.VERSION=$(src.VERSION)
+        this.FILES[]=
+        return $(this)
+    
+    ### Install target
+    install-target()=
+        private.target=$(addprefix install-, $(this.NAME))
+        private.meta=$(meta-target)
+        .PHONY: $(target)
+        $(target): $(meta) $(this.FILES)
+            -ocamlfind install $(this.NAME) $^
+        return $(target)
+    
+    ### Remove target
+    remove-target()=
+        private.target=$(addprefix remove-, $(this.NAME))
+        .PHONY: $(target)
+        $(target):
+            -ocamlfind remove $(this.NAME)
+        return $(target)
+
 # End $File$
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.