Can I install a program's source as a package?

Hello, I’d like to install Emacs’ source code in order to get access to function definitions in the C source code through its help system. Is there a neat way to do it so that it is always up-to-date with the application binary?

2 Likes

Although there are some packages with a devel and or src sub-package. (mostly for reference/headers)
This is not really a good use for a package manager.

I would recommend using GIT (or whatever VCS applies) and regularly pulling the latest version and check out the tag of the version currently installed.

Emacs does have a devel package. Why do you say it wouldn’t be a good use of the package manager to install it? I wouldn’t tinker and build Emacs from source, I’d just like to have an “install and forget” bundle of application and relative code for reading it.

1 Like

You of course could do it, but package/dependency managers are really made for managing binaries and their dependencies.

Using git would just be easier, and using something that is specifically made to do that sort of thing.
If you want to keep it up to date with the version currently installed you could for example make a script that figures out the version number of the currently installed package, and gets the appropriate source.
(you could use a dnf hook for that; but i don’t have any experience with that)

As far as i see it the source packages are only for libraries like the Java standard library and the devel packages only provide headers for public APIs to link against.

As far as i see it the source packages are only for libraries like the Java standard library and the devel packages only provide headers for public APIs to link against.

Yes, I took a look at the emacs-devel package and it only contains a header file. In the end I downloaded the source code and put it in a directory whose path I assigned to the variable find-function-C-source-directory in Emacs, and it works fine.

Thanks for your help. (-:

1 Like

I see what you are looking for, but things are not quite that simple. Programs like Emacs certainly would benefit from having the source code tree provided as a documentation package. If you want to have the source tree of your binary package available, you need to use the corresponding Fedora source package.

To make a source tree available you first need to install rpmdevtools and rpm-build,

You can download the source package with dnf download --source emacs and then install that package to your home directory: rpm -ivh emacs-26.2-1.fc30.src.rpm or whatever your version happens to be.

At this point the source tree is not yet available so first we have to make sure that all the build dependencies are met: sudo dnf builddep emacs

And now you can build the actual source tree: rpmbuild -bp rpmbuild/SPECS/emacs.spec

The source tree will now be found at ~/rpmbuild/BUILD/emacs-26.2

But yes, the Emacs source tree is used as a documentation so a documentation package would be quite useful.

3 Likes

Thanks Jyrki! Can I ask you a couple more questions?

  1. Just to be sure, the process you described just makes the source code available, without installing or building the binary, right?
  2. What happens when DNF upgrades emacs, is the source code automatically upgraded too?

Yes, the -bp option just builds the source tree. See rpmbuild --help for more info.

When the binary package is updated the source package will not be automatically upgraded but dnf download --source, rpm -ivh and rpmbuild -bp will do the trick.

1 Like

When the binary package is updated the source package will not be automatically upgraded but dnf download --source , rpm -ivh and rpmbuild -bp will do the trick.

Hi Jyrki, a new version of Emacs has been released and your instructions worked. But now how do I remove the old version’s tree? (I assume there’s a cleaner way than finding and deleting the files manually.)

rpmbuild is far from perfect :frowning: The SOURCES directory will eventually become a big mess with files from different source packages all in the same directory. A good improvement would be to have a separate directory under SOURCES for each source package.

Well then, I went with find ~/rpmbuild -name "emacs-26.2*" -print0 | xargs -0 trash-put, emacs-26.2 being the obsolete package, and it looks like it did the job. (trash-put comes from the trash-cli package.)

Thanks (-:

Another good alternative is to use mock if you’re trying to rebuild packages instead of just downloading the source code. It’s quite neat and allows you to build both release and debug versions of packages even for other architectures.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.