Skip to content

Commit

Permalink
Add OpenBSD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibara committed Jun 23, 2024
1 parent 9acac69 commit c780a1a
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://alire.ada.dev/

## TL;DR ##

Available for Linux/macOS/Windows/FreeBSD.
Available for Linux/macOS/Windows/FreeBSD/OpenBSD.

Download the latest stable version from the [Releases](https://github.com/alire-project/alire/releases) page. See the [Getting Started](doc/getting-started.md) guide for binary downloads.

Expand All @@ -34,15 +34,15 @@ See the [Getting Started](doc/getting-started.md) guide.

The build process of `alr` is straighforward and depends only on a recent GNAT Ada 2012 compiler. All dependencies are included as submodules. A project file (`alr_env.gpr`) is provided to drive the build with all necessary configuration (which is also valid for editing with GNAT Studio).

The ALIRE_OS environment variable must be set to the OS for which `alr` is being build, taking one of the values in `freebsd`, `linux`, `macos`, `windows`.
The ALIRE_OS environment variable must be set to the OS for which `alr` is being build, taking one of the values in `freebsd`, `openbsd`, `linux`, `macos`, `windows`.

Follow these steps:

1. Clone the repository: `git clone --recurse-submodules https://github.com/alire-project/alire.git`
1. Enter the cloned repository folder.
1. Build the executable:
* if you have Bash on your system: `dev/build.sh`
* if you don't have Bash on your system: `ALIRE_OS=<one of: freebsd, linux, macos, windows> gprbuild -j0 -p -P alr_env`
* if you don't have Bash on your system: `ALIRE_OS=<one of: freebsd, openbsd, linux, macos, windows> gprbuild -j0 -p -P alr_env`

The binary will be found at `bin/alr`. You can run `alr version` to see version and diagnostics information.

Expand Down Expand Up @@ -80,7 +80,7 @@ environment `alr` is using with `alr printenv`.

## Supported platforms ##

Alire can be built on Linux, macOS, Windows, and FreeBSD.
Alire can be built on Linux, macOS, Windows, FreeBSD, and OpenBSD.

Alire requires a recent Ada 2012 compiler. In practice, this currently means
the latest [GNAT Community](https://www.adacore.com/download) or a somewhat
Expand Down
4 changes: 4 additions & 0 deletions alire.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ library project Alire is

case Alire_Common.Host_Os is
when "freebsd" => Src_Dirs := Src_Dirs & ("src/alire/os_freebsd");
when "openbsd" => Src_Dirs := Src_Dirs & ("src/alire/os_openbsd");
when "linux" => Src_Dirs := Src_Dirs & ("src/alire/os_linux");
when "macos" => Src_Dirs := Src_Dirs & ("src/alire/os_macos");
when "windows" => Src_Dirs := Src_Dirs & ("src/alire/os_windows");
Expand All @@ -38,6 +39,9 @@ library project Alire is
when "freebsd" =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__freebsd.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__freebsd.adb";
when "openbsd" =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__openbsd.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__openbsd.adb";
when "linux" =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__linux.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__linux.adb";
Expand Down
3 changes: 2 additions & 1 deletion alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CLIC_LIBRARY_TYPE="static"
# Building alr requires the explicit setting of this variable
[gpr-set-externals."case(os)"]
freebsd = { ALIRE_OS = "freebsd" }
openbsd = { ALIRE_OS = "openbsd" }
linux = { ALIRE_OS = "linux" }
macos = { ALIRE_OS = "macos" }
windows = { ALIRE_OS = "windows" }
Expand Down Expand Up @@ -116,4 +117,4 @@ command = ["pwsh", "scripts/version-patcher.ps1", "_or_later"]

[actions.'case(os)'.'...']
type = "post-build"
command = ["scripts/version-patcher.sh", "_or_later"]
command = ["scripts/version-patcher.sh", "_or_later"]
1 change: 1 addition & 0 deletions alire_common.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ abstract project Alire_Common is

type Host_OSes is ("linux",
"freebsd",
"openbsd",
"macos",
"windows");

Expand Down
1 change: 1 addition & 0 deletions alr.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project Alr is

case Alire_Common.Host_Os is
when "freebsd" => Src_Dirs := Src_Dirs & ("src/alr/os_linux");
when "openbsd" => Src_Dirs := Src_Dirs & ("src/alr/os_linux");
when "linux" => Src_Dirs := Src_Dirs & ("src/alr/os_linux");
when "macos" => Src_Dirs := Src_Dirs & ("src/alr/os_macos");
when "windows" => Src_Dirs := Src_Dirs & ("src/alr/os_windows");
Expand Down
1 change: 1 addition & 0 deletions alr_env.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ aggregate project Alr_Env is

case Alire_Common.Host_Os is
when "freebsd" => for External ("GNATCOLL_OS") use "unix";
when "openbsd" => for External ("GNATCOLL_OS") use "unix";
when "linux" => for External ("GNATCOLL_OS") use "unix";
when "macos" => for External ("GNATCOLL_OS") use "osx";
when "windows" => for External ("GNATCOLL_OS") use "windows";
Expand Down
6 changes: 6 additions & 0 deletions dev/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function guess_OS() {
"freebsd")
echo freebsd
;;
"openbsd")
echo openbsd
;;
"darwin"*) # varies with versions: darwin18, darwin19, etc.
echo macos
;;
Expand All @@ -37,6 +40,9 @@ function get_OS() {
"FreeBSD")
echo freebsd
;;
"OpenBSD")
echo openbsd
;;
"Darwin")
echo macos
;;
Expand Down
4 changes: 2 additions & 2 deletions doc/catalog-format-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ available.'case(toolchain)'.user = false

## Parameters

- `os`: name of the OS. Currently supported values are: `freebsd`, `linux`,
`macos`, `windows`, and `os-unknown`.
- `os`: name of the OS. Currently supported values are: `freebsd`, `openbsd`,
`linux`, `macos`, `windows`, and `os-unknown`.

- `distribution`: name of the Linux distribution or name of the software
distribution platform if running on a different OS. Currently supported
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-directories.adb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ package body Alire.Directories is
Keep_Links : constant String
:= (case Platforms.Current.Operating_System is
when Linux => "-d",
when FreeBSD | MacOS => "-R",
when FreeBSD | OpenBSD | MacOS => "-R",
when others =>
raise Program_Error with "Unsupported operation");
begin
Expand Down
3 changes: 2 additions & 1 deletion src/alire/alire-platforms.ads
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Alire.Platforms with Preelaborate is
-- Platform information necessary for some releases

type Extended_Architectures is
(AMD64, -- Equivalent to X86_64 (FreeBSD)
(AMD64, -- Equivalent to X86_64 (FreeBSD/OpenBSD)
ARM64, -- Equivalent to AARCH64
End_Of_Duplicates,
-- Up to this point, these are architectures that we want to rename to
Expand All @@ -21,6 +21,7 @@ package Alire.Platforms with Preelaborate is
-- See e.g. https://stackoverflow.com/a/45125525/761390

type Operating_Systems is (FreeBSD,
OpenBSD,
Linux,
MacOS,
Windows,
Expand Down
7 changes: 7 additions & 0 deletions src/alire/os_openbsd/alire-check_absolute_path.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
separate (Alire)
function Check_Absolute_Path (Path : Any_Path) return Boolean is
begin
return (Path'Length >= 1
and then
Path (Path'First) = GNAT.OS_Lib.Directory_Separator);
end Check_Absolute_Path;
40 changes: 40 additions & 0 deletions src/alire/os_openbsd/alire-platforms-current__openbsd.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

package body Alire.Platforms.Current is

-- OpenBSD implementation (very close to Linux/FreeBSD)

---------------------------
-- Detected_Distribution --
---------------------------

function Detected_Distribution return Platforms.Distributions
is (Platforms.Distribution_Unknown);

-----------------------
-- Distribution_Root --
-----------------------

function Distribution_Root return Absolute_Path
is ("/");

----------------------
-- Load_Environment --
----------------------

procedure Load_Environment (Ctx : in out Alire.Environment.Context)
is null;

----------------------
-- Operating_System --
----------------------

function Operating_System return Alire.Platforms.Operating_Systems
is (Alire.Platforms.OpenBSD);

----------------
-- Initialize --
----------------

procedure Initialize is null;

end Alire.Platforms.Current;
34 changes: 34 additions & 0 deletions src/alire/os_openbsd/alire-platforms-folders__openbsd.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
with Ada.Directories;

with Alire.Platforms.Common;

package body Alire.Platforms.Folders is

-- Linux implementation

-----------
-- Cache --
-----------

function Cache return Absolute_Path is (Common.XDG_Data_Home);

-----------
-- Config--
-----------

function Config return Absolute_Path is (Common.XDG_Config_Home);

----------
-- Home --
----------

function Home return Absolute_Path is (Common.Unix_Home_Folder);

----------
-- Temp --
----------

function Temp return Absolute_Path
is (Ada.Directories.Full_Name (Common.Unix_Temp_Folder));

end Alire.Platforms.Folders;

0 comments on commit c780a1a

Please sign in to comment.