Image build-system for settopboxes sh4 based remake of duckbox tdt
Please read the following readme carefully if you still have question create an issue with question tag на русском, in english, auf deutsch !
Preparation
- To avoid data loss I recommend you to run this build system under individual user. So these build scripts have no chance to mess in your main home directory !
- Your host system requires some packages. Run
sudo ./setuptdt.sh
. If don't like to run unknown scripts under root install them manually
That's it, now start toolchain
2. Generate config: run make -f Makefile.setup xconfig
or make -f Makefile.setup menuconfig
3. Generate core Makefile run make -f Makefile.setup
4. Add make compleshion by TAB: source make-completion.sh
5. To build image exec buildsystem with make target-image
6. A lot of make targets are available
This toolchain is based on GNU Make and small perl preporcessor for generating make files. The first section is about our preprocessor (Smart-rules) and the second one is about [(Makefile conventions)](#Makefile conventions)
Smart-rules is Makefile preprocessor written in perl, it helps to write simpler Makefiles.
Makefile.pre --> |smart-rules.pl| --> Makefile
You must understand that firstly it expands all smart-rules macroses, and secondly make evaluates Makefile variables.
It has following features:
rule[[
extract:http://project.com/prog-${PV}.tar.gz
file://hello_world.c
patch:file://fixqq.diff
]]rule
Rules are separated by line break, all trailing white-spaces are ignored, use them for prettier indentation. Use #
for comments, Makefile conditionals are not touched.
rule[[
<rule1> # this is comment
ifdef FEATURE_2
<rule2>
endif
...
...
...
]]rule
This macro defines variables for future use in Makefile. They are DEPENDS
, PREPARE
, INSTALL
and SRC_URI
. Additional special targets and variables also printed to Makefile.
variants are
command:arg1:arg2:...:url:url-arg1:url-arg2:....
url:url-arg1:url-arg2:.... # default is extract command with no arguments
command:arg1:arg2:... # some commands doesn't require url.
url is detected by protocol://path
pattern.
If ;
is found in rule it becomes a separator instead of :
.
Commands that result in PREPARE
variable
nothing|extract|dirextract|patch(-(\d+))?|pmove|premove|plink|pdircreate
- nothing
copy file to ${DIR}. No arguments, url required - extract
extract archive to $(workprefix). No arguments, url required - dirextract
extract archive to ${DIR}. No arguments, url required - patch or patch-%d
executepatch -p%d arg1 arg2 ...
url required, default patch level is 1 - pmove
executemv arg1 arg2
url not supported - premove
executerm -rf arg1
url not supported - plink
executeln -sf arg1 arg2
. url not supported - pdircreate
executemkdir -p arg1
url is not supported
Commands that result in INSTALL
variable
install|install_file|install_bin|make|move|remove|mkdir|link
- install
executeinstall arg1 arg2 ...
If url is not provided
or
executeinstall file arg1 arg2 ...
Where file is downloaded from url - install_file
executeinstall file -m644 arg1 arg2 ...
Where file is downloaded from url - install_bin
executeinstall file -m755 arg1 arg2 ...
Where file is downloaded from url - make
executemake arg1 arg2 ...
url is not supported - move
executemv arg1 arg2
url not supported - remove
executerm -rf arg1
url not supported - mkdir
executemkdir -p arg1
url is not supported - link
executeln -sf arg1 arg2
url not supported
these are most common tasks, see smart-rules.pl for details and feel free to add more.. However, some special rules is better to write directly to .mk file
Now consider sources that are supported. Each url creates rule for downloading file, and append it to DEPENDS
variable. Also url is appended to SRC_URI
variable for future use in opkg CONTROL file.
https|http|ftp|file|git|svn|local|localwork
http://
- http wget downloadhttps://
- https wget downloadftp://
- ftp wget downloadgit://www.gitserver.com/gitrepo:r=revision:b=branch:sub=subdir_in_git_tree:protocol=http
- revision, branch and subdirectory to use (arguments are optional).
- and protocol which git should use. (replaces 'git://' while fetch)
- use protocol=ssh to replace "git://" with "git@"
svn://www.svnserver.com/svnrepo:r=revision
- only revision option
file://
- file path prefixed with $(srcdir)/make/localwork://
- temporary file in ${DIR}local://
- not prefixed file name.
input
package[[ example_lib
PV_${P} = 1
PR_${P} = 2
$(TARGET_${P}).do_package:
echo ${PV}-${PR} > $(PKDIR)/etc/version
touch $@
]]package
output
PV_example_lib = 1
PR_example_lib = 2
$(TARGET_example_lib).do_package:
echo $(PV_example_lib)-$(PR_example_lib) > $(PKDIR)/etc/version
touch $@
package[[ package_name
line1
line2
...
]]package
It does replacement in the body:
${P}
-->package_name
${VARIABLE}
-->$(VARIABLE_package_name)
In make all variables are global, but in buildsystem we have a lot of pacakges with similar properties like version, release etc. So we must name variables like in output example, but we have a lot of same code for different packages and I want it to look the same ! Furthermore see next chapter about functions.
function[[ common_code
$(TARGET_${P}).do_compile:
cd ${DIR} && make
touch $@
]]function
package[[ pkg1
call[[ common_code ]]
$(TARGET_${P}).do_package: $(TARGET_${P}).do_compile
install data1 $(PKDIR)/usr/share
touch $@
]]package
package[[ pkg2
call[[ common_code ]]
$(TARGET_${P}).do_package: $(TARGET_${P}).do_compile
install 2.png $(PKDIR)/usr/share
touch $@
]]package
This macroses allows to define chunks of code for future use. Code block inside function is saved in memory and pasted instead of call.
Every package usually have some standart targets with typical things to do:
do_prepare
- Clean working directory, then sources extraction and patching.do_compile
- Configuring sources and building binaries.do_package
- Copying resulting files to$(PKDIR)
treedo_ipk
- Building package from$(PKDIR)
tree for futher installing in targetprefix rootdo_install
- Installing files to targetprefix by installing coresponding *.ipk
There are coresponding clean*_ targets... And more.