######################################################################## # COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED. # # Module name : jats.sh # Module type : Makefile system # Compiler(s) : n/a # Environment(s): jats # # Description : This package extends the JATS toolset at build time # It provides additional directives to the JATS makefiles # to simplify the directives. # # The directive matches up with a run-time tool to # do the bulk of the work. # # Operation : This package adds the JATS directive MakeDebianPackage # When used the directive will use GenerateFiles to invoke # a script (DebianPackager.pl) to actually do the hard work. # # Syntax : MakeDebianPackage (, Options+); # Where Options may be one of: # --Script=PackagerScript - Mandatory. Name of a the packaging script # --Name=Name - Debian Package name(optional) # --Variant=Text - Package Variant(optional) # --VersionPrefix=Text - Prefixes the version with the passed text(optional) # --ExtDesc=Text - Stored in the variable $opt_extdesc availabe in the # packaging script(optional) # --DeployMode - Create Deployable packages(optional) # Default for native targets # These are: # * Packaged into the root of target pkg # * Have P or D in the name # --NoDeployMode - Create packages that cannot be directly deployed # Default for embedded devices # --NoArch - Marks the package as having no specific architecture # # --TarFile[=TemplateName] - Create named .tgz file, of the data area [not Debian scripts] # --TarFile - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM # --TarOnly - Suppress the Debian Build # # --ZipFile[=TemplateName] - Create named .zip file, of the data area [not Debian scripts] # --ZipFile - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM # --ZipOnly - Suppress the Debian Build # # --ImageOnly - Only generate the filesystem image. No Tar, NoZip, NoDebian ... # --DirectPkg - Construct directly into the pkg directory within the output . No Tar, NoZip, NoDebian ... # # # Templates may contain: # PACKAGE # VARIANT # VERSION # PLATFORM # TYPE # ARCH # #......................................................................# require 5.006_001; #use strict; use warnings; #use PackagerUtils; #------------------------------------------------------------------------------- # Function : MakeDebianPackage # # Description : Create a Debian Package # # Inputs : See above # # Returns : Nothing # sub MakeDebianPackage { my( $platforms, @elements ) = @_; Debug2( "MakeDebianPackage($platforms, @elements)" ); return if ( ! ActivePlatform($platforms) ); my $build_name = $::ScmBuildPackage; my $build_version = $::ScmBuildVersionFull; my $build_variant = ''; my $build_version_prefix = ''; my $build_extdesc = ''; my $name_set=0; my $variant_set=0; my $version_prefix_set=0; my $extdesc_set=0; my $deploy_mode = GetGlobalOption('DEBIAN_PACKAGE_DEPLOYABLE', 0); my $tarOnly; my $tarFileName = ''; my $zipOnly; my $zipFileName = ''; my $imageOnly; my $directPkg; my @outputFiles; my @optArgs; my $noArch; my @arglist; my $rpmScript; my $debianScript; my $script; # # Collect user arguments # They are all processed within the toolset # foreach ( @elements ) { push @arglist, $_; if ( m/^--Script=(.+)/i ) { ReportError ("MakeDebianPackage: --Script. Debian script name already set") if $debianScript; ReportError ("MakeDebianPackage: --Script. RPM script name already set") if $rpmScript; $debianScript = $1; $rpmScript = $1; pop @arglist; } elsif ( m/^--RpmScript=(.+)/i ) { ReportError ("MakeDebianPackage: --RpmScript. RPM script name already set") if $rpmScript; $rpmScript = $1; pop @arglist; } elsif ( m/^--DebianScript=(.+)/i ) { ReportError ("MakeDebianPackage: --DebianScript. Debian script name already set") if $debianScript; $debianScript = $1; pop @arglist; } elsif ( m/^--Name=(.+)/i ) { $build_name = $1; $name_set++; } elsif ( m/^--Variant=(.+)/i ) { $build_variant = $1; $variant_set++; } elsif ( m/^--VersionPrefix=(.+)/i ) { $build_version_prefix = $1; $version_prefix_set++; } elsif ( m/^--ExtDesc=(.+)/i ) { $build_extdesc = $1; $extdesc_set++; } elsif ( m/^--(No)?DeployMode/i ) { $deploy_mode = ! defined($1); } elsif ( m/^--NoArch$/i ) { $noArch = 1; } elsif ( m/^--TarOnly$/i ) { $tarOnly = 1; } elsif ( m/^--TarFile(=(.*))?/i ) { $tarFileName = defined($1) ? $2 : 'DEFAULT'; } elsif ( m/^--ZipOnly$/i ) { $zipOnly = 1; } elsif ( m/^--ZipFile(=(.*))?/i ) { $zipFileName = defined($1) ? $2 : 'DEFAULT'; } elsif ( m/^--ImageOnly$/i ) { $imageOnly = 1; } elsif ( m/^--DirectPkg$/i ) { $directPkg = 1; } elsif ( m/^--/ ) { ReportError("MakeDebianPackage. Unknown option: $_"); } else { ReportError("MakeDebianPackage. Unknown argument: $_"); } } # # Sanity test # ReportError ("MakeDebianPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' && !($zipOnly || $tarOnly || $imageOnly || $directPkg) ); ReportError ("MakeDebianPackage: Script name not defined") unless ( $debianScript || $rpmScript ); ReportError ("MakeDebianPackage: --Name option can only be used once") if ( $name_set > 1 ); ReportError ("MakeDebianPackage: --Variant option can only be used once") if ( $variant_set > 1 ); ReportError ("MakeDebianPackage: --VersionPrefix option can only be used once") if ( $version_prefix_set > 1 ); ReportError ("MakeDebianPackage: --ExtDesc option can only be used once") if ( $extdesc_set > 1 ); ReportError ("MakeDebianPackage: --DirectPkg cannot be used with Tar options") if ( $directPkg && ($tarOnly || $tarFileName) ); ReportError ("MakeDebianPackage: --DirectPkg cannot be used with Zip options") if ( $directPkg && ($zipOnly || $zipFileName) ); ReportError ("MakeDebianPackage: --ImageOnly cannot be used with Tar options") if ( $imageOnly && ($tarOnly || $tarFileName) ); ReportError ("MakeDebianPackage: --ImageOnly cannot be used with Zip options") if ( $imageOnly && ($zipOnly || $zipFileName) ); ReportError ("MakeDebianPackage: --ZipOnly used without --ZipFile") if ( ($zipOnly && ! $zipFileName) ); ReportError ("MakeDebianPackage: --TarOnly used without --TarFile") if ( ($tarOnly && ! $tarFileName) ); ReportError ("MakeDebianPackage: --DirectPkg cannot be used with --ImageOnly") if ( $directPkg && $imageOnly ); ErrorDoExit(); # # Determine what we are really doing # Under Redhat we will generate an RPM # if ( ActivePlatform('PKG_RPM') ) { return unless (defined $rpmScript); return MakeRpmPackage ($platforms, "--Script=$rpmScript", @arglist ); } return unless (defined $debianScript); $script = $debianScript; ErrorDoExit(); # # If the platform cannot generate a native installer then (silently) ignore the request # unless the user has specified a --TarOnly # my $canGenerateInstaller = ActivePlatform('PKG_DEB'); if ( !$canGenerateInstaller && !$tarOnly && !zipOnly) { Verbose ("MakeDebianPackage: Installer not builadble for this platform"); return; } # # Build up the build name # Add variant to base name. # if ( $build_variant ) { $build_name .= '-' . $build_variant; } # # Build up the version # Add the version prefix to the base version if ( $build_version_prefix ) { $build_version = $build_version_prefix . '-' . $build_version; } # # Sanity check the package name and version # Debian has stricter requirements than JATS # Name: Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.). # Release Manager does not allow '.' # Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit # # Allow ( and cleanup ) # ERGxxxxx -> erg-xxx # VIXxxxxx -> vix-xxx # Whitespace -> - # _ -> - # Remove multiple '-' characters # Lowercase all text # # # Convert the build_name to a form that is Debian complient # $build_name = canonicalName ($build_name, 'Debian'); # # Sanity test the version information # unless ( $build_version =~ m/^[0-9][-+:.A-Za-z0-9]+$/ ) { Error ("Package Version does not conform to Debian Requirements", "Must only contain: (a-zA-Z) (0-9), - and .", "Must start with a number", ); } # # Create the name of the target package # The form of the name is of a fixed form. # # Note: "_" used since this is the format of dpkg-name # Note: dpkg-name generates: Name _ Version _ Architecture [ _ Type ] # # my $PkgType = $deploy_mode ? ( '_' . '$(GBE_TYPE)' ) : '' ; my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmTarget); my $Platform = $::ScmPlatform; if ($noArch) { $PkgArch = 'all'; $Platform = 'all'; $PkgType = ''; push @optArgs, "-NoArch"; } my $PkgName = "${build_name}_${build_version}_${Platform}${PkgType}.deb"; push @optArgs, "-PkgArch=$PkgArch"; unless ($tarOnly || $zipOnly || $imageOnly || $directPkg) { push (@outputFiles, $PkgName); push @optArgs, "-Output=--GeneratedProg{$PkgName}"; } # # Create name for the optional TGZ file # Allow user to specify parts of the name symbolically # if ($tarFileName) { if ($tarFileName eq 'DEFAULT') { $tarFileName = 'PACKAGE_VERSION_PLATFORM'; if ($deploy_mode && ! $noArch) { $tarFileName .= '_TYPE'; } } if ($noArch) { $PkgArch = 'all'; } $tarFileName =~ s~PACKAGE~${build_name}~g; $tarFileName =~ s~VERSION~${build_version}~g; $tarFileName =~ s~PLATFORM~${Platform}~g; $tarFileName =~ s~ARCH~${PkgArch}~g; $tarFileName =~ s~TYPE~\$(GBE_TYPE)~; $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~; push @outputFiles, $tarFileName; push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}"; # push @optArgs, "-TarFile=$tarFileName"; push (@optArgs, '-TarOnly' ) if $tarOnly; } # # Create name for the optional ZIP file # Allow user to specify parts of the name symbolically # if ($zipFileName) { if ($zipFileName eq 'DEFAULT') { $zipFileName = 'PACKAGE_VERSION_PLATFORM'; if ($deploy_mode && ! $noArch) { $zipFileName .= '_TYPE'; } } if ($noArch) { $PkgArch = 'all'; } $zipFileName =~ s~PACKAGE~${build_name}~g; $zipFileName =~ s~VERSION~${build_version}~g; $zipFileName =~ s~PLATFORM~${Platform}~g; $zipFileName =~ s~ARCH~${PkgArch}~g; $zipFileName =~ s~TYPE~\$(GBE_TYPE)~; $zipFileName .= '.zip' unless $zipFileName =~ m~\.zip$~; push @outputFiles, $zipFileName; push @optArgs, "-ZipFile=--GeneratedProg{$zipFileName}"; push (@optArgs, '-ZipOnly' ) if $zipOnly; } # # Only generating an image # No output files created # if ($imageOnly) { push (@optArgs, '-ImageOnly' ); push (@optArgs, '--NoGenerate' ); } if ($directPkg) { push (@optArgs, '-DirectPkg' ); push (@optArgs, '--NoGenerate' ); } # # Simply use Generate Files # With lots of options # Src ( '*', $script ); GenerateFiles ('*', "--Tool=DebianPackager.pl", # Associated tool "--AutoGenerate", # Build when needed "--UnknownPreq", # Always build "--Clean", # Script supports jats clean "--Text=Debian Package", # Display when building '--Var(BuildName)', # Target Package '--Var(BuildVersion)', # Target Version '--Var(Platform)', # Target platform '--Var(Product)', # Target product '--Var(Target)', # Underlying Target '--Var(Type)', # Build Type '--Var(Verbose)', # Verbose operation '--Var(InterfaceDir)', # Interface Directory '--Var(InterfaceIncDir)', '--Var(InterfaceLibDir)', '--Var(InterfaceBinDir)', '--Var(LibDir)', # My Artifacts '--Var(BinDir)', '--Var(PackageDir)', # My Package '--Var(PackageLibDir)', # My Package Library '--Var(PackageBinDir)', # My Package Bin '--Var(PackagePkgDir)', # My Package/pkg.target '--Var(LocalIncDir)', # Installed Artifacts '--Var(LocalLibDir)', '--Var(LocalBinDir)', "-genDeb", # Type to generate "-Script=--Prerequisite($script)", # Packager script "-Name=$build_name", # Massaged Package Name "-Version=$build_version", # Massaged Version "-Variant=$build_variant", # Variant Name "-VersionPrefix=$build_version_prefix", # Version Prefix "-ExtDesc=$build_extdesc", # External Description of Package @optArgs, # Optional args ); # # The Packager has created a binary in the 'PROG' directory # Lets package it as a program. # if ($deploy_mode) { PackageFile ('*', @outputFiles ); } else { PackageProg ('*', @outputFiles ); } } 1;