1#************************************************************************** 2#* * 3#* OCaml * 4#* * 5#* Xavier Leroy, projet Cristal, INRIA Rocquencourt * 6#* * 7#* Copyright 1999 Institut National de Recherche en Informatique et * 8#* en Automatique. * 9#* * 10#* All rights reserved. This file is distributed under the terms of * 11#* the GNU Lesser General Public License version 2.1, with the * 12#* special exception on linking described in the file LICENSE. * 13#* * 14#************************************************************************** 15 16include ../config/Makefile 17 18INSTALL_BINDIR=$(DESTDIR)$(BINDIR) 19INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR) 20 21# The PROGRAMS (resp. LIBRARIES) variable list the files to build and 22# install as programs in $(INSTALL_BINDIR) (resp. libraries in 23# $(INSTALL_LIBDIR)) 24 25PROGRAMS = ocamlrun$(EXE) 26LIBRARIES = ld.conf libcamlrun.$(A) 27 28ifeq "$(RUNTIMED)" "true" 29PROGRAMS += ocamlrund$(EXE) 30LIBRARIES += libcamlrund.$(A) 31endif 32 33ifeq "$(RUNTIMEI)" "true" 34PROGRAMS += ocamlruni$(EXE) 35LIBRARIES += libcamlruni.$(A) 36endif 37 38ifeq "$(UNIX_OR_WIN32)" "unix" 39ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true" 40LIBRARIES += libcamlrun_pic.$(A) libcamlrun_shared.$(SO) 41endif 42endif 43 44CC=$(BYTECC) 45 46ifdef BOOTSTRAPPING_FLEXLINK 47CFLAGS=-DBOOTSTRAPPING_FLEXLINK 48else 49CFLAGS= 50endif 51 52# On Windows, OCAML_STDLIB_DIR needs to be defined dynamically 53 54ifeq "$(UNIX_OR_WIN32)" "win32" 55CFLAGS += -DOCAML_STDLIB_DIR='"$(LIBDIR)"' 56endif 57 58CFLAGS += $(IFLEXDIR) $(BYTECCCOMPOPTS) 59 60DFLAGS=$(CFLAGS) -DDEBUG 61IFLAGS=$(CFLAGS) -DCAML_INSTR 62PICFLAGS=$(CFLAGS) $(SHAREDCCCOMPOPTS) 63 64ifneq "$(CCOMPTYPE)" "msvc" 65DFLAGS += -g 66endif 67 68ifeq "$(CCOMPTYPE)" "msvc" 69OUTPUTOBJ=-Fo 70else 71OUTPUTOBJ=-o 72endif 73DBGO=d.$(O) 74 75ifeq "$(UNIX_OR_WIN32)" "win32" 76LIBS = $(call SYSLIB,ws2_32) $(EXTRALIBS) 77ifdef BOOTSTRAPPING_FLEXLINK 78MAKE_OCAMLRUN=$(MKEXE_BOOT) 79else 80MAKE_OCAMLRUN = $(MKEXE) -o $(1) $(2) 81endif 82else 83LIBS = $(BYTECCLIBS) 84MAKE_OCAMLRUN = $(MKEXE) $(BYTECCLINKOPTS) -o $(1) $(2) 85endif 86 87PRIMS=\ 88 alloc.c array.c compare.c extern.c floats.c gc_ctrl.c hash.c \ 89 intern.c interp.c ints.c io.c lexing.c md5.c meta.c obj.c parsing.c \ 90 signals.c str.c sys.c terminfo.c callback.c weak.c finalise.c stacks.c \ 91 dynlink.c backtrace_prim.c backtrace.c spacetime.c afl.c 92 93OBJS=$(addsuffix .$(O), \ 94 interp misc stacks fix_code startup_aux startup \ 95 freelist major_gc minor_gc memory alloc roots globroots \ 96 fail signals signals_byt printexc backtrace_prim backtrace \ 97 compare ints floats str array io extern intern \ 98 hash sys meta parsing gc_ctrl terminfo md5 obj \ 99 lexing callback debugger weak compact finalise custom \ 100 dynlink spacetime afl $(UNIX_OR_WIN32) main) 101 102DOBJS=$(OBJS:.$(O)=.$(DBGO)) instrtrace.$(DBGO) 103IOBJS=$(OBJS:.$(O)=.i.$(O)) 104PICOBJS=$(OBJS:.$(O)=.pic.$(O)) 105 106.PHONY: all 107all: $(LIBRARIES) $(PROGRAMS) 108 109ld.conf: ../config/Makefile 110 echo "$(STUBLIBDIR)" > $@ 111 echo "$(LIBDIR)" >> $@ 112 113.PHONY: install 114install: 115 cp $(PROGRAMS) "$(INSTALL_BINDIR)" 116 cp $(LIBRARIES) "$(INSTALL_LIBDIR)" 117 mkdir -p "$(INSTALL_LIBDIR)/caml" 118 for i in caml/*.h; do \ 119 sed -f ../tools/cleanup-header $$i \ 120 > "$(INSTALL_LIBDIR)/$$i"; \ 121 done 122 123# If primitives contain duplicated lines (e.g. because the code is defined 124# like 125# #ifdef X 126# CAMLprim value caml_foo() ... 127# #else 128# CAMLprim value caml_foo() ... 129# end), horrible things will happen (duplicated entries in Runtimedef -> 130# double registration in Symtable -> empty entry in the PRIM table -> 131# the bytecode interpreter is confused). 132# We sort the primitive file and remove duplicates to avoid this problem. 133 134# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC 135# port, the "sort" program in the path is Microsoft's and not cygwin's 136 137# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly. 138# Sort is unstable for "is_directory" and "isatty" 139# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html: 140# "using sort to process pathnames, it is recommended that LC_ALL .. set to C" 141 142 143primitives : $(PRIMS) 144 sed -n -e "s/CAMLprim value \([a-z0-9_][a-z0-9_]*\).*/\1/p" $(PRIMS) \ 145 | LC_ALL=C sort | uniq > primitives 146 147prims.c : primitives 148 (echo '#define CAML_INTERNALS'; \ 149 echo '#include "caml/mlvalues.h"'; \ 150 echo '#include "caml/prims.h"'; \ 151 sed -e 's/.*/extern value &();/' primitives; \ 152 echo 'c_primitive caml_builtin_cprim[] = {'; \ 153 sed -e 's/.*/ &,/' primitives; \ 154 echo ' 0 };'; \ 155 echo 'char * caml_names_of_builtin_cprim[] = {'; \ 156 sed -e 's/.*/ "&",/' primitives; \ 157 echo ' 0 };') > prims.c 158 159caml/opnames.h : caml/instruct.h 160 sed -e '/\/\*/d' \ 161 -e '/^#/d' \ 162 -e 's/enum /char * names_of_/' \ 163 -e 's/{$$/[] = {/' \ 164 -e 's/\([[:upper:]][[:upper:]_0-9]*\)/"\1"/g' caml/instruct.h \ 165 > caml/opnames.h 166 167# caml/jumptbl.h is required only if you have GCC 2.0 or later 168caml/jumptbl.h : caml/instruct.h 169 sed -n -e '/^ /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \ 170 -e '/^}/q' caml/instruct.h > caml/jumptbl.h 171 172caml/version.h : ../VERSION ../tools/make-version-header.sh 173 ../tools/make-version-header.sh ../VERSION > caml/version.h 174 175.PHONY: clean 176clean: 177 rm -f $(LIBRARIES) $(PROGRAMS) *.$(O) *.$(A) *.$(SO) 178 rm -f primitives prims.c caml/opnames.h caml/jumptbl.h 179 rm -f caml/version.h 180 181ocamlrun$(EXE): prims.$(O) libcamlrun.$(A) 182 $(call MAKE_OCAMLRUN,$@,$^ $(LIBS)) 183 184libcamlrun.$(A): $(OBJS) 185 $(call MKLIB,$@, $^) 186 187ocamlrund$(EXE): prims.$(O) libcamlrund.$(A) 188 $(MKEXE) $(MKEXEDEBUGFLAG) $(BYTECCLINKOPTS) -o $@ $^ $(LIBS) 189 190libcamlrund.$(A): $(DOBJS) 191 $(call MKLIB,$@, $^) 192 193ocamlruni$(EXE): prims.$(O) libcamlruni.$(A) 194 $(MKEXE) $(BYTECCLINKOPTS) -o $@ $^ $(LIBS) 195 196libcamlruni.$(A): $(IOBJS) 197 $(call MKLIB,$@, $^) 198 199libcamlrun_pic.$(A): $(PICOBJS) 200 $(call MKLIB,$@, $^) 201 202libcamlrun_shared.$(SO): $(PICOBJS) 203 $(MKDLL) -o $@ $^ $(BYTECCLIBS) 204 205%.$(O): %.c 206 $(CC) $(CFLAGS) -c $< 207 208%.$(DBGO): %.c 209 $(CC) $(DFLAGS) -c $(OUTPUTOBJ)$@ $< 210 211%.i.$(O): %.c 212 $(CC) $(IFLAGS) -c $(OUTPUTOBJ)$@ $< 213 214%.pic.$(O): %.c 215 $(CC) $(PICFLAGS) -c $(OUTPUTOBJ)$@ $< 216 217ifneq "$(TOOLCHAIN)" "msvc" 218.PHONY: depend 219depend : prims.c caml/opnames.h caml/jumptbl.h caml/version.h 220 -$(CC) -MM $(BYTECCCOMPOPTS) *.c > .depend 221 -$(CC) -MM $(BYTECCCOMPOPTS) -DDEBUG *.c | sed -e 's/\.o/.d.o/' \ 222 >> .depend 223 -$(CC) -MM $(BYTECCCOMPOPTS) -DCAML_INSTR *.c | sed -e 's/\.o/.i.o/' \ 224 >> .depend 225 -$(CC) -MM $(BYTECCCOMPOPTS) *.c | sed -e 's/\.o/.pic.o/' >> .depend 226endif 227 228ifeq "$(UNIX_OR_WIN32)" "win32" 229.depend.nt: .depend 230 rm -f .depend.win32 231 echo "win32.o: win32.c caml/fail.h caml/compatibility.h \\"\ 232 >> .depend.win32 233 echo " caml/misc.h caml/config.h ../config/m.h ../config/s.h \\"\ 234 >> .depend.win32 235 echo " caml/mlvalues.h caml/memory.h caml/gc.h caml/major_gc.h \\"\ 236 >> .depend.win32 237 echo " caml/freelist.h caml/minor_gc.h caml/osdeps.h caml/signals.h"\ 238 >> .depend.win32 239 cat .depend >> .depend.win32 240 sed -ne '/\.pic\.o/q' \ 241 -e 's/^\(.*\)\.d\.o:/\1.$$(DBGO):/' \ 242 -e 's/^\(.*\)\.o:/\1.$$(O):/' \ 243 -e p \ 244 .depend.win32 > .depend.nt 245 rm -f .depend.win32 246 247include .depend.nt 248 249else 250include .depend 251endif 252