Last Edited: 04 July 2008 by hairywill
removed automatic cruft at the bottom about revisions etc. left over from import from old wiki

image

To convert Puppy into a complete compiler environment you will need to get the compiling addon file that corresponds with the version of Puppy that you are using, e.g. for Puppy 2.14 devx_214.sfs. So start downloading now, then read while you wait....

Download here:

For most every type of Puppy install (live-cd, frugal), save or copy the file to /mnt/home(if it doesn't exist then you probably have a full hard drive install, see below). This is where your personal storage file is, e.g. pup_save.2fs or pup001. Now if you're using Puppy 2.x and haven't saved your session somewhere then you need to do that first for Puppy to recognize the devx file. Now simply reboot back into Puppy to start compiling.

But for a full/option-2/normal hard drive install to Linux partition with Puppy 2.x, then follow the instructions at the bottom of Barry's page∞ for now but check back here later for a shortcut.
see also: http://www.murga-linux.com/puppy/viewtopic.php?t=16780

How to Test if devx is installed

Now that you've installed you devx module, it is time to test it to see if it works.

Quick Test

Open up rxvt and type 'cc' it should spit this back at you
cc: no input files
If it tells you 'command not found' then it has not installed properly.

Better Test

Save the following as test.c
If using Geany, set it it to C and test compile first

/* Example C program */

int main()

{ int i;
for (i = 0; i < 50000; i++)
{
printf ("%d",i);
printf (" Puppy is Great\n");
}
return 0;
}

in the same directory
open a terminal (Right click in the open folder/directory with Rox 2.5 /Window/terminal here)
and type

gcc test.c -o test

this will create a runnable file called "test"
the command

./test

will run it . . .

find a good tutorial e.g.

What does Compiling mean?

In a nutshell: Compiling is the process by which a program written in a human readable format is converted to a computer executable format.
For a full explanation read the Wikipedia: http://en.wikipedia.org/wiki/Compile

compiling...

you can write programs in assembler, which is almost "perfect" in the eyes of a computer, very close to binary code.

lda 02
sta #c000
lda #c001
cmp #c000
bne d000

But this is difficult to understand, in C it might look like this:
a=2;
b=c;
if (a != b){
my_subroutine();
}

This is easier to understand (high-level language), a simple comparison of two numbers, and depending on the result (if they are different), a sub-program is executed.

As computers do not understand "if" and don't have variables (C) but only a stack (assembler), the code must be translated from C to assembler or even better directly to binary code (assembler itself is not binary, but a very simple form of a "high-level-language" very close to binary code).

This translation is "compiling".
If you open the resulting "code" in a hexeditor, you will only see binary code, values from 0 to 255 "wildly mixed". The computer can understand this code, but no human can.

Why Compiling programs

Sometimes you will find that a program or driver that you need or want is not available for Puppy.
The good news is: If that application or driver is open source, you will have access to the source code to compile, but don't get put off by the long words. These days most open source applications have a very simple way to compile and install from source code.

How to Compile programs

Puppy 2
If you're running a liveCD or frugal/poor-man's/option-1/coexist install, stick the devx file in /mnt/home, in the same directory as pup_save.3fs and co.

That's always been the way to do it with these installations. You only need to put it in root when using an option-2 full-hd install.

Now, if you've got a multisession, I don't know exactly how that works. I imagine the same as the option-2 setup.

If you do have one of the latter two, did you say you were putting it in /root? If so, and that doesn't work, try / instead. As in the actual root, not /root.




Prerequisites:

The Puppy liveCD does not come with the compilation tools. For that you will need the file devx_201.sfs. [Note that Puppy 2.00 requires devx_200.sfs, Puppy 2.01 requires devx_201.sfs, etc. This is the naming convention for all extra sqaushfs files that allows puppy to recognize them. Puppy 1 versions use usr_devx.sfs, which does not follow this convention.]
The devx_201.sfs is not a standard requirement in Linux. It is just a clever way Barry (Puppy's creator) found to package all the development tools in an easy to install package. This package includes the tools, libraries and header files required to compile applications.

To install the usr_devx.sfs do the following:

  • Go to this download page and download the devx_201.sfs (http://www.puppyos.com/test/∞) or (http://www.puppylinux.org/user/downloads.php?cat_id=12∞)
  • Copy the downloaded file to the same place where your pupxxx.sfs file is located (e.g. pup001.sfs for puppy 1, pup_200.sfs for puppy 2.00, pup_201.sfs for puppy 2.01...). Or in a Hard Drive installation to the / folder. Or in /root on a liveCD.
  • Reboot puppy.

    or try this explanation



    Puppy has a full gcc make/compile/link suite, available as a scrunched file system. It builds most Linux packages from source using the standard "./configure", "make", "make install" incantation.

    The development environments for Puppy 2.00 and 1.xx are available at http://puppylinux.org/user/downloads.php?cat_id=12∞ . devx_201.sfs is at http://www.puppyos.com/test/∞ (and at my mirror page: http://s3.amazonaws.com/puppy/index.html∞ )

    To use it, put the devx_xxx.sfs or usr_devx.sfs file in the same place as your pup_save file, and reboot.



    Your application may have other dependencies. Make sure that those dependencies are present in Puppy or that you compile them before trying to compile the application. The ldd command is useful here. Google 'man ldd linux'. The command is available in Puppy, though the man page is not. As it displays a list of all packages required, and you are probably most interested in just those missing, try
    ldd `which mplayer` |grep not

    Note that the ` on each side of mplayer is a back quotes above the tab button, not regular single quotes. This tells it to run the ldd command on the results of the which command, so you don't have to first locate mplayer (in this example - replace mplayer with the program you wish to check dependencies for), the results of which are piped through the grep command which only lets through the results containing the word 'not'
    Example with results:

    ldd `which mplayer` |grep not
    libsmbclient.so.0 => not found

    Of course you could type in

    ldd /etc/local/bin/mplayer

    substituing your app and its path for /etc/local/bin/mplayer, and scan the resulting list manually (thanks for MU, or was it Lobster, who pointed out this simple trick... I like being lazy).

    To Compile:

    • Download source of the application or driver you need:
      It is usually recommended to download the stable version of the package. Only download the development or test versions if you really need them and know what you are doing.
    • Extract source from archive to a suitable location
      Most if not all the applications sources come packaged. Use the appropriate command to extract the source.
      It is Highly advisable to Extract the files to a new or empty folder.
      e.g.
      # mkdir /root/src
      # mkdir /root/src/packageName
      Then download the file to that folder
      # cd /root/src/packageName
      # tar -xvzf packageName.tar.gz
    • READ THE DOCUMENTATION INCLUDED IN THE SOURCE PACKAGE ESPECIALLY ANY INSTALL & README FILES
    • Open a terminal console (e.g. rxvt) and do the following:
      • Change directories to the directory where you extracted the source code
        e.g. cd /root/src/<appName>
      • Follow the compilation instructions included in the source package (README and INSTALL files)

    ....If you run into problems

    1. Remember the INSTALL & README's ? They usually have addresses of mailing lists you can search
    2. If you do not find the info you are after, try googling
    3. If this fails and you have no ideas make a post to the relevant mailing list
    4. If you get a reply and do not understand or you get no reply post to the puppy forums but please describe EXACTLY the errors you are getting, the version you are trying to compile, the steps you have taken so others may reproduce the same errors then be very very patient
    5. PLEASE DON'T SAY "I CAN'T COMPILE XYZ" "IT DOESN'T WORK" OR ANY OTHER 3 WORD PROBLEM. If you won't help yourself don't expect others to do so.
    6. Someone (other than me) make a suggestion that we should mayhaps start a wiki (do the wiki tiki!) on what we can compile in puppy and what we can't and any possible work arounds.
    7. SelfHostingPuppy



    Optimising

    This little detail is not on the "compiling for puppy" but it's a fairly important one:

    a lot of Makefiles will leave the "add debug symbol" option of gcc enabled (it's "-g"). This means that a alot of "text" information is added to your program to facilitate debugging, increasing the program file significanlty.

    When you compile for puppy before typing make (but after the ./configure step if it's part of the compiling steps) you should open Makefile and look for a line that sets the C flags (usually CFLAGS = ....).

    if the line include -g remove it and see how much space is gained. This will NOT change the behavior of the program.

    There are other optimizations that can be enabled, such as changing the optimizer setting. I find of a lot of program use -O2 by default, changing it to -Os will usually make a smaller program. In theory changing optimizer settings should not change the behavior of your program, however it is possible that it can have subtle side effects that the original programmer didn't test for.

    I'm really happy to see the source-sorcerer project, because now we can go in and check how each package was built, and make sure that each build is optimized.

    Optimazation options

    Categories

    CategoryDevelopment
    CategoryDocumentation