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
1010PREFIX ?= /usr/local
1111BINDIR ?= $(PREFIX ) /bin
1212
13- # Detect Linux distribution
13+ # Detect Linux distribution / package manager
1414ifeq ($(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+
2627else
27- DISTRO := unknown
28+ PKG_MGR := unknown
2829endif
2930
31+
3032.PHONY : all build install uninstall test clean help deps deps-ubuntu deps-fedora
3133
3234all : build
@@ -51,24 +53,25 @@ test:
5153clean :
5254 $(MAKE ) -C src clean
5355
54- # Detect and install dependencies automatically
56+ # Detect and install dependencies automatically based on package manager
5557deps :
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
6870deps-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)
8890deps-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
108107help :
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"
0 commit comments