File: Makefile.bundles

package info (click to toggle)
coccinelle 1.0.8.deb-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 26,148 kB
  • sloc: ml: 136,392; ansic: 23,594; sh: 2,189; makefile: 2,157; perl: 1,576; lisp: 840; python: 823; awk: 70; csh: 12
file content (170 lines) | stat: -rw-r--r-- 4,832 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
163
164
165
166
167
168
169
170
OCAML_INCLUDE_FLAGS := -I $(SRC_DIR)
OCAMLFLAGS += $(OCAML_INCLUDE_FLAGS)
OCAMLC_CMD= \
	$(OCAMLC) $(OCAMLCFLAGS) $(OCAMLFLAGS) \
	$(EXTRACFLAGS)
OCAMLOPT_CMD= \
	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLFLAGS) \
	$(EXTRACFLAGS)
OCAMLMKLIB_CMD=$(OCAMLMKLIB) -linkall $(EXTRALNKFLAGS)
OCAMLDEP_CMD=$(OCAMLDEP) $(OCAMLDEPFLAGS) $(OCAML_INCLUDE_FLAGS)

OCAMLC_LDFLAGS = $(patsubst %,-custom -cclib -l%_stubs,$(LIBRARY)) \
	$(addprefix -cclib -l,$(C_LIBS))
OCAMLOPT_LDFLAGS = $(patsubst %,-cclib -l%_stubs,$(LIBRARY)) \
	$(addprefix -cclib -l,$(C_LIBS))

OCAMLCCFLAGS+=-ccopt -fPIC

SIDEPRODUCTS+= \
	$(INTERFACES:=.cmi) \
	$(patsubst %,lib%_stubs.a,$(LIBRARY))

all: depend
	@$(MAKE) all-build
all-build: all-build-targets $(OTHERS)
all-build-targets: \
	$(addsuffix .cma,$(ARCHIVE)) \
	$(SIDEPRODUCTS) \
	$(SIDEPRODUCTS_BYTECODE) \
	$(patsubst %,dll%_stubs.so,$(LIBRARY))

define foreach_file_to_copy_from_src
$(file) : $(SRC_DIR)/$(file)
	cp $$< $$@
endef

$(foreach file, \
	$(addsuffix .cma, $(ARCHIVE)) \
	$(addsuffix .cmxa, $(ARCHIVE)) \
	$(addsuffix .cmx, $(INTERFACES)) \
	$(addsuffix .a, $(LIBRARY)) \
	$(SIDEPRODUCTS) \
	$(SIDEPRODUCTS_NATIVE) \
	$(SIDEPRODUCTS_BYTECODE) \
	$(patsubst %,dll%_stubs.so,$(LIBRARY)), \
	$(eval $(foreach_file_to_copy_from_src)))

all.opt: depend
	@$(MAKE) all-opt-build
all-opt-build: all-opt-build-targets $(OTHERS)
all-opt-build-targets: \
	$(addsuffix .cmxa,$(ARCHIVE)) \
	$(addsuffix .cmx,$(INTERFACES)) \
	$(addsuffix .a,$(LIBRARY)) \
	$(SIDEPRODUCTS) \
	$(SIDEPRODUCTS_NATIVE) \
	$(patsubst %,dll%_stubs.so,$(LIBRARY))

clean:
	rm -f .depend $(ARCHIVE:=.cma) $(ARCHIVE:=.cmxa) \
		$(SIDEPRODUCTS) $(SIDEPRODUCTS_NATIVE) \
		$(SIDEPRODUCTS_BYTECODE) \
		$(INTERFACES:=.cmx) $(LIBRARY:=.a) $(CLEANOTHERS) \
		$(patsubst %,$(SRC_DIR)/%.mli,$(PRODUCTS)) \
		$(patsubst %,$(SRC_DIR)/%.ml,$(PRODUCTS)) $(OTHERS) \
		$(patsubst %,dll%_stubs.so,$(LIBRARY)) \
		$(patsubst %,$(SRC_DIR)/dll%_stubs.so,$(LIBRARY)) \
		$(patsubst %,$(SRC_DIR)/%.a,$(LIBRARY)) \
		$(patsubst %,$(SRC_DIR)/lib%_stubs.a,$(LIBRARY)) \
		$(patsubst %,$(SRC_DIR)/%.o,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cmi,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cmx,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cmo,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cmt,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cmti,$(MODULES)) \
		$(patsubst %,$(SRC_DIR)/%.cma,$(ARCHIVE)) \
		$(patsubst %,$(SRC_DIR)/%.cmxa,$(ARCHIVE)) \
		$(patsubst %,$(SRC_DIR)/%.cmi,$(MERE_INTERFACES)) \
		$(patsubst %,$(SRC_DIR)/%.cmti,$(MERE_INTERFACES))

depend: .depend

yacc_files := $(wildcard $(patsubst %,$(SRC_DIR)/%.mly,$(MODULES)))
lex_files := $(wildcard $(patsubst %,$(SRC_DIR)/%.mll,$(MODULES)))

source_files := \
	$(wildcard $(patsubst %,$(SRC_DIR)/%.mli,$(MODULES))) \
	$(patsubst %,$(SRC_DIR)/%.mli,$(MERE_INTERFACES)) \
	$(wildcard $(patsubst %,$(SRC_DIR)/%.ml,$(MODULES))) \
	$(patsubst %.mly,%.ml,$(yacc_files)) \
	$(patsubst %.mly,%.mli,$(yacc_files)) \
	$(patsubst %.mll,%.ml,$(lex_files)) \
        $(GENERATED_SOURCE_FILES)

.PHONY: depend-rec
depend-rec: $(source_files)
	$(OCAMLDEP_CMD) $(source_files) >.depend

.depend:
	$(MAKE) depend-rec

.PHONY: \
	all all-build all-build-targets all.opt all-opt-build \
	all-opt-build-targets clean distclean depend

$(SRC_DIR)/$(ARCHIVE).cma: \
		$(add_suffix ($add_prefix $(LIBRARY),$(SRC_DIR)/dll),_stubs.so)\
		$(patsubst %,$(SRC_DIR)/%.cmo,$(OBJS))
	$(OCAMLC_CMD) $(OCAMLC_LDFLAGS) -a $^ -o $@

$(SRC_DIR)/$(ARCHIVE).cmxa: \
		$(add_suffix ($add_prefix $(LIBRARY),$(SRC_DIR)/dll),_stubs.so)\
		$(patsubst %,$(SRC_DIR)/%.cmx,$(OBJS))
	$(OCAMLOPT_CMD) $(OCAMLOPT_LDFLAGS) -a $^ -o $@

$(SRC_DIR)/$(ARCHIVE).a : $(SRC_DIR)/$(ARCHIVE).cmxa

$(SRC_DIR)/lib$(LIBRARY)_stubs.a : \
	$(patsubst %,$(SRC_DIR)/%_stubs.o,$(C_OBJS))
	$(OCAMLMKLIB_CMD) -o $(SRC_DIR)/$(LIBRARY)_stubs $^

$(SRC_DIR)/dll$(LIBRARY)_stubs.so: $(SRC_DIR)/lib$(LIBRARY)_stubs.a

%.ml: %.mll
	$(OCAMLLEX) $< -o $@

%.ml %.mli: %.mly
	$(OCAMLYACC) $<

%.cmi: %.mli
	$(OCAMLC_CMD) -c $< -o $@

%.cmo: %.ml
	$(OCAMLC_CMD) $(OCAML_BUNDLES_FLAGS) -c $< -o $@

%.cmx: %.ml
	$(OCAMLOPT_CMD) $(OCAML_BUNDLES_FLAGS) -c $< -o $@

define bundle_without_mli
ifeq ($(wildcard $(SRC_DIR)/$(SOURCE).mli),)
ifeq ($(OCAMLOPT),)
$(SRC_DIR)/$(SOURCE).cmi: $(SRC_DIR)/$(SOURCE).cmo
else
$(SRC_DIR)/$(SOURCE).cmo: $(SRC_DIR)/$(SOURCE).cmx
$(SRC_DIR)/$(SOURCE).cmi: $(SRC_DIR)/$(SOURCE).cmx
endif
endif
endef

$(foreach SOURCE,$(MODULES),$(eval $(bundle_without_mli)))

%.o: %.c
	$(OCAMLC_CMD) $(OCAMLCCFLAGS) $< -o $@
# Workaround for what looks like a bug with object compilation...
	- mv $(notdir $@) $@

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
include ../../Makefile.config
-include ../../Makefile.local
endif
endif

ifeq ($(MAKECMDGOALS),all-build)
include .depend
endif

ifeq ($(MAKECMDGOALS),all-opt-build)
include .depend
endif