views:

338

answers:

5

I am trying to download the source code for wget in Mac.

I managed to get the source code of wget in Ubuntu by

apt-get source wget

However, I have not managed to download source codes in Mac's terminal. I did not find the same utility in MacPorts.

+2  A: 

Most open source projects provide a compressed archive of their source code, or a readable version control repository. For instance, the source code for wget is available at http://ftp.gnu.org/gnu/wget/. All you need to do is decide which version you want to download and enter in the terminal window a command like

ftp http://ftp.gnu.org/gnu/wget/wget-1.10.2.tar.gz

You can then unpack the source code with a command like

tar xvzf wget-1.10.2.tar.gz

If the code is in a version control repository, then the project will also list the command you'll need to download the code. For instance, cvs2svn gives you the command

svn co --username=guest http://cvs2svn.tigris.org/svn/cvs2svn/trunk cvs2svn-trunk

There may be Mac-specific methods, but the beauty of what I described is that it works for any Unix-like environment.

Diomidis Spinellis
+2  A: 

AFAIK, MacPorts doesn't have a similar function to apt-get's source.

However, the source URL is in the Portfiles. You can view the portfile for a port by typing

cat `port file port_name`

in the terminal, for example:

cat `port file wget`

Or you can just install the port and find the source in /opt/local/var/macports/distfiles.

You might even be able to use the install command to just download (and not build or install) the port.

Can Berk Güder
Could you give an example of how your command works? Do you mean like $ cat `port NotSureWhichFileIshouldChoose devtodo`, where devtodo is the name of the program.
Masi
See updated answer. file is the name of the command, so that's a literal.
Can Berk Güder
There is also a `port cat` command in MacPorts.
Raim
+1  A: 

If you want an apt interface onto open source projects, look at Fink, a dpkg system for Mac OS X with various open source packages.

Graham Lee
+2  A: 

apt-get is a program for automatically downloading and installing software packages and their dependencies; it is only available on some Linux-based platforms like Debian and Ubuntu. Mac OS X has two similar utilities: Fink and MacPorts. Both serve the same purpose as apt-get. I personally prefer MacPorts because I think it has a nicer UI, but both pieces of software work more or less the same.

mipadi
Actually fink includes "apt-get" because it basically is dpkg+apt for OSX, but you can also fetch packages using the "fink" command itself.
harms
+6  A: 

MacPorts is a source-based package manager. That means that each time you install a package via MacPorts, it downloads the source, potentially patches it, configures it, builds it, installs it to a temporary location (so it can track which files the port needs), makes an archive of it, then installs that archive into the MacPorts root, which is usually /opt/local.

If you want to look at or edit the source before building it, you can execute a subset of the steps necessary to download and install it. port extract <name> will download and extract the source for the port, without actually building or installing it. You can then find the extracted source with port dir <portname>:

$ sudo port -v extract zlib
Password:
--->  Fetching zlib
--->  Verifying checksum(s) for zlib
--->  Checksumming zlib-1.2.3.tar.bz2
--->  Extracting zlib
--->  Extracting zlib-1.2.3.tar.bz2
$ ls $(port dir zlib)
Portfile    files  work
$ ls $(port dir zlib)/work
zlib-1.2.3
$ ls $(port dir zlib)/work/zlib-1.2.3
ChangeLog   as400  examples inftrees.h uncompr.c
FAQ  compress.c gzio.c  make_vms.com win32
INDEX    configure infback.c minigzip.c zconf.h
Makefile    contrib  inffast.c msdos  zconf.in.h
Makefile.in crc32.c  inffast.h old  zlib.3
README   crc32.h  inffixed.h projects zlib.h
adler32.c   deflate.c inflate.c qnx  zutil.c
algorithm.txt   deflate.h inflate.h trees.c  zutil.h
amiga    example.c inftrees.c trees.h

See the MacPorts guide for more information on developing ports, and also man port.

Brian Campbell
Thank you for the answer!
Masi