1## The type of library we want to build. Possible values:
2##   relocatable
3##   static
4UTIL_LIBRARY_TYPE=static
5
6# You may edit this makefile as long as you keep these original
7# target names defined.
8MODE=distrib
9GNATMAKE=@GNATMAKE@
10GNATCLEAN=gnatclean
11GPRINSTALL=@GPRINSTALL@
12SVN=svn
13INSTALL=@INSTALL@
14
15GPRPATH=util.gpr
16UTIL_HTTP_GPRPATH=util_http.gpr
17UTIL_HTTP_CURL_GPRPATH=util_http_curl.gpr
18UTIL_HTTP_AWS_GPRPATH=util_http_aws.gpr
19TESTUTIL_GPRPATH=util_unit.gpr
20
21BUILDS_SHARED=@BUILDS_SHARED@
22
23version=@UTIL_VERSION@
24
25distdir=ada-util-@UTIL_VERSION@
26
27DIST_FILE=ada-util-@UTIL_VERSION@.tar.gz
28
29XML_SRC_DIR=@UTIL_XML_DIR@
30ASM_SRC_DIR=@UTIL_ASM_DIR@
31OS_SRC_DIR=@UTIL_OS_DIR@
32OS_VERSION=@UTIL_OS_VERSION@
33AUNIT_SRC_DIR=@UTIL_AUNIT_DIR@
34AHVEN_SRC_DIR=@UTIL_AHVEN_DIR@
35AHVEN_SRC_OS_DIR=@UTIL_AHVEN_OS_DIR@
36
37HAVE_XML=@UTIL_HAVE_XML@
38HAVE_CURL=@UTIL_HAVE_CURL@
39HAVE_AWS=@UTIL_HAVE_AWS@
40HAVE_VECTOR_MAPPERS=@UTIL_HAVE_VECTOR_MAPPERS@
41HAVE_PRJ_DIRECTORIES=@UTIL_HAVE_PRJ_DIRECTORIES@
42
43LN_S=@LN_S@
44MKDIR=mkdir
45CP=cp
46LN=ln -s
47CC=@CC@
48CFLAGS=@CFLAGS@ @DEFS@
49
50ifeq (${OS},Windows_NT)
51LIBEXT=dll
52LIBVER=dll
53else
54LIBEXT=so
55LIBVER=so.$(version)
56endif
57
58srcdir = .
59top_srcdir = @top_srcdir@
60VPATH = @srcdir@
61prefix = ${DESTDIR}@prefix@
62exec_prefix = @exec_prefix@
63top_builddir = .
64
65# share/ada/adainclude
66infix_inc=@ADA_INC_BASE@
67
68# share/ada/adainclude
69infix_prj=@ADA_PRJ_BASE@
70
71# lib
72infix_lib=@ADA_LIB_BASE@
73
74# lib/ada/adalib
75infix_ali=@ADA_ALI_BASE@
76
77includedir=${prefix}/${infix_inc}
78projectdir=${prefix}/${infix_prj}
79bindir=${prefix}/bin
80libdir=${prefix}/${infix_lib}
81alidir=${prefix}/${infix_ali}
82
83libname=libada_util
84libprefix=$(libname)_
85
86CPUS := @NR_CPUS@
87MAKE_ARGS=-XMODE=${MODE} -XUTIL_LIBRARY_TYPE=${UTIL_LIBRARY_TYPE} -XPROCESSORS=$(CPUS)
88ifeq ($(UTIL_LIBRARY_TYPE),relocatable)
89MAKE_ARGS += -XXMLADA_BUILD=relocatable -XAWS_BUILD=relocatable
90MAKE_ARGS += -XLIBRARY_TYPE=relocatable
91endif
92
93# The timeout execution time in second for a test case.
94# The concurrent fifo test takes arround 120 seconds on some ARM but only 4 seconds on an i7.
95# Make this a make configuration variable so that it can be given when launching make.
96TEST_TIMEOUT=30
97
98ifeq (${BUILDS_SHARED},yes)
99all:     static shared
100install: install_static install_shared install-info
101else
102all:     static
103install: install_static install-info
104endif
105
106UTIL_GEN_FILES=src/util-systems-constants.ads
107UTIL_GEN_FILES+=src/util-systems-types.ads
108ifeq (${HAVE_CURL},yes)
109UTIL_GEN_FILES+=src/http/curl/util-http-clients-curl-constants.ads
110endif
111
112# Build executables for all mains defined by the project.
113build:	$(UTIL_GEN_FILES)
114	$(GNATMAKE) -m -p -P"$(GPRPATH)" $(MAKE_ARGS)
115	test T${HAVE_CURL} = Tno || $(GNATMAKE) -m -p -P"$(UTIL_HTTP_CURL_GPRPATH)" $(MAKE_ARGS)
116	test T${HAVE_AWS} = Tno || $(GNATMAKE) -m -p -P"$(UTIL_HTTP_AWS_GPRPATH)" $(MAKE_ARGS)
117	$(GNATMAKE) -m -p -P"$(TESTUTIL_GPRPATH)" $(MAKE_ARGS)
118	$(GNATMAKE) -m -p -P"$(UTIL_HTTP_GPRPATH)" $(MAKE_ARGS)
119
120static:
121	$(MAKE) UTIL_LIBRARY_TYPE=static build
122
123shared:
124	$(MAKE) UTIL_LIBRARY_TYPE=relocatable build
125
126# Build and run the unit tests
127test:	build regtests/util-testsuite.adb
128	$(GNATMAKE) -p -Ptests_proc $(MAKE_ARGS)
129	$(GNATMAKE) -p -Putil_tests $(MAKE_ARGS)
130	-bin/util_harness -xml util-aunit.xml -timeout ${TEST_TIMEOUT}
131
132regtests/util-testsuite.adb: regtests/util-testsuite.gpb Makefile
133	gnatprep -DHAVE_XML=$(HAVE_XML) -DHAVE_CURL=$(HAVE_CURL) \
134                 -DHAVE_AWS=$(HAVE_AWS) -DHAVE_VECTOR_MAPPERS=$(HAVE_VECTOR_MAPPERS) \
135		 -DOS_VERSION='"$(OS_VERSION)"' \
136		 regtests/util-testsuite.gpb $@
137
138# Not intended for manual invocation.
139# Invoked if automatic builds are enabled.
140# Analyzes only on those sources that have changed.
141# Does not build executables.
142autobuild:
143	$(GNATMAKE) -gnatc -c -k  -P "$(GPRPATH)"
144
145# Clean the root project of all build products.
146clean:	clean_test
147	-rm -rf obj/* $(UTIL_GEN_FILES) bin/utilgen
148	-rm -rf lib/util
149	-rm -rf lib/util-curl
150	-rm -rf lib/util-aws
151	-rm -rf lib/testutil
152	-rm -f bin/util_harness bin/util_test_process
153
154# Clean the files produced by the unit tests
155clean_test:
156	rm -f test?.log test.log test-stream.txt test-write.txt util-tests.xml
157	rm -rf regtests/result
158
159# Clean root project and all imported projects too.
160clean_tree:
161	$(GNATCLEAN) -P "$(GPRPATH)" -r
162
163# Check *all* sources for errors, even those not changed.
164# Does not build executables.
165analyze:
166	$(GNATMAKE) -f  -gnatc -c -k  -P "$(GPRPATH)"
167
168# Clean, then build executables for all mains defined by the project.
169rebuild: clean build
170
171# Update src/util.ads with the latest SVN revision number.
172version:
173	gnatprep `svn info | grep '^[UR][eR][Lv]' | sed -e 's,URL: \(.*\),-DURL="\1",' -e 's,Revision: ,-DREVISION=,'` \
174		  src/util.gpb src/util.ads
175
176# Files to package in source distribution
177DISTFILES=README LICENSE.txt LICENSE.Ahven NOTICE.txt NEWS \
178config.guess configure config.sub \
179configure.in Makefile.in install-sh \
180util.gpr.in util_http.gpr.in config.gpr util_unit.gpr.in util_tests.gpr tests_proc.gpr samples.gpr \
181util_http_aws.gpr.in util_http_curl.gpr.in \
182src samples regtests testutil \
183distrib support bundles
184
185dist:
186	-rm -rf $(distdir)
187	mkdir $(distdir)
188	-chmod 777 $(distdir)
189	here=`cd $(top_builddir) && pwd`; \
190	top_distdir=`cd $(distdir) && pwd`; \
191	distdir=`cd $(distdir) && pwd`; \
192	for file in $(DISTFILES); do \
193	  d=$(srcdir); \
194	  if test -d $$d/$$file; then \
195	    cp -pr $$d/$$file $(distdir)/$$file; \
196	  else \
197	    test -f $(distdir)/$$file \
198	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
199	    || cp -p $$d/$$file $(distdir)/$$file || :; \
200	  fi; \
201	done
202	rm -f $(distdir)/distrib/*.gpr
203	cp distrib/util_config-*.gpr $(distdir)/distrib
204	rm -rf $(distdir)/regtests/result
205	mkdir $(distdir)/bin
206	mkdir $(distdir)/obj
207	mkdir $(distdir)/lib
208	tar --exclude=.svn --exclude=.git --exclude="*~" --exclude="*.o" --exclude="*.ali" \
209	    --exclude="*.log" --exclude="*.a" \
210	    -cvzf $(DIST_FILE) $(distdir)
211
212install_static:
213	$(MAKE) UTIL_LIBRARY_TYPE=static install_lib
214
215install_shared:
216	$(MAKE) UTIL_LIBRARY_TYPE=relocatable install_lib
217
218install_lib:
219ifneq (${GPRINSTALL},)
220	$(GPRINSTALL) -p -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) \
221		--build-name=$(UTIL_LIBRARY_TYPE) $(GPRPATH)
222	$(GPRINSTALL) -p -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) \
223		--build-name=$(UTIL_LIBRARY_TYPE) $(TESTUTIL_GPRPATH)
224	$(GPRINSTALL) -p -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) \
225		--build-name=$(UTIL_LIBRARY_TYPE) $(UTIL_HTTP_GPRPATH)
226	test T${HAVE_CURL} = Tno || \
227		 $(GPRINSTALL) -p -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) \
228					   --build-name=$(UTIL_LIBRARY_TYPE) $(UTIL_HTTP_CURL_GPRPATH)
229	test T${HAVE_AWS} = Tno || \
230		 $(GPRINSTALL) -p -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) \
231					   --build-name=$(UTIL_LIBRARY_TYPE) $(UTIL_HTTP_AWS_GPRPATH)
232else
233	rm -rf ${alidir}/ada-util-curl \
234	       ${alidir}/ada-util-aws \
235	       ${alidir}/ada-util-unit \
236	       ${alidir}/ada-util
237	$(MKDIR) -p ${includedir}/ada-util
238	$(MKDIR) -p ${includedir}/ada-util-unit
239	$(MKDIR) -p ${projectdir}/
240	${MKDIR} -p ${alidir}/ada-util-unit
241	${MKDIR} -p ${alidir}/ada-util
242	${MKDIR} -p ${libdir} ${bindir}
243	${CP} -p testutil/*.ad[bs] ${includedir}/ada-util-unit
244	${CP} -p src/*.ad[bs] ${includedir}/ada-util
245	${CP} -p src/http/*.ad[bs] ${includedir}/ada-util
246	if test T${XML_SRC_DIR} != T ; then \
247	   ${CP} -p ${XML_SRC_DIR}/*.ad[bs] ${includedir}/ada-util ; \
248	fi
249	if test T${ASM_SRC_DIR} != T ; then \
250	   ${CP} -p ${ASM_SRC_DIR}/*.ad[bs] ${includedir}/ada-util ; \
251	fi
252	if test T${OS_SRC_DIR} != T ; then \
253	   ${CP} -p ${OS_SRC_DIR}/*.ad[bs] ${includedir}/ada-util ; \
254	fi
255	if test T${AUNIT_SRC_DIR} != T ; then \
256	   ${CP} -p ${AUNIT_SRC_DIR}/*.ad[bs] ${includedir}/ada-util-unit ; \
257	fi
258	if test T${AHVEN_SRC_DIR} != T ; then \
259	   ${CP} -p ${AHVEN_SRC_DIR}/*.ad[bs] ${includedir}/ada-util-unit ; \
260	   ${CP} -p ${AHVEN_SRC_OS_DIR}/*.ad[bs] ${includedir}/ada-util-unit ; \
261	fi
262	test T${HAVE_PRJ_DIRECTORIES} = Tyes || \
263	  sed -e "s,ALI_INSTALL,${alidir},g" \
264		  -e "s,LIB_INSTALL,${libdir},g" \
265		  -e "s,BIN_INSTALL,${bindir},g" \
266		  -e "s,INCLUDE_INSTALL,${includedir},g" \
267		  < distrib/util_config-default.gpr > ${projectdir}/util_config.gpr
268	test T${HAVE_PRJ_DIRECTORIES} = Tno || \
269	  ${CP} distrib/util_config-directories.gpr ${projectdir}/util_config.gpr
270	sed -e "s,LIBRARY_TYPE,$(UTIL_LIBRARY_TYPE),g" < distrib/util.gpr > ${projectdir}/util.gpr
271	sed -e "s,LIBRARY_TYPE,$(UTIL_LIBRARY_TYPE),g" < distrib/util_unit.gpr > ${projectdir}/util_unit.gpr
272	sed -e "s,LIBRARY_TYPE,$(UTIL_LIBRARY_TYPE),g" < distrib/util_http.gpr > ${projectdir}/util_http.gpr
273	test T${HAVE_CURL} = Tno || \
274	     sed -e "s,LIBRARY_TYPE,$(UTIL_LIBRARY_TYPE),g" \
275		 < distrib/util_http_curl.gpr > ${projectdir}/util_http_curl.gpr
276	test T${HAVE_AWS} = Tno || \
277	     sed -e "s,LIBRARY_TYPE,$(UTIL_LIBRARY_TYPE),g" \
278		 < distrib/util_http_aws.gpr > ${projectdir}/util_http_aws.gpr
279	test T${HAVE_CURL} = Tno || \
280	  (${MKDIR} -p ${includedir}/ada-util-curl && \
281           ${MKDIR} -p ${alidir}/ada-util-curl && \
282	   ${CP} -p src/http/curl/*.ad[bs] ${includedir}/ada-util-curl && \
283	   ${CP} -p lib/util-curl/$(UTIL_LIBRARY_TYPE)/*.ali ${alidir}/ada-util-curl)
284	test T${HAVE_AWS} = Tno || \
285	  (${MKDIR} -p ${includedir}/ada-util-aws && \
286           ${MKDIR} -p ${alidir}/ada-util-aws && \
287	   ${CP} -p src/http/aws/*.ad[bs] ${includedir}/ada-util-aws && \
288	   ${CP} -p lib/util-aws/$(UTIL_LIBRARY_TYPE)/*.ali ${alidir}/ada-util-aws)
289	${CP} -p lib/testutil/$(UTIL_LIBRARY_TYPE)/*.ali ${alidir}/ada-util-unit
290	${CP} -p lib/util/$(UTIL_LIBRARY_TYPE)/*.ali ${alidir}/ada-util
291ifeq ($(UTIL_LIBRARY_TYPE),static)
292	test T${HAVE_AWS} = Tno || \
293	   ${CP} -p lib/util-aws/$(UTIL_LIBRARY_TYPE)/$(libprefix)aws.a ${libdir}/
294	test T${HAVE_CURL} = Tno || \
295	   ${CP} -p lib/util-curl/$(UTIL_LIBRARY_TYPE)/$(libprefix)curl.a ${libdir}/
296	${CP} -p lib/util/$(UTIL_LIBRARY_TYPE)/$(libname).a ${libdir}/
297	${CP} -p lib/testutil/$(UTIL_LIBRARY_TYPE)/$(libprefix)unit.a ${libdir}/
298else
299	test T${HAVE_AWS} = Tno || \
300	   ${CP} -p lib/util-aws/$(UTIL_LIBRARY_TYPE)/$(libprefix)aws.$(LIBVER) ${libdir}/
301	test T${HAVE_CURL} = Tno || \
302	   ${CP} -p lib/util-curl/$(UTIL_LIBRARY_TYPE)/$(libprefix)curl.$(LIBVER) ${libdir}/
303	${CP} -p lib/util/$(UTIL_LIBRARY_TYPE)/$(libname).$(LIBVER) ${libdir}/
304	${CP} -p lib/testutil/$(UTIL_LIBRARY_TYPE)/$(libprefix)unit.$(LIBVER) ${libdir}/
305ifneq (${OS},Windows_NT)
306	cd ${libdir} && \
307	rm -f $(libname).$(LIBEXT) $(libprefix)unit.$(LIBEXT) && \
308	rm -f $(libprefix)aws.$(LIBEXT) $(libprefix)curl.$(LIBEXT) && \
309	${LN} $(libname).$(LIBVER) $(libname).$(LIBEXT) && \
310	${LN} $(libprefix)unit.$(LIBVER) $(libprefix)unit.$(LIBEXT) && \
311	(test T${HAVE_AWS} = Tno || \
312	   ${LN} $(libprefix)aws.$(LIBVER) $(libprefix)aws.$(LIBEXT)) && \
313	(test T${HAVE_CURL} = Tno || \
314	   ${LN} $(libprefix)curl.$(LIBVER) $(libprefix)curl.$(LIBEXT))
315else
316	${CP} -p lib/util/$(UTIL_LIBRARY_TYPE)/$(libname).$(LIBVER) ${bindir}/
317	${CP} -p lib/testutil/$(UTIL_LIBRARY_TYPE)/$(libprefix)unit.$(LIBVER) ${bindir}/
318endif
319endif
320endif
321
322install-info:
323	@echo "Installation directories:"
324	@echo "  Ada source files:    ${includedir}"
325	@echo "  ALI files:           ${alidir}"
326	@echo "  Libraries:           ${libdir}"
327	@echo "  GNAT project:        ${projectdir}"
328	@echo "Environment setup:"
329	@echo "  export ADA_PROJECT_PATH=${projectdir}:$$ADA_PROJECT_PATH"
330
331install-support:
332	$(MKDIR) -p ${bindir}
333	${CP} support/*.sh ${bindir}
334	${CP} support/*.xsl ${bindir}
335
336uninstall:
337ifneq (${GPRINSTALL},)
338	-$(GPRINSTALL) -q -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) --uninstall $(GPRPATH)
339	-$(GPRINSTALL) -q -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) --uninstall $(TESTUTIL_GPRPATH)
340	-$(GPRINSTALL) -q -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) --uninstall $(UTIL_HTTP_GPRPATH)
341	-test T${HAVE_CURL} = Tno || \
342	 $(GPRINSTALL) -q -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) --uninstall $(UTIL_HTTP_CURL_GPRPATH)
343	-test T${HAVE_AWS} = Tno || \
344	 $(GPRINSTALL) -q -f --project-subdir=lib/gnat --prefix=${prefix} $(MAKE_ARGS) --uninstall $(UTIL_HTTP_AWS_GPRPATH)
345else
346	rm -rf ${includedir}/ada-util ${includedir}/ada-util-unit ${includedir}/ada-util-curl ${includedir}/ada-util-aws
347	rm -rf ${alidir}/ada-util ${alidir}/ada-util-unit ${alidir}/ada-util-curl ${alidir}/ada-util-aws  ${alidir}/ada-util-unit
348	rm -f ${libdir}/$(libname).a
349	rm -f ${libdir}/$(libprefix)curl.a ${libdir}/$(libprefix)curl.$(LIBEXT)  ${libdir}/$(libprefix)curl.$(LIBEXT).${version}
350	rm -f ${libdir}/$(libprefix)aws.a ${libdir}/$(libprefix)aws.$(LIBEXT) ${libdir}/$(libprefix)aws.$(LIBEXT).${version}
351	rm -f ${libdir}/$(libprefix)unit.a ${libdir}/$(libprefix)unit.$(LIBEXT) ${libdir}/$(libprefix)unit.$(LIBEXT).${version}
352	rm -f ${libdir}/$(libname).so.${version}
353	rm -f ${libdir}/$(libprefix)unit.so.${version}
354	rm -f ${projectdir}/util_http_aws.gpr
355	rm -f ${projectdir}/util_http_curl.gpr
356	rm -f ${projectdir}/util_http.gpr
357	rm -f ${projectdir}/util_unit.gpr
358	rm -f ${projectdir}/util.gpr
359endif
360
361# prepare before releasing a new version of the package
362# (collect information about changes and SVN repository)
363prepare-release:
364	# ${SVN} update
365	# ${SVN} info > CHANGES
366	# ${SVN} log -v > ChangeLog
367
368src/util-systems-constants.ads:	bin/utilgen
369	bin/utilgen > $@
370
371src/util-systems-types.ads:	bin/utilgen
372	bin/utilgen types > $@
373
374src/http/curl/util-http-clients-curl-constants.ads:	bin/utilgen
375	bin/utilgen curl > $@
376
377# Utility for the generation of util-systems-constants.ads
378bin/utilgen:    support/utilgen.c Makefile
379	mkdir -p bin
380	$(CC) -o $@ $(CFLAGS) -g support/utilgen.c
381