Skip to content

Commit d49b8aa

Browse files
authored
Fix make deps (#28)
Improve package manager detection and add ci-tested multi-distro support (Ubuntu/Debian, Fedora)
1 parent bf7484a commit d49b8aa

File tree

5 files changed

+167
-60
lines changed

5 files changed

+167
-60
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
# Symlink clang-18 to clang if not exists
3333
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
3434
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
35-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc
3635
rm llvm.sh
3736
3837
- name: Build Compiler
@@ -67,14 +66,8 @@ jobs:
6766
steps:
6867
- uses: actions/checkout@v4
6968

70-
- name: Install Runtime Dependencies (LLVM)
71-
run: |
72-
wget https://apt.llvm.org/llvm.sh
73-
chmod +x llvm.sh
74-
sudo ./llvm.sh 18
75-
sudo apt-get install -y llvm-18
76-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc
77-
rm llvm.sh
69+
# Note: The compiler itself was built once in build-compiler job and is reused here
70+
# No additional runtime dependencies needed - clang handles compilation
7871

7972
- name: Set up Python
8073
uses: actions/setup-python@v5

.github/workflows/test-deps.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Test Dependencies
2+
3+
# Manual trigger only
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
9+
jobs:
10+
test-deps:
11+
name: Test on ${{ matrix.distro }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- distro: Ubuntu 22.04
18+
container: ubuntu:22.04
19+
pkg_mgr: apt
20+
- distro: Debian 12
21+
container: debian:12
22+
pkg_mgr: apt
23+
- distro: Fedora Latest
24+
container: fedora:latest
25+
pkg_mgr: dnf
26+
27+
container:
28+
image: ${{ matrix.container }}
29+
30+
steps:
31+
- name: Install Git and Basic Tools
32+
run: |
33+
if [ "${{ matrix.pkg_mgr }}" = "apt" ]; then
34+
apt-get update
35+
apt-get install -y git make sudo
36+
elif [ "${{ matrix.pkg_mgr }}" = "dnf" ]; then
37+
dnf install -y git make sudo
38+
fi
39+
40+
- name: Checkout Repository
41+
uses: actions/checkout@v4
42+
43+
- name: Detect Package Manager
44+
run: |
45+
echo "Testing package manager detection..."
46+
make deps || true
47+
echo "Detection output shown above"
48+
49+
- name: Install Dependencies with make deps
50+
run: |
51+
echo "Running: make deps"
52+
make deps
53+
54+
- name: Verify Clang Installation
55+
run: |
56+
echo "Checking clang..."
57+
clang --version
58+
clang --version | grep -i "clang version" || (echo "ERROR: clang not found or wrong version" && exit 1)
59+
60+
- name: Verify Bison Installation
61+
run: |
62+
echo "Checking bison..."
63+
bison --version
64+
65+
- name: Verify Flex Installation
66+
run: |
67+
echo "Checking flex..."
68+
flex --version
69+
70+
- name: Verify Python Installation
71+
run: |
72+
echo "Checking python3..."
73+
python3 --version
74+
75+
- name: Verify Pytest Installation
76+
run: |
77+
echo "Checking pytest..."
78+
pytest --version || python3 -m pytest --version
79+
80+
- name: Build Compiler
81+
run: |
82+
echo "Building compiler to verify all dependencies work..."
83+
make
84+
ls -lh src/danac
85+
86+
- name: Test Compiler
87+
run: |
88+
echo "Testing compiler with a simple program..."
89+
cat > test.dana << 'EOF'
90+
def main
91+
writeString: "Hello from ${{ matrix.distro }}!\n"
92+
EOF
93+
src/danac test.dana
94+
./a.out
95+
96+
- name: Summary
97+
if: success()
98+
run: |
99+
echo "SUCCESS: make deps works correctly on ${{ matrix.distro }}"
100+
echo "Package manager: ${{ matrix.pkg_mgr }}"
101+
echo "All dependencies installed and compiler built successfully!"

Makefile

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dana Compiler - Top-level Makefile
22
# Usage:
33
# make - Build the compiler
4-
# make deps - Install dependencies (detects distro automatically)
4+
# make deps - Install dependencies (detects package manager automatically)
55
# make install - Build and install to /usr/local/bin (requires sudo)
66
# make uninstall - Remove from /usr/local/bin
77
# make test - Run test suite
@@ -10,23 +10,25 @@
1010
PREFIX ?= /usr/local
1111
BINDIR ?= $(PREFIX)/bin
1212

13-
# Detect Linux distribution
13+
# Detect Linux distribution / package manager
1414
ifeq ($(shell uname -s),Linux)
15-
ifeq ($(shell test -f /etc/os-release && grep -q '^ID=ubuntu' /etc/os-release && echo ubuntu),ubuntu)
16-
DISTRO := ubuntu
17-
else ifeq ($(shell test -f /etc/os-release && grep -q '^ID_LIKE=.*debian' /etc/os-release && echo debian),debian)
18-
DISTRO := debian
19-
else ifeq ($(shell test -f /etc/os-release && grep -q '^ID=fedora' /etc/os-release && echo fedora),fedora)
20-
DISTRO := fedora
21-
else ifeq ($(shell test -f /etc/os-release && grep -q '^ID=rhel' /etc/os-release && echo rhel),rhel)
22-
DISTRO := fedora
15+
16+
# Package manager detection
17+
ifneq ($(shell command -v apt-get >/dev/null 2>&1 && echo apt),)
18+
PKG_MGR := apt
19+
else ifneq ($(shell command -v dnf >/dev/null 2>&1 && echo dnf),)
20+
PKG_MGR := dnf
21+
else ifneq ($(shell command -v yum >/dev/null 2>&1 && echo yum),)
22+
PKG_MGR := yum
2323
else
24-
DISTRO := unknown
24+
PKG_MGR := unknown
2525
endif
26+
2627
else
27-
DISTRO := unknown
28+
PKG_MGR := unknown
2829
endif
2930

31+
3032
.PHONY: all build install uninstall test clean help deps deps-ubuntu deps-fedora
3133

3234
all: build
@@ -51,24 +53,25 @@ test:
5153
clean:
5254
$(MAKE) -C src clean
5355

54-
# Detect and install dependencies automatically
56+
# Detect and install dependencies automatically based on package manager
5557
deps:
56-
@echo "Detected system: $(DISTRO)"
57-
@if [ "$(DISTRO)" = "ubuntu" ] || [ "$(DISTRO)" = "debian" ]; then \
58+
@echo "Detected package manager: $(PKG_MGR)"
59+
@if [ "$(PKG_MGR)" = "apt" ]; then \
5860
$(MAKE) deps-ubuntu; \
59-
elif [ "$(DISTRO)" = "fedora" ]; then \
61+
elif [ "$(PKG_MGR)" = "dnf" ] || [ "$(PKG_MGR)" = "yum" ]; then \
6062
$(MAKE) deps-fedora; \
6163
else \
62-
echo "ERROR: Unable to detect Linux distro. Please install dependencies manually."; \
63-
echo "See docs/building.md for manual installation instructions."; \
64+
echo "Unsupported package manager. Only Ubuntu/Debian (apt) and Fedora/RHEL (dnf/yum) are supported."; \
65+
echo "Required packages: clang, llvm 18, bison, flex, python3, python3-pip"; \
6466
exit 1; \
6567
fi
6668

6769
# Ubuntu/Debian dependencies
6870
deps-ubuntu:
6971
@echo "Installing dependencies for Ubuntu/Debian..."
7072
sudo apt-get update
71-
sudo apt-get install -y build-essential bison flex python3 python3-pip wget
73+
# lsb-release is required by llvm.sh script, libzstd-dev for linking
74+
sudo apt-get install -y build-essential bison flex python3 python3-pip wget lsb-release software-properties-common gnupg libzstd-dev
7275
# Install LLVM 18
7376
wget https://apt.llvm.org/llvm.sh
7477
chmod +x llvm.sh
@@ -78,15 +81,15 @@ deps-ubuntu:
7881
# Create symlinks
7982
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
8083
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
81-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc
8284
rm llvm.sh
83-
# Install pytest
84-
pip3 install pytest
85+
# Install pytest via apt (avoids PEP 668 externally-managed-environment issues)
86+
sudo apt-get install -y python3-pytest
8587
@echo "Dependencies installed successfully!"
8688

87-
# Fedora/RHEL dependencies
89+
# Fedora/RHEL dependencies (requires LLVM 18)
8890
deps-fedora:
8991
@echo "Installing dependencies for Fedora/RHEL..."
92+
@echo "Note: Fedora repos may not have LLVM 18. Ubuntu/Debian is recommended."
9093
sudo dnf install -y \
9194
clang \
9295
llvm18 \
@@ -95,24 +98,20 @@ deps-fedora:
9598
flex \
9699
bison \
97100
gcc-c++ \
101+
zlib-devel \
102+
ncurses-devel \
98103
python3 \
99-
python3-pip
100-
# Create symlinks if needed
101-
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang 2>/dev/null || true
102-
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++ 2>/dev/null || true
103-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc 2>/dev/null || true
104-
# Install pytest
105-
pip3 install pytest
104+
python3-pytest
106105
@echo "Dependencies installed successfully!"
107106

108107
help:
109108
@echo "Dana Compiler Build System"
110109
@echo ""
111110
@echo "Targets:"
112111
@echo " make - Build the compiler"
113-
@echo " make deps - Install dependencies (auto-detects distro)"
114-
@echo " make deps-ubuntu- Install Ubuntu/Debian dependencies"
115-
@echo " make deps-fedora- Install Fedora/RHEL dependencies"
112+
@echo " make deps - Install dependencies (Ubuntu/Debian/Fedora)"
113+
@echo " make deps-ubuntu- Manual: Ubuntu/Debian dependencies (apt)"
114+
@echo " make deps-fedora- Manual: Fedora/RHEL dependencies (dnf)"
116115
@echo " make install - Build and install to $(BINDIR) (may need sudo)"
117116
@echo " make uninstall - Remove installation"
118117
@echo " make test - Run test suite"

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Dana is an educational programming language designed as a semester project for t
55

66
[![Language](https://img.shields.io/badge/language-C%2B%2B17-blue)](https://en.cppreference.com/w/cpp/17)
77
[![LLVM](https://img.shields.io/badge/LLVM-18-orange)](https://llvm.org/)
8+
[![Bison](https://img.shields.io/badge/Bison-3.8%2B-green)](https://www.gnu.org/software/bison/)
9+
[![Flex](https://img.shields.io/badge/Flex-2.6%2B-yellowgreen)](https://github.com/westes/flex)
810

911
## Features
1012

@@ -84,7 +86,8 @@ danac myprogram.dana && ./a.out
8486
git clone https://github.com/geokoko/dana_compiler.git
8587
cd dana_compiler
8688

87-
# Install dependencies (auto-detects your distro: works for Fedora/RHEL, Ubuntu/Debian)
89+
# Install dependencies (auto-detects your package manager)
90+
# Supports: Ubuntu/Debian (apt), Fedora/RHEL (dnf/yum), Arch (pacman), openSUSE (zypper)
8891
make deps
8992

9093
# Build and install
@@ -100,20 +103,27 @@ danac myprogram.dana && ./a.out
100103

101104
- Build essentials (gcc, g++, make)
102105
- Clang 18 (with C++17 support)
103-
- LLVM 18 (development libraries, llc)
106+
- LLVM 18 (development libraries)
104107
- Flex & Bison
105108
- Python 3 with pip and pytest
106109

107110
#### Build Commands
108111

109112
```bash
110113
make # Build compiler
114+
make deps # Install dependencies (auto-detects package manager)
111115
make install # Install to /usr/local/bin (needs sudo)
112116
make uninstall # Remove installation
113117
make test # Run test suite (requires prior build)
114118
make clean # Clean build artifacts
115119
```
116120

121+
#### Supported Distributions
122+
123+
The `make deps` command works on:
124+
- **Ubuntu/Debian** (apt) - LLVM 18 installed via official llvm.sh
125+
- **Fedora/RHEL** (dnf/yum) - uses system LLVM packages
126+
117127
## Usage
118128

119129
### Basic Compilation

docs/building.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
## Quick Installation (Automated)
44

5-
The easiest way - the Makefile detects your distro and installs dependencies automatically:
5+
The easiest way - the Makefile detects your package manager and installs dependencies automatically:
66

77
```bash
88
# Clone the repository
99
git clone https://github.com/geokoko/dana_compiler.git
1010
cd dana_compiler
1111

12-
# Install dependencies (auto-detects Ubuntu, Debian, Fedora, RHEL)
12+
# Install dependencies (auto-detects package manager)
13+
# Supports: apt, dnf, yum
1314
make deps
1415

1516
# Build and install system-wide
@@ -19,7 +20,9 @@ sudo make install
1920
danac --help
2021
```
2122

22-
The `make deps` target automatically detects your Linux distribution and installs the required packages using the appropriate package manager (apt and dnf supported).
23+
The `make deps` target automatically detects your package manager and installs the required packages. Supported distributions:
24+
- **Ubuntu/Debian** (apt)
25+
- **Fedora/RHEL** (dnf/yum)
2326

2427
---
2528

@@ -29,22 +32,12 @@ The `make deps` target automatically detects your Linux distribution and install
2932

3033
- **Build essentials**: gcc, g++, make
3134
- **C++ Compiler**: Clang 18 with C++17 support
32-
- **LLVM**: Version 18 (headers, libraries, and llc)
35+
- **LLVM**: Version 18 (headers and libraries)
3336
- **Flex**: Lexer generator
3437
- **Bison**: Parser generator (version 3.8+)
3538
- **Python 3**: With pip and pytest for running tests
3639
- **wget**: For downloading LLVM installation script
3740

38-
### Installation on Fedora/RHEL
39-
40-
```bash
41-
sudo dnf install -y clang llvm18 llvm18-devel llvm18-static flex bison gcc-c++ python3 python3-pip
42-
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
43-
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
44-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc
45-
pip3 install pytest
46-
```
47-
4841
### Installation on Ubuntu/Debian
4942

5043
```bash
@@ -61,13 +54,22 @@ sudo apt-get install -y llvm-18 llvm-18-dev libllvm18 clang-18 libclang-rt-18-de
6154
# Create symlinks
6255
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
6356
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
64-
sudo ln -sf /usr/bin/llc-18 /usr/bin/llc
6557
rm llvm.sh
6658

6759
# Install pytest
6860
pip3 install pytest
6961
```
7062

63+
### Installation on Fedora/RHEL
64+
65+
```bash
66+
sudo dnf install -y clang llvm18 llvm18-devel llvm18-static flex bison gcc-c++ python3 python3-pip
67+
pip3 install --user pytest
68+
```
69+
70+
> [!NOTE]
71+
> Fedora may not have LLVM 18 in all versions. Ubuntu/Debian is recommended for guaranteed LLVM 18 support.
72+
7173
## Detailed Installation Steps
7274

7375
The easiest way to get started:
@@ -245,7 +247,9 @@ tar xf bison-3.8.tar.gz && cd bison-3.8
245247
| Target | Description |
246248
|--------|-------------|
247249
| `make` | Build the compiler |
248-
| `make deps` | Install dependencies (auto-detects distro) |
250+
| `make deps` | Install dependencies (auto-detects package manager) |
251+
| `make deps-ubuntu` | Install Ubuntu/Debian dependencies (apt) |
252+
| `make deps-fedora` | Install Fedora/RHEL dependencies (dnf) |
249253
| `make install` | Build and install to `/usr/local/bin` (requires sudo) |
250254
| `make uninstall` | Remove from `/usr/local/bin` |
251255
| `make test` | Run test suite (requires prior build) |

0 commit comments

Comments
 (0)