CARDS 3.0.0
Package manager for the NuTyX GNU/Linux distribution
|
You don't need to be an experienced programmer to contribute to this project.
A rudimentary knowledge of the bash scripting language is good enough. If you have no knowledge of bash, this article will explain the basic principles for creating a recipe without going crazy.
The bash langage is used to edit a recipe and to generate a package from it. The fact that bash is a programming language might seem frightening to some potential users, who might think: "I don't know how to program". There are three reasons why you should not feel scared:
So let's start our little course on the bash programming
This article will explain some basic features of the language that are good to knows to comprehend the syntax of a recipe:
All you need to do to declare a variable is this:
You declare the variable name by using the equals sign, with the name of the variable to the left of the sign and the value mypackage to the right.
So you know how to declare a variable; that's very nice, but how do you get at its content in order to use it?
To extract the content of a variable you use the dollar sign ($) with braces if required. Both forms are valid:
It is better to use the first form since otherwise, if the variable name contains an underscore, it will not be interpretated correctly by bash:
In order to see the result of this command, I suggest you create a little file containing this code. You can call the file DeclareVar
Now give the command:
When you construct a recipe, you will have access to a whole series of predefined variables.
PKG: Certainly the most often used, this defines the destination folder for the compiled files.
This folder then contains the file structure before it is packaged up
SRC: This variable defines the folder where all the source files are extracted.
It is therefore very useful when you need to loop through subfolders and then return at the end of the loop to where you started. This is also the variable which defines the current working directory for the main function of the recipe.
MAKEFLAGS: This variable is not used so often. It is initialized in the pkgmk configuration file. Its use is detailed in another article. For the time being, all you need to know is that it allows you to specify the extent of parallel compilation. There are others, but personally I see no need for them when constructing recipes.
To declare an array of strings (or anything else), you add parentheses:
This array source contains 2 variables: firefox.png and firefox.desktop. The source array from the recipe for the kernel provides a particularly good example:
Each line is a variable in its own right and can be accessed using the syntax:
You will notice that each variable can in turn contain other variables provided that they have been defined earlier.
To declare a function is almost as simple. You use parentheses when giving the name of the function; the function code is always enclosed in braces { etc }. A little example:
As you can see, it's very pretty and also contains a minimal recipe (without the variable declarations). Here you can see the essential use of the PKG variable.
We are now ready to learn what's a recept or a port