## # Makefile support for Tarball source retrieval ## # Daniel A. Steffen ## ## # Set these variables as needed, then include this file: # # Release # UrlBase # UrlExt # UrlFile # Url # ExtractedDir # ExtractOptions # License # TEApotVersion # TEApotProject # ProjectPlistName # ImportDate # CvsRoot # CvsTag # SvnUrl # ## ifndef CoreOSMakefiles include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make endif ## # Defaults ## ifndef TEApotVersion ifndef UrlBase UrlBase = http://osdn.dl.sourceforge.net/project endif ifndef UrlExt UrlExt = .tar.gz endif ifndef UrlFile UrlFile = $(Project)$(if $(Release),-$(Release)) endif ifndef Url Url = $(UrlBase)/$(Project)/$(ProjectName)/$(Release)/$(UrlFile)$(UrlExt) endif ifndef UrlExtract UrlExtract = $(TAR) $(ExtractOptions) zxf endif ifndef ImportDate ImportDate = $(shell $(DATE) '+%Y-%m-%d') endif else # Retrieve sources from TEApot repository ifndef UrlBase UrlBase = http://teapot.activestate.com/package/name endif ifndef UrlExt UrlExt = .zip endif ifndef TEApotProject TEApotProject = $(ProjectName) endif ifndef Url Url = $(UrlBase)/$(TEApotProject)/ver/$(TEApotVersion)/arch/source/file$(UrlExt) endif ifndef UrlExtract UrlExtract = $(UNZIP) $(ExtractOptions) -q -d $(ExtractedDir) endif ifndef ImportDate ImportDate = $(shell echo '$(TEApotVersion)' | awk -F. '{print $$4"-"$$5"-"($$6<9?"0":"")$$6+1}') endif endif ifndef License License = license.terms endif ifndef ProjectPlistName ProjectPlistName = $(Project) endif LicenseInstallDir = $(TclExtLibDir)/$(TclExtDir) Plist = $(SRCROOT)/$(ProjectPlistName).plist ifdef CvsRoot ScmGet = $(CVS) -Q -d '$(CvsRoot)' export $(if $(CvsTag),-r '$(CvsTag)',-D '$(ImportDate)') PlistSourceKey = OpenSourceCVS endif ifdef SvnUrl ScmGet = $(SVN) -q export -r '{$(ImportDate)}' '$(SvnUrl)' PlistSourceKey = OpenSourceSVN endif ifndef ScmGet Fetch = $(CURL) -L -s -S $(Url) PlistSourceKey = OpenSourceURL PlistSourceValue = $(Url) ifndef TEApotVersion ifndef ExtractedDir ExtractedDir = $(UrlFile) endif endif else Fetch = ($(ScmGet) $(ExtractedDir) && $(TAR) cz $(ExtractedDir) && $(RMDIR) $(ExtractedDir)) PlistSourceValue = $(ScmGet) $(ExtractedDir) endif ifndef ExtractedDir ExtractedDir = $(Project) endif ## # Commands ## PATCH ?= /usr/bin/patch CURL ?= /usr/bin/curl CVS ?= /usr/bin/cvs SVN ?= /usr/bin/svn UNZIP ?= /usr/bin/unzip SHA1 ?= /usr/bin/openssl sha1 DATE ?= /bin/date ## # Targets ## fetch_targets := fetch extract wipe install-license extract:: $(SRCROOT)/$(Project) $(SRCROOT)/$(Project): @echo "Extracting $(Project)..." $(_v) cd $(SRCROOT) && $(UrlExtract) $(Project)$(UrlExt) && $(RM) $(Project)$(UrlExt) && \ if [ ! -d $(Project) ]; then $(MV) $(ExtractedDir) $(Project); fi $(_v) shopt -s nullglob; for p in $(SRCROOT)/$(Project)*.diff; do \ $(PATCH) -d $(SRCROOT)/$(Project) -Np0 < $${p} && $(RM) $${p}; done ifdef Configure ifneq ($(Configure),:) ifdef TEA_TclConfig $(_v) $(TEA_TclConfig)/updt_tcl_m4.sh $@ endif $(_v) $(CHMOD) +x $(Configure) endif endif wipe:: cd $(SRCROOT) && $(RMDIR) $(Project) install-license:: $(_v) $(MKDIR) $(DSTROOT)$(LicenseInstallDir) && \ $(INSTALL_FILE) $(SRCROOT)/$(Project)/$(License) $(DSTROOT)$(LicenseInstallDir)/$(Project).txt fetch:: SRCROOT = $(CURDIR) fetch:: $(SRCROOT)/$(Project)$(UrlExt) $(SRCROOT)/$(Project)$(UrlExt): @echo "Fetching $(Project)..." $(_v) cd $(SRCROOT) && $(Fetch) > $(Project)$(UrlExt) @ if [ ! -f $(Plist) ]; then printf '\n\n\n\n\n' > $(Plist); fi @ sha="$$(cat $(SRCROOT)/$(Project)$(UrlExt) | $(SHA1))" &&\ awk '/^\t/ {s=$$0; do {getline; s=s"\n"$$0} while($$0 !~ /^\t<\/dict>/);'\ 'if (match(s,/OpenSourceProject<\/key>\n\t+$(ProjectPlistName)<\/string>/)) {x=1;'\ 'sub(/OpenSourceVersion<\/key>\n\t+[^\n]*<\/string>/,"OpenSourceVersion\n\t\t$(Release)",s);'\ 'sub(/$(PlistSourceKey)<\/key>\n\t+[^\n]*<\/string>/,"$(PlistSourceKey)\n\t\t$(PlistSourceValue)",s);'\ 'sub(/OpenSourceSHA1<\/key>\n\t+[^\n]*<\/string>/,"OpenSourceSHA1\n\t\t'"$${sha}"'",s);'\ 'sub(/OpenSourceImportDate<\/key>\n\t+[^\n]*<\/string>/,"OpenSourceImportDate\n\t\t'"$(ImportDate)"'",s);'\ '}; print s; next}; /^<\/array>/ && !x {print "\t\n'\ '\t\tOpenSourceProject\n\t\t$(ProjectPlistName)\n'\ '\t\tOpenSourceVersion\n\t\t$(Release)\n'\ '\t\tOpenSourceWebsiteURL\n\t\thttp://$(Project).sourceforge.net/\n'\ '\t\t$(PlistSourceKey)\n\t\t$(PlistSourceValue)\n'\ '\t\tOpenSourceSHA1\n\t\t'"$${sha}"'\n'\ '\t\tOpenSourceImportDate\n\t\t'"$(ImportDate)"'\n'\ '\t\tOpenSourceLicense\n\t\tTcl\n'\ '\t\tOpenSourceLicenseFile\n\t\t$(Project).txt\n'\ '\t"}; {print}' $(Plist) > $(Plist).1 && $(MV) $(Plist).1 $(Plist) .PHONY: $(fetch_targets) .NOTPARALLEL: