14

I want to create a makefile that will compile my objects and name them according to the Linux distro (e.g. Suse, RedHat, or Ubuntu). How can I detect if the OS is Ubuntu or not?

tshepang
  • 1,937
  • 3
  • 20
  • 35
RRR
  • 265
  • 3
  • 7

1 Answers1

20

We use cat /etc/lsb-release for identifying the Ubuntu release:

sh-3.2$  cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.4 LTS"

For other releases it might be

ls /etc/*release

Gentoo, RedHat, Arch & SuSE all have a release file: http://linuxmafia.com/faq/Admin/release-files.html These is a complete script in the link ;)


Example code for operation system, architecture and version for Ubuntu type systems:

OS=$(shell lsb_release -si)
ARCH=$(shell uname -m | sed 's/x86_//;s/i[3-6]86/32/')
VER=$(shell lsb_release -sr)
Josip Rodin
  • 380
  • 2
  • 14
Rinzwind
  • 293,910
  • 41
  • 570
  • 710