Creating a new package from scratch
From Gentoo Linux Wiki
- This page is a candidate for deletion
- Reason given: Not really Gentoo related. Belongs on a programming wiki.
- If you disagree with its deletion, please explain why on its discussion page.
- If you intend to fix it, please remove this notice, but do not remove this notice from articles that you have created yourself.
- Make sure no other pages link here and check the page's history before deleting.
This example shows how to create a new helloworld package from scratch.
Contents |
[edit] Create the development directory structure for the helloworld package
Before writing the code for the helloworld program, the directory structure for the helloworld package is first created:
[edit] Creating a project directory for the package
cd ~/ mkdir helloworld cd ~/helloworld
[edit] Create the development subdirectories for the new package
Next the directory infrastructure for the source code and supplementary files is created:
mkdir src
[edit] Create the source code files for the helloworld package
The development subdirectories for the helloworld package have been created. The next step is to make the package source directory current:
cd ~/helloworld/src
The hello.c source file for the new package can now be created:
/*
* hello.c
* This program outputs a message to the terminal
*
* (C) Copyright 2004 Mark Hobley
*
* This is free software. This file can be redistributed or modified
* under the terms of the GNU General Public Licence (Version 2)
* as published by the Free Software Foundation.
*
*/
#include <stdio.h>
main ()
{
printf("Hello World!");
return(0);
}
[edit] Create the Makefile.am file for the helloworld package
The Makefile.am file is used by the automake tool to create the project makefile entries used by the build scripts.
[edit] Create the Makefile.am file for the package sources
Make the source directory current before creating the makefile:
cd ~/helloworld/src vi Makefile.am
Create the Makefile.am file as follows:
bin_PROGRAMS = hello hello_SOURCES = hello.c
[edit] Use autoscan to scan the source code
[edit] Make the helloworld project directory current
Before using the autoscan tool, first make the helloworld project directory current:
cd ~/helloworld
[edit] Run the autoscan tool
Now run the autoscan tool:
autoscan
[edit] Create the configure.ac file
The autoscan tool will create a configure.scan file. Copy this file to create a configure.ac file for use by the autoconf tool as follows:
cp configure.scan configure.ac
[edit] Configure the package name and version number
The generated configure.ac file requires modification to change the default package name, version number and bug report email address information:
vi configure.ac
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
Modify these entries as follows:
AC_INIT(The helloworld example, 1.0.0, bugs-helloworld@foobar.com)
