Using Experimental MacPorts Portfiles

Monday, 2007-05-07; 21:56:00


How to use portfiles that aren't in the official MacPorts repository

A long time ago in a rant far, far away, I railed on the fact that there didn't seem to be any good scanning software for Mac OS X. I tried out VueScan, which was given a 4 out of 5 average rating by over 2500 users that left feedback, but ended up being a piece of crap anyway. I tried SilverFast, which gives you a tailored download for your specific device and didn't even work. I tried HP's own ImageZone software which doesn't do any scanning. I tried SANE, an open-source project that provides lots of scanner drivers, to no luck. And lastly I tried installing hpoj, a project funded by HP and designed to provide open source printing and scanning software for all of HP's printers, which utterly failed.

A couple months later, I posted a follow-up to my rant. I had filed a bug to request a port of hpoj on DarwinPorts, and a guy named Adam Schenker had done some preliminary work on porting hplip to DarwinPorts. hplip was, apparently, the successor to hpoj, and claimed to offer scanning support for my *cough* HP PSC 1210 all-in-one printer. I also mentioned that Readiris Pro seemed to use the HP scanning software without installing the annoying parts (like the startup item that persistently asked you to set preferences and did at each startup and didn't tell you where it lived so you could trash it).

Well a year and two days later, I decided I would check out Schenker's work to see if I could get scanning to work on my PSC 1210. The reason? The MacBook that I have on loan from the elementary school where I work had to be sent in for repairs. (There was nothing wrong with it; apparently, 1st generation MacBooks that have a 1.83 GHz or 2 GHz processor need to have their heat sink replaced; a defect in the design can cause the MacBooks to overheat and cause physical damage. Since the school's warranty is running out on these computers, we want to send them in for pre-emptive repair so that we don't get stuck with expensive bills down the road.)

So currently I only have my iMac G5 to use, which is my main computer anyway. However, I had been doing some scanning on the laptop using the official HP software. I was OK with installing it on there since it wasn't my main computer, and, surprisingly, it seems that at the very least, the annoying startup item doesn't come up anymore. Which is good.

But I'm still wary of installing the HP software on my iMac G5, so I decided today, since I wanted to scan something, that I would try to get the experimental port of hplip working. The problem is, this port isn't in the official MacPorts (né DarwinPorts) database. So installing the patch via the normal methods doesn't work. And after looking around the internets, I couldn't find any very good step-by-step instructions that show you how to use an experimental patch that has been posted to MacPorts.

This entry is an attempt to rectify this situtation. Maybe someone else will find it useful. I'll use hplip as an example throughout the steps.

(Please note: the one resource that was very helpful was Geoffery Ericksson's page in which he creates a simple portfile. This didn't completely answer all my questions, but it did help me get past a lot of my problems. Thanks, Geoffery!)

1. The first thing to do, obviously, is to download MacPorts and install it if you haven't already. This is easy: it's a standard Mac OS X installation package which you can download at the MacPorts website.

2. Now download the portfile and any supporting files. These will probably be attached to a bug ticket that requested the port in the first place. For example, my request ticket for hpoj has a number of attachments, all submitted by Schenker. You'll notice that all modifications have been preserved, too. So just download the latest versions; in hplip's case, I need to get "patch-io_hpiod_device.4.cpp" and "Portfile.7". (Also note: when you click on these links, the files get displayed in a special viewer in your browser. To actually download the files, scroll to the bottom of this viewer page and click the "Original Format" link under the "Download in other formats:" heading.)

3. Rename the downloaded files correctly. The portfile should always just be named "Portfile". In my case, I had to delete the ".7" suffix. As for the patch, you would guess that I need to delete the ".4", and you'd be right. You can find the expected names for the patchfiles by opening the portfile, and looking at the filenames listed after the "patchfiles" key. (The patchfile consists of a series of key-value pairs, one pair on each line, where the key is placed at the start of the line, the value at the end, and some whitespace in between.)

4. Set up a root folder for your local MacPorts repository. I chose to create a folder called "DarwinPorts" in my home folder, and then I used another folder called "local-sources" inside the "DarwinPorts" folder to serve as the root folder of my local MacPorts repository. This mimics Ericksson's method. You can choose whatever root folder you like.

5. Set up the directory structure for the portfiles you'll be adding to your local repository. To do this, open up each of the portfiles you want to use. Then look for the "categories" key in the portfile, and see what the value is. In my case, the experimental portfile for hplip is "print". So inside my "local-sources" folder, I created a "print" folder, and inside that I created an "hplip" folder. I also created a folder called "files" inside the "hplip" folder. This was necessary because the hplip port has a patchfile associated with it as well. All patchfiles should go in this "files" folder. (I figured this out by looking at the example portfile located at /opt/local/var/db/dports/sources/rsync.rsync.darwinports.org_dpupdate1/base/doc/exampleport/Portfile which Ericksson referenced.)

6. Place the portfiles and patchfiles in the appropriate places. Your portfile should go directly in the port folder. In my case, my portfile would go inside "hplip". Patchfiles should go inside the "files" subdirectory of your port folder. Thats where I placed my "patch-io_hpiod_device.cpp" file.

7. Notify MacPorts of your local repository. To do this, use the Terminal command open -a TextEdit /opt/local/etc/ports/sources.conf to open the "sources.conf" file which tells MacPorts where to look for portfiles. On a new line at the end of the file, put in a file: URL that points to the root folder of your local repository. In my case, I added "file:///Users/simone/DarwinPorts/local-sources/" to the sources.conf file. Then save and quit TextEdit.

8. Index your local repository. As Ericksson details on his page, this is simply a matter of issuing the Terminal command portindex /path/to/root/folder/of/local/repository . In my case, the command was portindex ~/DarwinPorts/local-sources/ . This command will create a "PortIndex" file inside your repository's root folder. It should also tell you that your portfiles were successfully parsed. If you see a zero for the number of successfully parsed ports or you see some ports failed, make sure that you've set everything up correctly as in steps 1-6.

9. Now, you're ready to install! Yay! Now you just issue the Terminal command sudo port install port-name . For me, it was sudo port install hplip . If the portfile was set up correctly, as it was in hplip's case, MacPorts should download and install all the dependencies, and then it will install your experimental port. Note that you might need to do other things at the end of the installation in order to properly set up your installed software. For example, hplip prints a message during installation that you need to tell launchd, Mac OS X's daemon that controls when other services need to be launched, that it should launch hplip and that it should do so on startup as well. The command for that is sudo launchctl load -w /Library/LaunchDaemons/org.macports.hplip.plist , but obviously this will not be the case for other ports. Make sure you've followed any other instructions to finish setting up your installed port.

Now you're done! Woo!

Now for the bad news: my PSC 1210 still doesn't work with hplip installed. hplip works in concert with SANE which is exposed via Mac OS X's Image Capture application, and it just says that another application is using the SANE scanning software. Boo. Is it possible that somehow my manual installation of SANE is interfering? *shrug*

Maybe I'll try and update the port request with my experiences, but I can't seem to figure out how to do that now that DarwinPorts moved to Mac OS Forge and was renamed MacPorts. I did try manually modifying the portfile to download the latest release of hplip, 1.7.4a, but I'm getting some errors during the install.

One last thing: you should be able to access the man pages for MacPorts by issuing the Terminal command man port . If you get an error saying that no man pages are available, open your .profile and make sure that "/opt/local/bin" and "/opt/local/sbin" are in your PATH. If you're using bash, the standard shell in Tiger, the first line in your ".profile" file should be something like this:

export PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/bin:/opt/local/sbin

This is a colon-delimited list of paths in which executable files should be found, and it also affects where man pages are found. As you can see, "/opt/local/bin" and "/opt/local/sbin" are in this list at the end.

I initially had troubles accessing the man pages, but it turned out that the postflight script of the MacPorts installer tried to add the MacPorts folders to my ".profile" file automatically, but failed to do so correctly.


Technological Supernova   Tips   Older   Newer   Post a Comment