Home > Articles > Operating Systems, Server

  • Print
  • + Share This
From the author of

Project: Modifying a Package

In this project, you'll actually modify an existing package. The modifications will be trivial (and not very useful), but this will take you through the steps required to make minor modifications. The examples are given for an OpenLinux system so that specific directories can be listed, but other RPM-based distributions are very similar.

  1. Install the sources for ed:

    # rpm -i /mnt/cdrom/Packages/RPMS/ed-0.2-5.src.rpm

  2. Extract the sources so that you can work on them:

    # cd /usr/src/OpenLinux; rpm -bp SPECS/ed.spec

  3. Make a copy to work on (you don't want to work on the sources in the BUILD directory):

    # cd BUILD; cp -a ed-0.2 /usr/local/src

  4. Make main.c writeable:

    # cd /usr/local/src/ed-0.2; chmod u+w main.c; vi main.c

  5. Add a line to say, "Hey, I modified ed!" to the usage() routine, as shown in Listing 2.

  6. Listing 2  The First Part of the usage() Routine in ed-0.2/main.c

    usage (status)
    int status;
    if (status != 0)
    fprintf (stderr, "Try `%s-help' for more information.\n", program_name);
    printf ("Hey, I modified ed!\n");
    printf ("Usage: %s [OPTION]... [FILE]\n", program_name);
  7. Test your changes:

    # ./configure && make && ./ed-help

    Hey, I modified ed!
    Usage: ./ed [OPTION]... [FILE]

  8. Clean up the tree and make a patch file:

    # make distclean; rm stamp-h
    # diff -cr /usr/src/OpenLinux/BUILD/ed-0.2 . > /usr/src/OpenLinux/SOURCES/ed-mypatch.patch

  9. Update the spec file to update the release number and include your new patch (see Listing 3). To prevent confusion, you should add your initials to the release number.

  10. Listing 3  Portion of ed.spec

    Summary: GNU Line Editor
    Name: ed
    Version: 0.2
    Release: 5ran
    Group: Textprocessing/Editor
    Source0: ftp://prep.ai.mit.edu/pub/gnu/ed-0.2.tar.gz
    Patch0: ed-mypatch.patch
  11. Build the package to the installation stage:

    # rpm -bi SPECS/ed.spec

  12. Test the package:

    # /tmp/ed-0.2/bin/ed-help
    Hey, I modified ed!
    Usage: /tmp/ed-0.2/bin/ed [OPTION]... [FILE]

  13. Build the whole package, install, and enjoy!

    # rpm -ba SPECS/ed.spec
    # rpm -i RPMS/i386/ed-0.2-5ran.i386.rpm

I don't recommend actually installing this package because it's a rather silly patch, but that's how it would be done. Notice the 5ran in the name of the package, which comes from the Release line that we put in the spec file.

You can use these same techniques to make new packages. Generally the best way to do that is to use the spec files from your distribution as a guide. Copy what you need and change what is different for your program. Congratulations! You are now a software packager.

  • + Share This
  • 🔖 Save To Your Account