What compiler options were used for a given binary package?

This tutorial is about checking compiler options of binaries installed with pkgng or ports in FreeBSD 9.1. As an example Apache22 is used in this tutorial.

Reason this tutorial was written is to verify what Senior member @kpa stated in this post.
My other reason is that this article might be useful for other FreeBSD users :)

Written by Johan Havermans
April 30, 2013

Used sources
  • Comment of Senior member @kpa in forums.freebsd.org regarding next generation package manager pkgng
  • The FreeBSD handbook, 5.5 Using pkgng for Binary Package Management

Showing used compiler options of a binary (pkgng feature), using Apache22 as an example
On some FreeBSD systems, Apache22 is installed by default. You might be in a situation that you need to know what compiler options were used when a given binary was built. I am using Apache22 as an example here, but it should basically apply to other installed binaries on a FreeBSD system as well.
For software installed via ports, it is already possible to answer this question. For installed binaries, this was not possible until now: meet pkg Next Generation aka pkgng. Pkgng is a new package manager that is first introduced in FreeBSD 9.1. According to the FreeBSD book, pkgng will be the default package manager for FreeBSD 10.

Migrating from pkg_install based package manager to pkgng
Before you can use pkgng, you have to install it and convert your package database. This can be done in a few simple steps.

Obtaining pkgng
FreeBSD 9.1 and later includes a "bootstrap" utility for pkgng. The bootstrap utility will download and install pkgng.
To bootstrap the system, run:

[root@dmzsrv ~]# /usr/sbin/pkg

Existing FreeBSD installations require conversion of the pkg_install package database to the new format. To convert the package database, run:

[root@dmzsrv ~]# pkg2ng
Code:
...
Installing portupgrade-2.4.10.5_1,2... done
Installing postgresql-client-9.0.13... done
Installing python27-2.7.3_6... done
Installing ruby-1.8.7.371,1... done
Installing ruby18-bdb-0.6.6_1... done
Installing vim-lite-7.3.669_2... done
Conversion has been successfully finished
Your old packages database has been moved to: /var/db/pkg.bak.
[root@dmzsrv ~]#

This step is not required for new installations that do not have third-party software installed.

Important: This step is not reversible. Once the package database has been converted to the pkgng format, the pkg_install tools should not be used.

Note: The package database conversion may emit errors as the contents are converted to the new version. Generally, these errors can be safely ignored, however a list of third-party software that was not successfully converted will be listed after pkg2ng has finished. These must be fixed by hand.

Please be sure also to check your scripts and convert pkg_install, pkg_info, pkg_version, etc to their pkgng equivalents.

To ensure the FreeBSD Ports Collection registers new software with pkgng, and not pkg_install, FreeBSD versions earlier than 10.x require this line in /etc/make.conf:

Code:
WITH_PKGNG=yes

For more information, please read section 5.5 of the FreeBSD book: Using pkgng for Binary Package Management.

Show me some results
On a FreeBSD system with Apache22 installed via pkg_install (before the migration to pkgng), I checked the used compiler options by using the command in the first column. The output is also shown in the first column. I did the same for a vanilla port of Apache22. The command and output are shown in the second column.


Code:
Used compiler options binary                  Available compiler options port
[cmd]# pkg query -e "%n=apache22" "%n-%v %Ok %Ov"[/cmd]  [cmd][/usr/ports/www/apache22]# make showconfig[/cmd]
                                          ===> The following configuration options are 
apache22 2.2.24:                          available for apache22 2.2.24:
 AUTH_BASIC on                                AUTH_BASIC=on: mod_auth_basic
 AUTH_DIGEST on                               AUTH_DIGEST=on: mod_auth_digest
 AUTHN_ALIAS on                               AUTHN_ALIAS=on: mod_authn_alias
 AUTHN_ANON on                                AUTHN_ANON=on: mod_authn_anon
 AUTHN_DBD off                                AUTHN_DBD=off: mod_authn_dbd
 AUTHN_DBM on                                 AUTHN_DBM=on: mod_authn_dbm
 AUTHN_DEFAULT on                             AUTHN_DEFAULT=on: mod_authn_default
 AUTHN_FILE on                                AUTHN_FILE=on: mod_authn_file
 AUTHZ_DBM on                                 AUTHZ_DBM=on: mod_authz_dbm
 AUTHZ_DEFAULT on                             AUTHZ_DEFAULT=on: mod_authz_default
 AUTHZ_GROUPFILE on                           AUTHZ_GROUPFILE=on: mod_authz_groupfile
 AUTHZ_HOST on                                AUTHZ_HOST=on: mod_authz_host
.                                            .
.                                            .
.                                            .
OPTIONAL_FN_IMPORT off                       OPTIONAL_FN_IMPORT=off: mod_optional_fn_import
OPTIONAL_FN_EXPORT                           OPTIONAL_FN_EXPORT=off: mod_optional_fn_export
                                          ====> Options available for the multi PROXY:
                                          you have to choose at least one of them
 PROXY_AJP off                                PROXY_AJP=off: mod_proxy_ajp
 PROXY_BALANCER off                           PROXY_BALANCER=off: mod_proxy_balancer
 PROXY_CONNECT off                            PROXY_CONNECT=off: mod_proxy_connect
 PROXY_FTP off                                PROXY_FTP=off: mod_proxy_ftp
 PROXY_HTTP off                               PROXY_HTTP=off: mod_proxy_http
 PROXY_SCGI off                               PROXY_SCGI=off: mod_proxy_scgi
                                          ===> Use 'make config' to modify these settings

If we compare the compiler options in both columns, we see that they are both the same, so our Apache22 binary is compiled with the default compiler options. In my case, I need my Apache22 to proxy, so now I have the evidence that I have to recompile my Apache22 via ports.

Recompiling Apache22
Step 0. Remove existing Apache22 software (if any)
WARNING: we are using pkgng here! Remove Apache22 by typing:

[root@lansrv ~]# pkg delete apache22
Code:
Package(s) not found!
[root@lansrv ~]#

Or, if it was installed via ports:

[root@lansrv ~]# cd /usr/ports/www/apache22
[root@lansrv /usr/ports/www/apache22]# make deinstall
Code:
===>  Deinstalling for www/apache22
===>   apache22 not installed, skipping

Step 1. Compile and install Apache
cd into the Apache22 port directory

[root@dmzsrv]# cd /usr/ports/www/apache22

Restore the compiler options back to their default

[root@dmzsrv /usr/ports/www/apache22]# make rmconfig
Code:
===> No user-specified options configured for apache22-2.2.24

Modify compiler options via:

# make install clean

Check that the modules below are also checked
Code:
[X] SSL                     Enable mod_ssl
[X] PROXY                   Enable mod_proxy

And for mod_proxy, check these

Code:
[X] PROXY_CONNECT           Enable mod_proxy_connect
[X] PROXY_HTTP              Enable mod_proxy_http
What would I get if I check my Apache22 binary installed with ports, with the pkgng command for compiler options?

For FreeBSD, the result is the same whether a package is installed via ports or via pkg, so let see what the result will be if we type

[root@dmzsrv ~]# pkg query -e "%n=apache22" "%n-%v %Ok %Ov"
Code:
apache22-2.2.24 ACTIONS on
apache22-2.2.24 ALIAS on
apache22-2.2.24 ASIS on
apache22-2.2.24 AUTHNZ_LDAP off
apache22-2.2.24 AUTHN_ALIAS on
apache22-2.2.24 AUTHN_ANON on
apache22-2.2.24 AUTHN_DBD off
apache22-2.2.24 AUTHN_DBM on
apache22-2.2.24 AUTHN_DEFAULT on
...
apache22-2.2.24 PROXY on
apache22-2.2.24 REQTIMEOUT on
apache22-2.2.24 REWRITE on
apache22-2.2.24 SETENVIF on
apache22-2.2.24 SPELING on
apache22-2.2.24 SSL on
apache22-2.2.24 STATUS on
apache22-2.2.24 SUBSTITUTE off
apache22-2.2.24 SUEXEC off
apache22-2.2.24 SUEXEC_RSRCLIMIT off
apache22-2.2.24 SUEXEC_USERDIR off
apache22-2.2.24 UNIQUE_ID on
apache22-2.2.24 USERDIR on
apache22-2.2.24 USERTRACK on
apache22-2.2.24 VERSION on
apache22-2.2.24 VHOST_ALIAS on
apache22-2.2.24 PROXY_AJP off
apache22-2.2.24 PROXY_BALANCER off
apache22-2.2.24 PROXY_CONNECT on
apache22-2.2.24 PROXY_FTP off
apache22-2.2.24 PROXY_HTTP on
apache22-2.2.24 PROXY_SCGI off

The result is a list of compiled options too! Look at the last four lines. We see now that PROXY_CONNECT is ON and PROXY_HTTP is ON too! So our pkgng command can be used for both: binaries installed via pkgng and binaries installed via ports. That is totally awesome!

Thanks again @kpa for sharing the pkgng used-compiler-options-command!
 
Last edited by a moderator:
No problem at all. I forgot to mention that you can query a remote package repository for a package that satisfies a certain compile time option, just replace pkg query with pkg rquery. That's where the ability to query the compile time options gets really useful:

pkg rquery -e "%n=apache22" "%n-%v %Ok %Ov" | ...

I would personally prefer to express the query as something like this but the support for such syntax is not in ports-mgmt/pkg yet:

pkg rquery -e "%n=apache22 && %O[PROXY_CONNECT]=ON && %O[PROXY_HTTP]=ON" "%n-%v"
 
Back
Top