Skip to content

Commit f266c65

Browse files
committed
#b6ce087 wip reworking extlib handling
1 parent 7d749f0 commit f266c65

File tree

5 files changed

+50
-81
lines changed

5 files changed

+50
-81
lines changed

_charm/src/b6ce0872ce6312705d7b7dda4d3f6ead0a903d8106eccab76a0c4c16380779dd.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<links>
88
<link name="parent">7bc74cc796c455a46d699ad91f6aca5b7c790f56a6a0968b4ecbce33efce9d25</link>
99
</links>
10-
<cf v="Sebastien Devaux 2025-06-20T18:30:25+02:00"/>
10+
<cf v="Sebastien Devaux 2025-07-01T22:34:02+02:00"/>
1111
</cr>

core/common-extlib.mk

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
## ------------------------------------------------------------------------
33
## Dependencies management
44
## ------------------------------------------------------------------------
5-
# replace the | by - in libs specifications.
6-
USELIB_FOR_PATH=$(subst |,-,$(USELIB))
75

86
# MAP to get version of lib with | separator.
97
# This permit to correctly identify version even if lib have a '-' in its name
@@ -24,32 +22,13 @@ endef
2422
define getLibNameFromVersioned
2523
$(if $(findstring |,$1),$(word 1,$(subst |, ,$1)),$(word 1,$(subst -, ,$1)))
2624
endef
27-
28-
# macro to get the lib name from lib with version.
29-
# This macro use libs in list to get the real name of lib
30-
# if the list contains the lib with '|'
31-
# 1: the name of lib with version
32-
# 2: the list of libs
33-
define findLibNameFromVersioned
34-
$(call getLibNameFromVersioned,$(call getLibWithBar,$1,$2))
35-
endef
36-
37-
# macro to get lib from the name of the archive
38-
# 1: archive name (ex: cppunit-1.14.0.$(ARCH).tar.gz)
39-
# return the name of lib (ex: cppunit-1.14.0)
40-
define getLibFromArchiveName
41-
$(strip $(patsubst %.$(ARCH).tar.gz,%,$(filter %.$(ARCH).tar.gz,$1))\
42-
$(patsubst %.noarch.tar.gz,%,$(filter %.noarch.tar.gz,$1)))
43-
endef
44-
45-
# macro to get lib name from the name of the archive
46-
# 1: archive name (ex: cppunit-1.14.0.$(ARCH).tar.gz)
47-
# 2: list of libs
48-
define getLibNameFromArchiveName
49-
$(call findLibNameFromVersioned,$(call getLibFromArchiveName,$1),$2)
25+
# macro to get the lib version from <libname>-<version> or <libname>|<version>
26+
# 1: the name of lib with version.
27+
define getLibVersionFromVersioned
28+
$(if $(findstring |,$1),$(word 2,$(subst |, ,$1)),$(subst $(word 1,$(subst -, ,$1))-,,$1))
5029
endef
5130

52-
# mecro to get the list from a list using its name.
31+
# macro to get the list from a list using its name.
5332
# 1: name of the lib
5433
# 2: list of libs
5534
define getLibWithLibName
@@ -138,7 +117,7 @@ ABS_DEPDOWNLOAD_RULE_OVERLOADED:=1
138117
.PRECIOUS: $(ABSWS_EXTLIBDIR)/%/import.mk $(ABSWS_NDEXTLIBDIR)/%/import.mk $(ABSWS_NA_EXTLIBDIR)/%/import.mk $(ABSWS_NDNA_EXTLIBDIR)/%/import.mk
139118

140119

141-
ABS_REPO_TEMPLATE=$(foreach entry, $(ABS_REPO),$(if $(findstring {,$(entry)),$(entry),$(entry)/{arch}/{name}-{version}.{arch}{ext} $(entry)/{arch}/{name}/{name}-{version}.{arch}{ext} $(entry)/noarch/{name}-{version}{ext}))
120+
ABS_REPO_TEMPLATE=$(foreach entry, $(ABS_REPO),$(if $(findstring {,$(entry)),$(entry),$(entry)/{arch}/{name}-{version}.{arch}.{ext} $(entry)/{arch}/{name}/{name}-{version}.{arch}.{ext} $(entry)/noarch/{name}-{version}.{ext}))
142121

143122
# fetch package with wget (any URL kind that wget can handle)
144123
# $1 URL to download from
@@ -182,13 +161,13 @@ endef
182161

183162

184163
# Get URL list related to a package
185-
# $1 package file name. expected format is <name>-<version>.<arch>.<ext>
164+
# $1 package file name. expected format is <name>/<version>/pck.<ext>
186165
define GetDownloadURLs
187-
$(call SubstituteRepoTemplate,$(word 1,$(subst -, ,$1)),$(subst $(word 1,$(subst -, ,$1))-,,$(word 1,$(subst .$(ARCH), ,$1))),$(ARCH),.$(word 2,$(subst $(ARCH)., ,$1)))
166+
$(call SubstituteRepoTemplate,$(word 1,$(subst /, ,$1)),$(word 2,$(subst /, ,$1)),$(ARCH),$(subst pck.,,$(word 3,$(subst /, ,$1))))
188167
endef
189168

190169
define GetNoarchDownloadURLs
191-
$(call SubstituteRepoTemplate,$(word 1,$(subst -, ,$1)),$(subst $(word 1,$(subst -, ,$1))-,,$(word 1,$(subst .$(ARCH), ,$1))),noarch,)
170+
$(call SubstituteRepoTemplate,$(word 1,$(subst /, ,$1)),$(word 2,$(subst /, ,$1)),noarch,$(subst pck.,,$(word 3,$(subst /, ,$1))))
192171
endef
193172

194173
# Get URL list related to a raw package package file name
@@ -200,15 +179,14 @@ endef
200179
$(ABS_CACHE)/noarch/%:
201180
@mkdir -p $(@D)
202181
@$(ABS_PRINT_info) "Fetching NA $@..."
203-
$(call downloadFromURLs,$@,$(call GetNoarchDownloadURLs,$(@F)))
182+
$(call downloadFromURLs,$@,$(call GetNoarchDownloadURLs,$(subst $(ABS_CACHE)/noarch/,,$@)))
204183
@test -f $@
205184

206185

207186
$(ABS_CACHE)/%:
208187
@mkdir -p $(@D)
209188
@$(ABS_PRINT_info) "Fetching $@..."
210-
@$(ABS_PRINT_debug) "Debug on."
211-
$(call downloadFromURLs,$@,$(call GetDownloadURLs,$(@F)))
189+
$(call downloadFromURLs,$@,$(call GetDownloadURLs,$(subst $(ABS_CACHE)/$(ARCH)/,,$@)))
212190
@test -f $@
213191

214192
# extract import.mk at the end to be sure the extraction is complete.
@@ -217,26 +195,25 @@ define unpackArchive
217195
@$(ABS_PRINT_debug) "$<"
218196
@$(if $(wildcard $(@D)),chmod -R u+w $(@D) && rm -rf $(@D))
219197
@mkdir -p $(@D)
220-
@tar --exclude=$*/import.mk -xmzf $< -C $1
221-
@tar -xmzf $< -C $(1) $*/import.mk
198+
@tar -xmzf $< -C $(@D) --strip-components=1
222199
@$(if $(filter 1 true,$(EXTLIBDIR_READONLY)),chmod -R a-w $(@D))
223200
@touch $@
224201
endef
225202

226203
# unpack arch specific external lib
227-
$(ABSWS_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/$(ARCH)/%.$(ARCH).tar.gz
204+
$(ABSWS_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/$(ARCH)/%/pck.tar.gz
228205
$(call unpackArchive,$(ABSWS_EXTLIBDIR))
229206

230207
# unpack external lib that should not be forwarded to dist package
231-
$(ABSWS_NDEXTLIBDIR)/%/import.mk: $(ABS_CACHE)/$(ARCH)/%.$(ARCH).tar.gz
208+
$(ABSWS_NDEXTLIBDIR)/%/import.mk: $(ABS_CACHE)/$(ARCH)/%/pck.tar.gz
232209
$(call unpackArchive,$(ABSWS_NDEXTLIBDIR))
233210

234211
# unpack no arch external lib
235-
$(ABSWS_NA_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/noarch/%.tar.gz
212+
$(ABSWS_NA_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/noarch/%/pck.tar.gz
236213
$(call unpackArchive,$(ABSWS_NA_EXTLIBDIR))
237214

238215
# unpack no arch external lib that should not be forwarded to dist package
239-
$(ABSWS_NDNA_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/noarch/%.tar.gz
216+
$(ABSWS_NDNA_EXTLIBDIR)/%/import.mk: $(ABS_CACHE)/noarch/%/pck.tar.gz
240217
$(call unpackArchive,$(ABSWS_NDNA_EXTLIBDIR))
241218

242219

@@ -316,7 +293,7 @@ $(NDNA_EXTLIBDIR)/%/.dir: $(ABSWS_NDNA_EXTLIBDIR)/%/.dir
316293
$(call extlib_linkLibrary)
317294

318295
ifneq ($(BUILDCHAIN),)
319-
USELIB+=runtime-$(BUILDCHAIN)
296+
USELIB+=runtime|$(BUILDCHAIN)
320297
endif
321298

322299
# USELIB / NDUSELIB from modules. (needed for dist)
@@ -382,7 +359,7 @@ endef
382359
# $5 variable to use to store libs
383360
define extlib_import2
384361
$(foreach lib,$3,$(call extlib_import3,$(lib),$1-$2,$4,$5))
385-
$(eval _app_$1_dir:=$4/$1-$2)
362+
$(eval _app_$1_dir:=$4/$1/$2)
386363
$(eval _app_$1_depends+=$(foreach lib,$3,$(call getLibNameFromVersioned,$(lib))))
387364
$(eval ALL_LIBS_LOADED+=$1)
388365
endef
@@ -408,15 +385,17 @@ $$(NA_EXTLIBDIR)/%.jar: $$(EXTLIBDIR)/$1-$2/lib/%.jar
408385
@mkdir -p $$(@D)
409386
@$$(LNFILE) $$< $$@
410387
endef
388+
411389
# list of import makefile from external libraries declared in module
412390
# configuration only if not requesting clean or cleanabs target. In this case,
413391
# we don't care importing the dependencies.
414392
ifeq ($(filter clean% purgeabs docker% tag,$(MAKECMDGOALS)),)
393+
EXTLIBMAKES= \
394+
$(foreach entry,$(sort $(USELIB) $(MODS_USELIBS)),$(EXTLIBDIR)/$(call getLibNameFromVersioned,$(entry))/$(call getLibVersionFromVersioned,$(entry))/import.mk) \
395+
$(foreach entry,$(sort $(NDUSELIB) $(MODS_NDUSELIBS)),$(NDEXTLIBDIR)/$(call getLibNameFromVersioned,$(entry))/$(call getLibVersionFromVersioned,$(entry))/import.mk) \
396+
$(foreach entry,$(sort $(NDNA_USELIB)),$(NDNA_EXTLIBDIR)/$(call getLibNameFromVersioned,$(entry))/$(call getLibVersionFromVersioned,$(entry))/import.mk) \
397+
$(foreach entry,$(sort $(NA_USELIB)),$(NA_EXTLIBDIR)/$(call getLibNameFromVersioned,$(entry))/$(call getLibVersionFromVersioned,$(entry))/import.mk)
415398

416-
EXTLIBMAKES=$(patsubst %,$(EXTLIBDIR)/%/import.mk,$(subst |,-,$(sort $(USELIB) $(MODS_USELIBS)))) \
417-
$(patsubst %,$(NDEXTLIBDIR)/%/import.mk,$(subst |,-,$(sort $(NDUSELIB) $(MODS_NDUSELIBS)))) \
418-
$(patsubst %,$(NDNA_EXTLIBDIR)/%/import.mk,$(subst |,-,$(sort $(NDNA_USELIB)))) \
419-
$(patsubst %,$(NA_EXTLIBDIR)/%/import.mk,$(subst |,-,$(sort $(NA_USELIB))))
420399

421400
DEFAULT_EXTLIBMAKES:=$(EXTLIBMAKES)
422401

core/module-test.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
ifeq ($(filter %-win32 %-posix,$(CC_VERSION)),)
1919
CC_VERSION_GE6:=$(shell [ `echo "$(CC_VERSION)" | cut -f1 -d.` -ge 6 ] && echo true || echo false)
2020
ifeq ($(CC_VERSION_GE6),false)
21-
CPPUNIT?=cppunit-1.12.1
21+
CPPUNIT?=cppunit|1.12.1
2222
endif
2323
endif
24-
CPPUNIT?=cppunit-1.14.0
24+
CPPUNIT?=cppunit|1.14.0
2525

2626
TESTRUNNER=ctrunner$(BINEXT)
2727
TXTXSL=xunit2txt.xsl
@@ -33,7 +33,7 @@ else
3333
TIMEOUTCMD:=timeout $(TIMEOUT)
3434
endif
3535

36-
CPPUNIT_DIR=$(NDEXTLIBDIR)/$(CPPUNIT)
36+
CPPUNIT_DIR=$(NDEXTLIBDIR)/$(word 1,$(subst |, ,$(CPPUNIT)))/$(word 2,$(subst |, ,$(CPPUNIT)))
3737
TCFLAGS+=-I$(CPPUNIT_DIR)/include
3838
TLDFLAGS+=-L$(CPPUNIT_DIR)/$(SODIR)
3939
TLINKLIB+=cppunit

doc/main.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ HEMLARGS:=-param app $(APPNAME) -param version $(VERSION) -param date "`date --r
2424

2525
PUMLVERSION?=1.2021.6
2626
LUAJVERSION?=3.0.1
27-
PUMLJAR?=$(NDNA_EXTLIBDIR)/plantuml.$(PUMLVERSION).jar
28-
LUAJJAR?=$(NDNA_EXTLIBDIR)/luaj-jse-$(LUAJVERSION).jar
29-
HEMLJAR?=$(NDNA_EXTLIBDIR)/heml-$(HEMLVERSION).jar
27+
PUMLJAR?=$(NDNA_EXTLIBDIR)/plantuml/$(PUMLVERSION)/pck.jar
28+
LUAJJAR?=$(NDNA_EXTLIBDIR)/luaj-jse/$(LUAJVERSION)/pck.jar
29+
HEMLJAR?=$(NDNA_EXTLIBDIR)/heml/$(HEMLVERSION)/pck.jar
3030
HEMLCMD?=$(JAVACMD) -jar $(call absGetPath,$(HEMLJAR))
3131
PUMLCMD?=$(JAVACMD) -jar $(call absGetPath,$(PUMLJAR))
3232

sampleprj/Makefile

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,28 @@ include $(ABSROOT)/core/main.mk
4444
# Default and minimal rule download files from repository
4545
# May be overloaded by dependencies download rules for more features
4646
ifeq ($(ABS_DEPDOWNLOAD_RULE_OVERLOADED),)
47-
ABS_REPO_1ST=$(word 1,$(ABS_REPO))
48-
ifeq ($(findstring %,$(ABS_REPO_1ST)),)
49-
ABS_REPO_PATTERN_1ST:=$(ABS_REPO_1ST)/$(ARCH)/%
50-
ABS_REPO_NA_PATTERN_1ST:=$(ABS_REPO_1ST)/noarch/%
51-
else
52-
$(eval ABS_REPO_PATTERN_1ST:=$(ABS_REPO_1ST))
53-
$(eval ABS_REPO_NA_PATTERN_1ST:=$(subst $$(ARCH),noarch,$(ABS_REPO_1ST)))
54-
endif
47+
ABS_REPO_TEMPLATE=$(foreach entry, $(ABS_REPO),$(if $(findstring {,$(entry)),$(entry),$(entry)/{arch}/{name}-{version}.{arch}{ext} $(entry)/{arch}/{name}/{name}-{version}.{arch}{ext} $(entry)/noarch/{name}-{version}{ext}))
48+
# CAUTION: empty line before endef into the next 3 macro define is needed
49+
define GetFileWget
50+
@test -f $2 || ( echo "Downloading $1..." ; wget -q $(WGETFLAGS) $1 -O $2 || rm -f $2 )
5551

56-
$(ABS_CACHE)/noarch/%:
57-
@mkdir -p $(@D)
58-
ifeq ($(findstring file://,$(ABS_REPO_NA_PATTERN_1ST)),file://)
59-
@test -r $(patsubst file://%,%,$(patsubst %,$(ABS_REPO_NA_PATTERN_1ST),$(@F))) || exit 1
60-
@echo "Linking $(@F) from $(ABS_REPO_NA_PATTERN_1ST)"
61-
@ln -sf $(patsubst file://%,%,$(patsubst %,$(ABS_REPO_NA_PATTERN_1ST),$(@F))) $@
62-
else
63-
@echo "Fetching $(@F) from $(ABS_REPO_NA_PATTERN_1ST)"
64-
@wget -q $(WGETFLAGS) $(patsubst %,$(ABS_REPO_NA_PATTERN_1ST),$(@F)) -O [email protected]
65-
66-
endif
52+
endef
53+
define GetFileScp
54+
@test -f $2 || ( echo "Downloading $1..." ; scp $(SCPFLAGS) $(patsubst scp:%,%,$1) $2 || : )
6755

68-
$(ABS_CACHE)/%:
56+
endef
57+
define GetFileLink
58+
@test -f $2 || ( echo "Linking $1..." ; ln -sf $(patsubst file://%,%,$1) $2 ; test -r $2 || rm -f $2 )
59+
60+
endef
61+
define downloadFromURLs
62+
$(foreach entry,$2,$(if $(filter file://%,$(entry),),$(call GetFileLink,$(entry),$1))$(if $(filter scp:%,$(entry),),$(call GetFileScp,$(entry),$1))$(if $(filter-out file://% scp:%,$(entry)),$(call GetFileWget,$(entry),$1)))
63+
endef
64+
65+
$(ABS_CACHE)/noarch/abs.%-$(VABS).tar.gz:
6966
@mkdir -p $(@D)
70-
ifeq ($(findstring file://,$(ABS_REPO_PATTERN_1ST)),file://)
71-
@test -r $(patsubst file://%,%,$(patsubst %,$(ABS_REPO_PATTERN_1ST),$(@F))) || exit 1
72-
@echo "Linking $(@F) from $(ABS_REPO_PATTERN_1ST)"
73-
@ln -sf $(patsubst file://%,%,$(patsubst %,$(ABS_REPO_PATTERN_1ST),$(@F))) $@
74-
else
75-
@echo "Fetching $(@F) from $(ABS_REPO_PATTERN_1ST)"
76-
@wget -q $(WGETFLAGS) $(patsubst %,$(ABS_REPO_PATTERN_1ST),$(@F)) -O [email protected]
77-
78-
endif
67+
$(call downloadFromURLs,$@,$(subst {name},abs.core,$(subst {version},$(VABS),$(subst {ext},.tar.gz,$(subst {arch},noarch,$(ABS_REPO_TEMPLATE))))))
68+
@test -f $@
7969

8070
endif
8171

0 commit comments

Comments
 (0)