1##
2# Makefile support for Tarball source retrieval
3##
4# Daniel A. Steffen <das@users.sourceforge.net>
5##
6
7##
8# Set these variables as needed, then include this file:
9#
10#  Release
11#  UrlBase
12#  UrlExt
13#  UrlFile
14#  Url
15#  ExtractedDir
16#  ExtractOptions
17#  License
18#  TEApotVersion
19#  TEApotProject
20#  ProjectPlistName
21#  ImportDate
22#  CvsRoot
23#  CvsTag
24#  SvnUrl
25#
26##
27
28ifndef CoreOSMakefiles
29include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
30endif
31
32##
33# Defaults
34##
35
36ifndef TEApotVersion
37ifndef UrlBase
38UrlBase               = http://osdn.dl.sourceforge.net/project
39endif
40ifndef UrlExt
41UrlExt                = .tar.gz
42endif
43ifndef UrlFile
44UrlFile               = $(Project)$(if $(Release),-$(Release))
45endif
46ifndef Url
47Url                   = $(UrlBase)/$(Project)/$(ProjectName)/$(Release)/$(UrlFile)$(UrlExt)
48endif
49ifndef UrlExtract
50UrlExtract            = $(TAR) $(ExtractOptions) zxf
51endif
52ifndef ImportDate
53ImportDate            = $(shell $(DATE) '+%Y-%m-%d')
54endif
55else
56# Retrieve sources from TEApot repository
57ifndef UrlBase
58UrlBase               = http://teapot.activestate.com/package/name
59endif
60ifndef UrlExt
61UrlExt                = .zip
62endif
63ifndef TEApotProject
64TEApotProject         = $(ProjectName)
65endif
66ifndef Url
67Url                   = $(UrlBase)/$(TEApotProject)/ver/$(TEApotVersion)/arch/source/file$(UrlExt)
68endif
69ifndef UrlExtract
70UrlExtract            = $(UNZIP) $(ExtractOptions) -q -d $(ExtractedDir)
71endif
72ifndef ImportDate
73ImportDate            = $(shell echo '$(TEApotVersion)' | awk -F. '{print $$4"-"$$5"-"($$6<9?"0":"")$$6+1}')
74endif
75endif
76ifndef License
77License               = license.terms
78endif
79ifndef ProjectPlistName
80ProjectPlistName      = $(Project)
81endif
82LicenseInstallDir     = $(TclExtLibDir)/$(TclExtDir)
83Plist                 = $(SRCROOT)/$(ProjectPlistName).plist
84ifdef CvsRoot
85ScmGet                = $(CVS) -Q -d '$(CvsRoot)' export $(if $(CvsTag),-r '$(CvsTag)',-D '$(ImportDate)')
86PlistSourceKey        = OpenSourceCVS
87endif
88ifdef SvnUrl
89ScmGet                = $(SVN) -q export -r '{$(ImportDate)}' '$(SvnUrl)'
90PlistSourceKey        = OpenSourceSVN
91endif
92ifndef ScmGet
93Fetch                 = $(CURL) -L -s -S $(Url)
94PlistSourceKey        = OpenSourceURL
95PlistSourceValue      = $(Url)
96ifndef TEApotVersion
97ifndef ExtractedDir
98ExtractedDir          = $(UrlFile)
99endif
100endif
101else
102Fetch                 = ($(ScmGet) $(ExtractedDir) && $(TAR) cz $(ExtractedDir) && $(RMDIR) $(ExtractedDir))
103PlistSourceValue      = $(ScmGet) $(ExtractedDir)
104endif
105ifndef ExtractedDir
106ExtractedDir          = $(Project)
107endif
108
109##
110# Commands
111##
112
113PATCH                ?= /usr/bin/patch
114CURL                 ?= /usr/bin/curl
115CVS                  ?= /usr/bin/cvs
116SVN                  ?= /usr/bin/svn
117UNZIP                ?= /usr/bin/unzip
118SHA1                 ?= /usr/bin/openssl sha1
119DATE                 ?= /bin/date
120
121##
122# Targets
123##
124
125fetch_targets        := fetch extract wipe install-license
126
127extract:: $(SRCROOT)/$(Project)
128
129$(SRCROOT)/$(Project):
130	@echo "Extracting $(Project)..."
131	$(_v) cd $(SRCROOT) && $(UrlExtract) $(Project)$(UrlExt) && $(RM) $(Project)$(UrlExt) && \
132	    if [ ! -d $(Project) ]; then $(MV) $(ExtractedDir) $(Project); fi
133	$(_v) shopt -s nullglob; for p in $(SRCROOT)/$(Project)*.diff; do \
134	    $(PATCH) -d $(SRCROOT)/$(Project) -Np0 < $${p} && $(RM) $${p}; done
135ifdef Configure
136ifneq ($(Configure),:)
137ifdef TEA_TclConfig
138	$(_v) $(TEA_TclConfig)/updt_tcl_m4.sh $@
139endif
140	$(_v) $(CHMOD) +x $(Configure)
141endif
142endif
143
144wipe::
145	cd $(SRCROOT) && $(RMDIR) $(Project)
146
147install-license::
148	$(_v) $(MKDIR) $(DSTROOT)$(LicenseInstallDir) && \
149	     $(INSTALL_FILE) $(SRCROOT)/$(Project)/$(License) $(DSTROOT)$(LicenseInstallDir)/$(Project).txt
150
151fetch:: SRCROOT = $(CURDIR)
152fetch:: $(SRCROOT)/$(Project)$(UrlExt)
153
154$(SRCROOT)/$(Project)$(UrlExt):
155	@echo "Fetching $(Project)..."
156	$(_v) cd $(SRCROOT) && $(Fetch) > $(Project)$(UrlExt)
157	@ if [ ! -f $(Plist) ]; then printf '<?xml version="1.0" encoding="utf-8"?>\n<plist version="1.0">\n<array>\n</array>\n</plist>\n' > $(Plist); fi
158	@ sha="$$(cat $(SRCROOT)/$(Project)$(UrlExt) | $(SHA1))" &&\
159	awk '/^\t<dict>/ {s=$$0; do {getline; s=s"\n"$$0} while($$0 !~ /^\t<\/dict>/);'\
160	'if (match(s,/<key>OpenSourceProject<\/key>\n\t+<string>$(ProjectPlistName)<\/string>/)) {x=1;'\
161	'sub(/<key>OpenSourceVersion<\/key>\n\t+<string>[^\n]*<\/string>/,"<key>OpenSourceVersion</key>\n\t\t<string>$(Release)</string>",s);'\
162	'sub(/<key>$(PlistSourceKey)<\/key>\n\t+<string>[^\n]*<\/string>/,"<key>$(PlistSourceKey)</key>\n\t\t<string>$(PlistSourceValue)</string>",s);'\
163	'sub(/<key>OpenSourceSHA1<\/key>\n\t+<string>[^\n]*<\/string>/,"<key>OpenSourceSHA1</key>\n\t\t<string>'"$${sha}"'</string>",s);'\
164	'sub(/<key>OpenSourceImportDate<\/key>\n\t+<string>[^\n]*<\/string>/,"<key>OpenSourceImportDate</key>\n\t\t<string>'"$(ImportDate)"'</string>",s);'\
165	'}; print s; next}; /^<\/array>/ && !x {print "\t<dict>\n'\
166	'\t\t<key>OpenSourceProject</key>\n\t\t<string>$(ProjectPlistName)</string>\n'\
167	'\t\t<key>OpenSourceVersion</key>\n\t\t<string>$(Release)</string>\n'\
168	'\t\t<key>OpenSourceWebsiteURL</key>\n\t\t<string>http://$(Project).sourceforge.net/</string>\n'\
169	'\t\t<key>$(PlistSourceKey)</key>\n\t\t<string>$(PlistSourceValue)</string>\n'\
170	'\t\t<key>OpenSourceSHA1</key>\n\t\t<string>'"$${sha}"'</string>\n'\
171	'\t\t<key>OpenSourceImportDate</key>\n\t\t<string>'"$(ImportDate)"'</string>\n'\
172	'\t\t<key>OpenSourceLicense</key>\n\t\t<string>Tcl</string>\n'\
173	'\t\t<key>OpenSourceLicenseFile</key>\n\t\t<string>$(Project).txt</string>\n'\
174	'\t</dict>"}; {print}' $(Plist) > $(Plist).1 && $(MV) $(Plist).1 $(Plist)
175
176.PHONY: $(fetch_targets)
177.NOTPARALLEL:
178