Makefile.common.in 5.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
##########################################################################
#                                                                        #
#                 ACG development toolkit                                #
#                                                                        #
#                  Copyright 2008 INRIA                                  #
#                                                                        #
#  More information on "http://acg.gforge.loria.fr/"                     #
#  License: CeCILL, see the LICENSE file or "http://www.cecill.info"     #
#  Authors: see the AUTHORS file                                         #
#                                                                        #
#                                                                        #
#                                                                        #
#                                                                        #
#  $Rev::                              $:  Revision of last commit       #
#  $Author::                           $:  Author of last commit         #
#  $Date::                             $:  Date of last commit           #
#                                                                        #
##########################################################################

POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
20 21 22 23 24 25 26 27 28 29
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)
30
LOCAL_MLI = $(foreach mli,$(ML:.ml=.mli),$(filter $(mli),$(wildcard *.mli))) $(DYP:%.dyp=%.mli)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
31 32 33 34 35 36 37 38 39 40 41 42
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

43 44
.PRECIOUS : $(DYP:%.dyp=%.ml %.mli) $(CAMLLEX:%.mll=%.ml)

POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
45 46 47 48 49
PP = $(OCAMLPP)

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

50 51 52
CAMLLEX_ML=$(CAMLLEX:%.mll=%.ml)
DYP_ML=$(DYP:%.dyp=%.ml)
DYP_MLI=$(DYP:%.dyp=%.mli)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
53 54 55 56 57 58

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

# Makes byte the default goal
byte : $(PRELIMINARY) $(LOCAL_CMO) $(EXE)
59
byte_mli : $(PRELIMINARY) $(LOCAL_MLI:%.mli=%.cmi)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
60 61 62 63 64 65 66 67 68
opt : $(PRELIMINARY) $(LOCAL_CMX) $(EXEOPT)

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

ifdef EXE_SOURCES
$(EXEOPT) : $(CMX)
69
	@OCAMLCOPT@ -o $@ $(LIBDIR) $(LIBSOPT) $(OPTFLAGS) $^
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
70 71 72 73
endif


../%.cmi : ../%.mli 
74
	$(foreach dir,$(PREVIOUS_DIRS),$(MAKE) -r -S -C $(dir) byte_mli;)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

%.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) $<

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

#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
109 110 111 112 113 114 115 116 117 118 119 120 121
# 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)
122
#	@OCAMLDOC@ $(PP) $(LIBDIR) -o $@ -dot $(DEP_FLAG) $(ML)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
123 124 125 126 127 128 129 130 131 132
	@OCAMLDOC@ $(PP) $(LIBDIR) -o $@ -dot $(DEP_FLAG) $(ML)


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

clean:
ifdef EXE
	@rm -f $(EXE) $(EXEOPT)
endif
133 134
#	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
135 136 137 138 139 140 141 142 143 144
	@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 #*


145
depend: $(filter-out $(DYP_ML) $(DYP_MLI),$(LOCAL_MLI) $(LOCAL_ML) $(EXE_SOURCES))
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	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