# Creating lib32-* Version of Ports



## Amzo (Jul 18, 2019)

Since ports builds everything from ports it should be able to build lib32 versions of packages with the correct flags. However with the wait ports Mk/* files are, there are a lot of hardcoded dependencies to libraries in ${LOCALBASE}/lib.

I wanted to use some i386 applications such as emulators/gens so I started creating lib32- version of the ports.

Here is the current work. I have worked up to mesa-dri. Lib32 Ports. These do not conflict with the existing ports and set some specific locations and environment variables.

*LOCATIONS:*

For now the Makefiles only install files to ${LOCALBASE}/lib32 and ${LOCALBASE}/libdata32/pkgconfig. Everything else from the ports such as man pages, docs, binaries and include files are removed. As we remove include files the lib32- package depends directly on the regular 64bit version. For examples lib32-libgcrypt depends on libgcrypt of the exact same version. This keeps the lib32 versions in sync and also ensures that header files are provided by the normal package.

*ISSUES:*

Can't make use of specific USES that set hardcoded dependencies. USES_XORG=x11 hardcodes x11/libX11. So these had to be removed.
Using GNU_CONFIGURE also forces --host, --target and --build to be set.

Another issue is with USES=pkgconfig as this set the PKG_CONFIG enviroment variable to pkgconf.

*VARIABLES:*

PKGNAMEPREFIX= lib32-
PKG_CONFIG=       pkgconf32
PKG_CONFIG_DIR=${LOCALBASE}/lib32

*TODO:*
I need to add FOR_ARCHES_ONLY=amd64 to all the ports

usr/local/lib32 isn't included by ldconfig by default. Using:


```
echo /usr/loca/lib32 >> /usr/local/libdata/ldconfig/lib32
```

will fix this. I could create this in a PORT but it's figuring out which port should create it.


----------



## shkhln (Jul 18, 2019)

Ah, would you be interested in helping with https://reviews.freebsd.org/D16830 instead?


----------



## Amzo (Jul 18, 2019)

It's a lot of work to rewrite the Mk/* files as I started with this approach originally. I was going to use make the Makefiles use the original ones and create them as slave ports. Stuff such as LIB_DEPENDS are all hard-coded to lib/ so I created local modifications to add LIB32_DEPENDS. though the issue is with the port Makefiles testing for Arches as well and setting specific flags for such arch.

It seems easier to just create new lib32-* Makefiles and set the make variables manually as messing about with all the Mk/* files will probably break stuff for the ports.


----------



## sidetone (Jul 18, 2019)

How about `grep`-ping Makefiles for `ONLY_FOR ARCHS`. Then having a new individual .mk file in /usr/ports/mk and /usr/ports/mk/uses for running those specific ports, to only be for ports that apply to those limited architectures. The ports that have that in common, reference that .mk file. Then reference that .mk file as few times as needed from the top .mk file. The quick instruction of how to set this ability in make.conf can be at the top.

A few hard coded dependencies have been unset by using specialized .mk files through make.confthis way, as far as I understand.

A past example, that's no longer in use any more, due to qt4 being obsolete for FreeBSD was by setting `QT4_OPTIONS=   -CUP` through make.conf: that past option was allowed through under the /usr/ports/Mk directory.

I grep a few categories at a time starting by `grep ONLY_FOR_ARCHS [a-c]*/*/Makefil* | grep i386`


----------



## shkhln (Jul 18, 2019)

Amzo said:


> It's a lot of work to rewrite the Mk/* files as I started with this approach originally.



It's not as bad as it seems. Or, rather, everything in the ports is exactly as brittle that thing, so it's nothing new. I would be happy to see the current makefile abuse die in a fire, but people are quite used to it.

More to the point, I also converted another 50 packages to lib32.mk to see whether it breaks. It holds fine.


----------



## Amzo (Jul 18, 2019)

I originally used MASTER ports and added them as slave ports however this introduces too many problem as it inherits from the MASTER port and can overwrite specific build variables. Modifying the ports Mk/ files can introduce bugs and would require wrapping stuff around conditional statements such as:


```
.if ${LIB32}
do such
.else
do normal build
.endif
```

I took this approach as now I can put my files into a new category /usr/ports/multilib and have them work and stay in sync with the regular versions. It also doesn't clutter the ports with slave versions. It's hard to tell if that way would be cleaner or not. With my current approach I don't need to mess or modify the port build system and tehy work.


----------



## Amzo (Jul 18, 2019)

I checked your work on the USES lib32, but does it recursively prefix all dependencies as lib32- and build with -m32?


----------



## shkhln (Jul 18, 2019)

Pay a little bit more attention. It's not my work, it's a slightly modified version of the patch by one of the Wine port maintainers. It is supposed to go in the official ports tree, although at the moment that work is kinda stuck.


----------



## Amzo (Jul 18, 2019)

I had a look over it and I like that approach, but a tidier approach would be to allow a port option such as '32-bit' which sets the uses. This would avoid hundreds of slave ports in the port tree and would then mean that it can be set as an option in Make.conf. I only created the individual Makefiles for local use to see how it would go.


----------



## shkhln (Jul 18, 2019)

Slave ports are not really up to discussion. (Gatekeeper preference, sorry.)


----------

