Gordon Henriksen | 0908d49 | 2007-09-18 12:26:17 +0000 | [diff] [blame^] | 1 | ##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===## |
| 2 | # |
| 3 | # The LLVM Compiler Infrastructure |
| 4 | # |
| 5 | # This file was developed by Gordon Henriksen and is distributed under the |
| 6 | # University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | # |
| 8 | ##===----------------------------------------------------------------------===## |
| 9 | # |
| 10 | # An ocaml library is a unique project type in the context of LLVM, so rules are |
| 11 | # here rather than in Makefile.rules. |
| 12 | # |
| 13 | ##===----------------------------------------------------------------------===## |
| 14 | |
| 15 | include $(LEVEL)/Makefile.config |
| 16 | |
| 17 | # Find the ocaml stdlib root. /usr/local/lib/ocaml is the default when built |
| 18 | # from source; distros use something like /usr/lib/ocaml/3.10.0. |
| 19 | ifndef OCAML_LIBDIR |
| 20 | OCAML_LIBDIR := $(shell $(OCAMLC) -where) |
| 21 | endif |
| 22 | |
| 23 | # CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its |
| 24 | # includes under its libdir. |
| 25 | CFLAGS += -I$(OCAML_LIBDIR) |
| 26 | |
| 27 | include $(LEVEL)/Makefile.common |
| 28 | |
| 29 | # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the |
| 30 | # user can override this with OCAML_LIBDIR. |
| 31 | PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR) |
| 32 | OcamlDir := $(LibDir)/ocaml |
| 33 | |
| 34 | # Info from llvm-config and similar |
| 35 | ifdef UsedComponents |
| 36 | UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents)) |
| 37 | UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents)) |
| 38 | endif |
| 39 | |
| 40 | # Tools |
| 41 | OCAMLCFLAGS += -I $(OcamlDir) |
| 42 | OCAMLAFLAGS += $(patsubst %,-cclib %, \ |
| 43 | $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \ |
| 44 | $(UsedLibs) -l$(LIBRARYNAME)) |
| 45 | |
| 46 | Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) |
| 47 | Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) |
| 48 | Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o) |
| 49 | |
| 50 | Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o) |
| 51 | Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o) |
| 52 | |
| 53 | # Source files |
| 54 | OcamlSources := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml)) |
| 55 | OcamlHeaders := $(OcamlSources:.ml=.mli) |
| 56 | |
| 57 | # Output and intermediate files |
| 58 | # The .cmo files are the only intermediates; all others get installed. |
| 59 | BareLibraryA := lib$(LIBRARYNAME).a |
| 60 | LibraryA := $(OcamlDir)/$(BareLibraryA) |
| 61 | LibraryCMA := $(OcamlDir)/$(LIBRARYNAME).cma |
| 62 | LibraryCMXA := $(OcamlDir)/$(LIBRARYNAME).cmxa |
| 63 | ObjectsCMI := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmi) |
| 64 | ObjectsCMO := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(ObjDir)/%.cmo) |
| 65 | ObjectsCMX := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmx) |
| 66 | |
| 67 | # Dependencies |
| 68 | # Punting on ocamldep, since its output is only suitable for builds where |
| 69 | # objects are placed directly adjacent to sources, which is not us. |
| 70 | # Unfortunately, this is subtly incorrect and leads to occasional problems. |
| 71 | # ocamlc/ocamlopt really need an option akin to gcc -M or gcc -MD. |
| 72 | $(ObjectsCMO): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi) |
| 73 | $(ObjectsCMX): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi) |
| 74 | |
| 75 | # Installation targets |
| 76 | DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a |
| 77 | DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma |
| 78 | DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa |
| 79 | |
| 80 | |
| 81 | ##===- Build static library from C sources --------------------------------===## |
| 82 | |
| 83 | all-local:: $(LibraryA) |
| 84 | clean-local:: clean-a |
| 85 | install-local:: install-a |
| 86 | uninstall-local:: uninstall-a |
| 87 | |
| 88 | $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir |
| 89 | $(Echo) "Building $(BuildMode) $(notdir $@)" |
| 90 | -$(Verb) $(RM) -f $@ |
| 91 | $(Verb) $(Archive) $@ $(ObjectsO) |
| 92 | $(Verb) $(Ranlib) $@ |
| 93 | |
| 94 | clean-a:: |
| 95 | -$(Verb) $(RM) -f $(LibraryA) |
| 96 | |
| 97 | install-a:: $(LibraryA) |
| 98 | $(Echo) "Installing $(BuildMode) $(DestA)" |
| 99 | $(Verb) $(MKDIR) $(PROJ_libocamldir) |
| 100 | $(Verb) $(LTInstall) $(LibraryA) $(DestA) |
| 101 | $(Verb) |
| 102 | |
| 103 | uninstall-a:: |
| 104 | $(Echo) "Uninstalling $(DestA)" |
| 105 | -$(Verb) $(RM) -f $(DestA) |
| 106 | |
| 107 | |
| 108 | ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===## |
| 109 | |
| 110 | all-local:: build-cmis |
| 111 | clean-local:: clean-cmis |
| 112 | install-local:: install-cmis |
| 113 | uninstall-local:: uninstall-cmis |
| 114 | |
| 115 | build-cmis: $(ObjectsCMI) |
| 116 | |
| 117 | $(OcamlDir)/%.cmi: $(PROJ_SRC_DIR)/%.mli $(OcamlDir)/.dir |
| 118 | $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" |
| 119 | $(Verb) $(Compile.CMI) $@ $< |
| 120 | |
| 121 | clean-cmis:: |
| 122 | -$(Verb) $(RM) -f $(ObjectsCMI) |
| 123 | |
| 124 | # Also install the .mli's (headers) as documentation. |
| 125 | install-cmis: $(ObjectsCMI) |
| 126 | $(Verb) $(MKDIR) $(PROJ_libocamldir) |
| 127 | $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \ |
| 128 | $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ |
| 129 | $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ |
| 130 | done |
| 131 | $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \ |
| 132 | $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ |
| 133 | $(DataInstall) $(PROJ_SRC_DIR)/$$i "$(PROJ_libocamldir)/$$i"; \ |
| 134 | done |
| 135 | |
| 136 | uninstall-cmis:: |
| 137 | $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \ |
| 138 | $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ |
| 139 | $(RM) -f "$(PROJ_libocamldir)/$$i"; \ |
| 140 | done |
| 141 | $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \ |
| 142 | $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ |
| 143 | $(RM) -f "$(PROJ_libocamldir)/$$i"; \ |
| 144 | done |
| 145 | |
| 146 | |
| 147 | ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===## |
| 148 | |
| 149 | all-local:: $(LibraryCMA) |
| 150 | clean-local:: clean-cma |
| 151 | install-local:: install-cma |
| 152 | uninstall-local:: uninstall-cma |
| 153 | |
| 154 | $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir |
| 155 | $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" |
| 156 | $(Verb) $(Archive.CMA) $@ $(ObjectsCMO) |
| 157 | $(Verb) for i in $(UsedLibNames); do \ |
| 158 | ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \ |
| 159 | done |
| 160 | |
| 161 | $(ObjDir)/%.cmo: $(PROJ_SRC_DIR)/%.ml $(OcamlDir)/.dir |
| 162 | $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" |
| 163 | $(Verb) $(Compile.CMO) $@ $< |
| 164 | |
| 165 | clean-cma:: |
| 166 | $(Verb) $(RM) -f $(LibraryCMA) |
| 167 | |
| 168 | install-cma:: $(LibraryCMA) |
| 169 | $(Echo) "Installing $(BuildMode) $(DestCMA)" |
| 170 | $(Verb) $(MKDIR) $(PROJ_libocamldir) |
| 171 | $(Verb) $(DataInstall) $(LibraryCMA) "$(DestCMA)" |
| 172 | $(Verb) for i in $(UsedLibNames); do \ |
| 173 | $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ |
| 174 | ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \ |
| 175 | done |
| 176 | |
| 177 | uninstall-cma:: |
| 178 | $(Echo) "Uninstalling $(DestCMA)" |
| 179 | -$(Verb) $(RM) -f $(DestCMA) |
| 180 | $(Verb) for i in $(UsedLibNames); do \ |
| 181 | $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ |
| 182 | $(RM) -f "$(PROJ_libocamldir)/$$i"; \ |
| 183 | done |
| 184 | |
| 185 | |
| 186 | ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===## |
| 187 | |
| 188 | # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's. |
| 189 | # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config. |
| 190 | ifdef OCAMLOPT |
| 191 | |
| 192 | all-local:: $(LibraryCMXA) |
| 193 | clean-local:: clean-cmxa |
| 194 | install-local:: install-cmxa |
| 195 | uninstall-local:: uninstall-cmxa |
| 196 | |
| 197 | $(LibraryCMXA): $(ObjectsCMX) |
| 198 | $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" |
| 199 | $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX) |
| 200 | $(Verb) $(RM) -f $(@:.cmxa=.o) |
| 201 | |
| 202 | $(OcamlDir)/%.cmx: $(PROJ_SRC_DIR)/%.ml |
| 203 | $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build" |
| 204 | $(Verb) $(Compile.CMX) $@ $< |
| 205 | |
| 206 | clean-cmxa:: |
| 207 | $(Verb) $(RM) -f $(LibraryCMXA) $(LibraryCMXA:.cmxa=.o) \ |
| 208 | $(LibraryCMXA:.cmxa=.a) $(ObjectsCMX) |
| 209 | |
| 210 | install-cmxa:: $(LibraryCMXA) |
| 211 | $(Verb) $(MKDIR) $(PROJ_libocamldir) |
| 212 | $(Echo) "Installing $(BuildMode) $(DestCMXA)" |
| 213 | $(Verb) $(DataInstall) $(LibraryCMXA) $(DestCMXA) |
| 214 | $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)" |
| 215 | $(Verb) $(DataInstall) $(LibraryCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a) |
| 216 | $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \ |
| 217 | $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ |
| 218 | $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ |
| 219 | done |
| 220 | |
| 221 | uninstall-cmxa:: $(LibraryCMXA) |
| 222 | $(Echo) "Uninstalling $(DestCMXA)" |
| 223 | $(Verb) $(RM) -f $(DestCMXA) |
| 224 | $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)" |
| 225 | $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a) |
| 226 | $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \ |
| 227 | $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ |
| 228 | $(RM) -f $(PROJ_libocamldir)/$$i; \ |
| 229 | done |
| 230 | |
| 231 | endif |
| 232 | |
| 233 | |
| 234 | ##===- Debugging gunk -----------------------------------------------------===## |
| 235 | printvars:: printcamlvars |
| 236 | |
| 237 | printcamlvars:: |
| 238 | $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)' |
| 239 | $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)' |
| 240 | $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)' |
| 241 | $(Echo) "OCAMLC : " '$(OCAMLC)' |
| 242 | $(Echo) "OCAMLOPT : " '$(OCAMLOPT)' |
| 243 | $(Echo) "Compile.CMI : " '$(Compile.CMI)' |
| 244 | $(Echo) "Compile.CMO : " '$(Compile.CMO)' |
| 245 | $(Echo) "Archive.CMA : " '$(Archive.CMA)' |
| 246 | $(Echo) "Compile.CMX : " '$(Compile.CMX)' |
| 247 | $(Echo) "Archive.CMXA : " '$(Archive.CMXA)' |
| 248 | $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)' |
| 249 | $(Echo) "LibraryCMA : " '$(LibraryCMA)' |
| 250 | $(Echo) "LibraryCMXA : " '$(LibraryCMXA)' |
| 251 | $(Echo) "OcamlSources : " '$(OcamlSources)' |
| 252 | $(Echo) "ObjectsCMI : " '$(ObjectsCMI)' |
| 253 | $(Echo) "ObjectsCMO : " '$(ObjectsCMO)' |
| 254 | $(Echo) "ObjectsCMX : " '$(ObjectsCMX)' |
| 255 | $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)' |
| 256 | $(Echo) "DestA : " '$(DestA)' |
| 257 | $(Echo) "DestCMA : " '$(DestCMA)' |
| 258 | $(Echo) "DestCMXA : " '$(DestCMXA)' |
| 259 | $(Echo) "UsedLibs : " '$(UsedLibs)' |
| 260 | $(Echo) "UsedLibNames : " '$(UsedLibNames)' |
| 261 | |
| 262 | .PHONY: printcamlvars build-cmis \ |
| 263 | clean-a clean-cmis clean-cma clean-cmxa \ |
| 264 | install-a install-cmis install-cma install-cmxa \ |
| 265 | uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa |