Jim Trigg - 2014-12-18

Below is a proposed replacement makefile. I've updated it to automatically determine processor type and kernel version and add those into CFLAGS instead of having them on specific target commands, specified that each executable depends on the ncurses header file as well as the source file, and have filled out OS versions (bringing each distro current) and sorted them by architecture and then distro. I also corrected a minor typo in the initial comment.

ETA: code formatting, corrected awk script, added bash script to determine os version which allows for a default target

# NOTE: link the current working copy of the code to lmon.c for compiling
ARCH=$(uname -m)
ARCHDEF=$(if $(filter ppc,$(ARCH)),POWER,$(if $(filter s390,$(ARCH)),MAINFRAME,X86))

VERSION=$(shell bash -c osver.sh)

KERNEL=$(shell uname -r)
# Awk script prints 1 if kernel version is 2.6.18 or later, 0 if not.
KERNEL_2_6_18=$(shell awk -F . '{ print (($$1 > 2) || (($$1 > 1) && (($$2 > 6) || (($$2 > 5) && ($$3 > 17))))); }' <<< $(KERNEL))

CFLAGS=-g -O2 -Wall -D JFS -D GETUSER -D LARGEMEM -D $(ARCHDEF) $(if $(filter 1,$(KERNEL_2_6_18)),-D KERNEL_2_6_18,)
#CFLAGS=-g -O3 -Wall -D JFS -D GETUSER -D LARGEMEM
LDFLAGS=-lncurses -lm -g

FILE=lmon.c
HEADER=/usr/include/ncurses.h

default: nmon_$(ARCH)_$(VERSION)

#### POWER 
#### POWER Red Hat Enterprise Linux - RHEL
nmon_ppc_rhel3 nmon_ppc_rhel4 nmon_ppc_rhel5 nmon_ppc_rhel55 nmon_ppc_rhel65: $(FILE)
        gcc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)

nmon_ppc64_rhel3 nmon_ppc64_rhel4 nmon_ppc64_rhel5 nmon_ppc64_rhel55 nmon_ppc64_rhel65: $(FILE)
        gcc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)

nmon_ppc_rhel7 nmon_ppc_rhel71BE nmon_ppc_rhel71LE: $(FILE)
        gcc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D RHEL7

#### POWER SuSE Linux Enterprise Server - SLES
nmon_ppc_sles12: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D SLES12

nmon_ppc_sles113: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D SLES113

nmon_ppc_sles112 nmon_ppc_sles11 nmon_ppc_sles10 nmon_ppc_sles9 nmon_ppc_sles8: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)

#### POWER Canonical Ubuntu
nmon_ppc_ubuntu140403 nmon_ppc_ubuntu1410 nmon_ppc_ubuntu1504 nmon_ppc_ubuntu1510 nmon_ppc_ubuntu1604: $(FILE)
        gcc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D UBUNTU

#### POWER Canonical Ubuntu WITH NVIDIA GPU
nmon_ppc_ubuntu140403_gpu: $(FILE)
        gcc -o nmon_ppc_ubuntu140403_gpu $(FILE) $(CFLAGS) $(LDFLAGS) -D NVIDIA_GPU /usr/lib/nvidia-352/libnvidia-ml.so -D UBUNTU

#### MAINFRAME 
#### MAINFRAME SLES
nmon_mainframe_sles10: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)

nmon_mainframe_sles112: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D SLES113 

nmon_mainframe_rhel7: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D RHEL7 

### Raspbery pi
nmon_arm_raspian:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D ARM 

nmon_arm_ubuntu1510:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D ARM  -D UBUNTU

#### AMD and Intel 32 Bit and 64 Bit (_64)
#### SuSE Linux Enterprise Server - SLES
nmon_x86_sles8 nmon_x86_sles9 nmon_x86_sles10:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86

nmon_x86_sles113 nmon_x86_sles114:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D SLES113
nmon_x86_sles12:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D SLES12

### OpenSUSE
nmon_x86_opensuse10 nmon_x86_64_opensuse11 nmon_x86_64_opensuse13:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86

### Red Hat RHEL
nmon_x86_rhel2:
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D REREAD=1 -D X86

nmon_x86_redhat9 nmon_x86_rhel3 nmon_x86_rhel4 nmon_x86_rhel45:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86

nmon_x86_rhel5 nmon_x86_rhel52 nmon_x86_rhel54 nmon_x86_rhel58:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86

nmon_x86_rhel6 nmon_x86_rhel66:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D RHEL6

nmon_x86_rhel70 nmon_x86_rhel71 nmon_x86_rhel72:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D RHEL7

### CentOS
nmon_x86_centos5 nmon_x86_centos52 nmon_x86_centos54 nmon_x86_centos58:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86

nmon_x86_centos6 nmon_x86_centos66:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D RHEL6

nmon_x86_centos70 nmon_x86_centos71 nmon_x86_centos72:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86 -D RHEL7

### Debian
nmon_x86_debian3:  $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86

### x86 Red Hat Fedora
nmon_x86_fedora10 nmon_x86_fedora23: $(FILE)
        cc -s -o $@ $(FILE) $(CFLAGS) $(LDFLAGS)  -D X86

#### x86 Canonical Ubuntu
nmon_x86_ubuntu810 nmon_x86_ubuntu910 nmon_x86_ubuntu134 nmon_x86_ubuntu1404 nmon_x86_ubuntu140403 nmon_x86_ubuntu140404 nmon_x86_ubuntu1410 nmon_x86_ubuntu1504 nmon_x86_ubuntu1510 nmon_x86_ubuntu1604: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86 -D UBUNTU

nmon_x86_64_ubuntu810 nmon_x86_64_ubuntu910 nmon_x86_64_ubuntu134 nmon_x86_64_ubuntu1404 nmon_x86_64_ubuntu140403 nmon_x86_64_ubuntu140404 nmon_x86_64_ubuntu1410 nmon_x86_64_ubuntu1504 nmon_x86_64_ubuntu1510 nmon_x86_64_ubuntu1604: $(FILE)
        cc -o $@ $(FILE) $(CFLAGS) $(LDFLAGS) -D X86 -D UBUNTU

osver.sh:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

if [ -f /etc/lsb-release ] ; then
  source /etc/lsb-release
  ID=$(tr "A-Z" "a-z" <<< ${DISTRIB_ID})
  VERSION_ID=${DISTRIB_RELEASE}
elif [ -f /etc/os-release ] ; then
  source /etc/os-release
elif [ -f /etc/centos-release ] ; then
  ID=centos
  VERSION_ID=$(cut '-d ' -f4 /etc/centos-release) 
elif [ -f /etc/oracle-release ] ; then
  ID=ol
  VERSION_ID=$(cut '-d ' -f5 /etc/oracle-release)
elif [ -f /etc/redhat-release ] ; then
  ID=rhel
  VERSION_ID=$(cut '-d ' -f7 /etc/redhat-release)
elif [ -f /etc/SuSE-release ] ; then
  ID=$(head -1 /etc/SuSE-release | cut '-d ' -f1 | tr A-Z a-z)
  VERSION_ID=$(head -1 /etc/SuSE-release | cut '-d ' -f2)
fi

if [ $ID == ubuntu ] ; then
  MAJORVER=${VERSION_ID/./}
else
  MAJORVER=$(cut -d . -f1 <<< $VERSION_ID)
fi
echo ${ID}${MAJORVER}
 

Last edit: Jim Trigg 2016-10-17