Makefile.common.in 4.38 KB
Newer Older
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
1 2 3 4 5 6 7 8 9 10
PREVIOUS_FILES = $(foreach dir,$(PREVIOUS_DIRS),$(addprefix $(dir)/,$(shell sed -n -e 's/^ML *= *\(.*\)/\1/p' $(dir)/Makefile)))

PREVIOUS_MLIS = $(foreach mli,$(PREVIOUS_FILES:.ml=.mli),$(filter $(mli),$(foreach dir,$(PREVIOUS_DIRS),$(wildcard $(dir)/*.mli))))

LIBDIR += $(foreach dir,$(PREVIOUS_DIRS), -I $(dir))
LIBSOPT =  $(patsubst %.cmo,%.cmx,$(LIBS:.cma=.cmxa))

I_PREVIOUS_DIRS = $(foreach dir,$(PREVIOUS_DIRS), -I $(dir))

LOCAL_ML := $(ML)
11
LOCAL_MLI = $(foreach mli,$(ML:.ml=.mli),$(filter $(mli),$(wildcard *.mli))) $(DYP:%.dyp=%.mli)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
12 13 14 15 16 17 18 19 20 21 22 23
LOCAL_CMO := $(ML:%.ml=%.cmo)
LOCAL_CMX := $(ML:%.ml=%.cmx)
MLI = $(foreach mli,$(ML:.ml=.mli),$(filter $(mli),$(wildcard *.mli)))
ML := $(PREVIOUS_FILES) $(ML)
MLI := $(PREVIOUS_MLIS) $(MLI)

CMO = $(ML:.ml=.cmo)
CMI = $(ML:.ml=.cmi)
CMX = $(ML:.ml=.cmx)

.PHONY : all byte opt clean $(PRELIMINARY) superclean

24 25
.PRECIOUS : $(DYP:%.dyp=%.ml %.mli) $(CAMLLEX:%.mll=%.ml)

POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
26 27 28 29 30
PP = $(OCAMLPP)

EXE = $(EXE_SOURCES:%.ml=%)
EXEOPT = $(EXE_SOURCES:%.ml=%.opt)

31 32 33
CAMLLEX_ML=$(CAMLLEX:%.mll=%.ml)
DYP_ML=$(DYP:%.dyp=%.ml)
DYP_MLI=$(DYP:%.dyp=%.mli)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
34 35 36 37 38 39

# generic rules :
#################

# Makes byte the default goal
byte : $(PRELIMINARY) $(LOCAL_CMO) $(EXE)
40
byte_mli : $(PRELIMINARY) $(LOCAL_MLI:%.mli=%.cmi)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
41 42 43 44 45 46 47 48 49
opt : $(PRELIMINARY) $(LOCAL_CMX) $(EXEOPT)

ifdef EXE_SOURCES
$(EXE) : $(CMO)
	@OCAMLC@ -o $@ $(LIBDIR) $(LIBS) $(BYTEFLAGS) $^
endif

ifdef EXE_SOURCES
$(EXEOPT) : $(CMX)
50
	@OCAMLCOPT@ -o $@ $(LIBDIR) $(LIBSOPT) $(OPTFLAGS) $^
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
51 52 53 54
endif


../%.cmi : ../%.mli 
55
	$(foreach dir,$(PREVIOUS_DIRS),$(MAKE) -r -S -C $(dir) byte_mli;)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

%.cmi : %.mli
	@OCAMLC@ $(PP) -c $(LIBDIR) $(LIBS) $(BYTEFLAGS) $<

../%.cmo : ../%.ml 
	$(foreach dir,$(PREVIOUS_DIRS),$(MAKE) -r -S -C $(dir) byte;)
#	$(MAKE) -r -S -C $(@D) $(@F)

../%.cmx : ../%.ml 
	$(foreach dir,$(PREVIOUS_DIRS),$(MAKE) -r -S -C $(dir) opt;)
#	$(MAKE) $(PP) -r -S -C $(@D) $(@F)

%.cmo : %.ml $(PREVIOUS_FILES:.ml=.cmo) $(PREVIOUS_MLIS)
	@OCAMLC@ $(PP) -c $(LIBDIR) $(BYTEFLAGS) $<

%.cmx : %.ml $(PREVIOUS_FILES:.ml=.cmx) $(PREVIOUS_MLIS)
	@OCAMLCOPT@ $(PROFILEOPT) $(PP) -c $(LIBDIR) $(OPTFLAGS) $<

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

#DYPGEN_EXE = @DYPGEN@
#DYPGEN_EXE = $(DYPPATH)/dypgen/dypgen --ocamlc "$(LIBDIR) $(I_PREVIOUS_DIRS)"
DYPGEN_EXE = @DYPGEN@ --no-pp --no-obj-type --ocamlc "$(LIBDIR) $(I_PREVIOUS_DIRS)"


%.mli : %.dyp
	 $(DYPGEN_EXE) --noemit-token-type $<
%.ml : %.dyp
	 $(DYPGEN_EXE) --noemit-token-type $<


%.ml : %.mll
	@OCAMLLEX@ $<


POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
90 91 92 93 94 95 96 97 98 99 100 101 102
# Dependancy graphs and types
##################

dep : depend.ps
types : types.ps

depend.ps : DEP_FLAG = -dot-reduce
types.ps : DEP_FLAG = -dot-types

depend.ps : depend.dot
	dot -Tps -o $@ $<

%.dot : $(CMO)
103
#	@OCAMLDOC@ $(PP) $(LIBDIR) -o $@ -dot $(DEP_FLAG) $(ML)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
104 105 106 107 108 109 110 111 112 113
	@OCAMLDOC@ $(PP) $(LIBDIR) -o $@ -dot $(DEP_FLAG) $(ML)


# clean and depend
##################

clean:
ifdef EXE
	@rm -f $(EXE) $(EXEOPT)
endif
114 115
#	echo $(CAMLLEX_ML) $(DYP_ML) $(DYP_MLI)
	@rm -f *.cm[ioax]* *.o *.a *~ *.annot depend .targets $(CAMLLEX_ML) $(DYP_ML) $(DYP_MLI) $(DYP:%.dyp=%.extract_type) $(DYP:%.dyp=%.ml.temp)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
116 117 118 119 120 121 122 123 124 125
	@rm -f *.dot *.ps *.log
	@rm -rf doc
	@find . -name "*#[0-9]*" -exec printf "\n\nWARNING: I did not erase the file %s. It probably is a file automatically generated by so6 because of a conflict. Please check if the conflict was resolved, and manually erase it\n\n" {} \;
	@find . -name "#*" -exec printf "\n\nWARNING: I did not erase the file %s. It probably is a file automatically generated by (X)Emacs as backup. Please check if it can be erased\n\n" {} \;

superclean: clean
	@rm -i *#[0-9]*
	@rm -i #*


126
depend: $(filter-out $(DYP_ML) $(DYP_MLI),$(LOCAL_MLI) $(LOCAL_ML) $(EXE_SOURCES))
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	rm -f depend
	@(@OCAMLDEP@ $(PP) $(I_PREVIOUS_DIRS) $^ > depend)||(printf "\n\n****** WARNING: DEPEND FILE NOT GENERATED *******\n\n\n" ;rm depend)

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),superclean)
ifneq ($(MAKECMDGOALS),depend)
ifneq ($(MAKECMDGOALS),config)
-include depend
endif
endif
endif
endif

# documentation rules
#####################
doc : $(CMO) $(MLI) $(ML)
	mkdir -p doc
	@OCAMLDOC@ $(PP) $(OCAMLDOC_FLAGS) $(LIBDIR) -d $@ $(filter %.mli,$^) $(filter %.ml,$^)
#	@OCAMLDOC@ $(PP) $(OCAMLDOC_FLAGS) $(LIBDIR) -d $@ $(filter %.mli,$^)


.targets:
	-rm -f $@
	@($(foreach exe,$(EXE),echo $(exe) : $(exe:%=%.cmo)>>$@;))
	@($(foreach exe,$(EXE),echo $(exe:%=%.opt) : $(exe:%=%.cmx)>>$@;))

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),superclean)
ifneq ($(MAKECMDGOALS),config)
ifdef EXE_SOURCES
include .targets
endif
endif
endif
endif