Cyberithub

How to Install M4 Macro Processor on Ubuntu or Debian Linux

Advertisements

In this article, we will see how to install m4 macro processor on Ubuntu or Debian based linux systems. M4 is a free and open source macro processor tool used to expand macros. It is widely employed by various applications to perform macro expansion. M4 can perform task ranging from simple macro expansion to complex text substitutions, manipulations and transformations. It is used as preprocessor to process various kinds of data, code and configuration files.

M4 has well known usage in generation of configuration scripts (using autoconf). Hence making the scripts more adaptable for the build process of software packages in multiple other Unix like systems. This makes it more portable. The syntax of using m4 is quite straightforward and easy to learn. M4 uses some of the programming concepts such as loops, conditionals and variable handling which makes it flexible and more capable. Here we will see how to install this macro processor on Ubuntu or Debian based linux systems.

 

How to Install M4 Macro Processor on Ubuntu or Debian Linux 2

How to Install M4 Macro Processor on Ubuntu or Debian Linux

Also Read: How to Install and Use TimeShift on Ubuntu

Step 1: Prerequisites

a) You should have a functional Ubuntu or Debian based Linux System.

b) You would require sudo or root access to run privileged commands.

c) You would also require Ubuntu default package manager apt or apt-get utility.

d) Some other utilities like wget, tar and make would be required as well in case of installation through source code.

 

Step 2: Update Your Server

It is not mandatory but in case you have not checked and installed latest updates in your system then run sudo apt update && sudo apt upgrade command as shown below. This will update the repository cache and install all the latest upgrades.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade

 

Step 3: Install M4 Macro Processor

There are few ways to install M4 macro processor on Ubuntu or Debian based systems.

a) Using Apt

The most easiest way to install m4 is through default ubuntu repo. You just have to run sudo apt install m4 command to install m4 macro processor as you can see below.

cyberithub@ubuntu:~$ sudo apt install m4

b) Using Source Code

If you are looking to install latest available version of m4 then it is best to install from source code. For that, you have to first download the latest file from GNU FTP using wget utility as shown below. This will download the file in current working location.

cyberithub@ubuntu:~$ wget https://ftp.gnu.org/gnu/m4/m4-latest.tar.gz
--2024-03-29 00:03:48-- https://ftp.gnu.org/gnu/m4/m4-latest.tar.gz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2953876 (2.8M) [application/x-gzip]
Saving to: ‘m4-latest.tar.gz’

m4-latest.tar.gz 100%[============================================================================>] 2.82M 1.36MB/s in 2.1s

2024-03-29 00:03:52 (1.36 MB/s) - ‘m4-latest.tar.gz’ saved [2953876/2953876]

Extract tarball by using tar -xzf m4-latest.tar.gz command.

cyberithub@ubuntu:~$ tar -xzf m4-latest.tar.gz

Switch to extracted directory by using cd m4-1.4.19 command.

cyberithub@ubuntu:~$ cd m4-1.4.19

To check the compatibility of package with target system and ensure that all requires tools, libraries and other dependencies are available, run configure script as shown below.

cyberithub@ubuntu:~/m4-1.4.19$ ./configure
...................................
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating lib/Makefile
config.status: creating po/Makefile.in
config.status: creating src/Makefile
config.status: creating tests/Makefile
config.status: creating checks/Makefile
config.status: creating examples/Makefile
config.status: creating lib/config.h
config.status: executing depfiles commands
config.status: executing stamp-h commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile

Next step is to compile source code using make command. This utility will read the compilation instruction from Makefile and compile the code.

cyberithub@ubuntu:~/m4-1.4.19$ make
.............................
make[4]: Leaving directory '/home/cyberithub/m4-1.4.19/tests'
make[3]: Leaving directory '/home/cyberithub/m4-1.4.19/tests'
make[2]: Leaving directory '/home/cyberithub/m4-1.4.19/tests'
make[1]: Leaving directory '/home/cyberithub/m4-1.4.19'

To install all compiled binaries, run sudo make install command as shown below. This command will read the instructions from Makefile and install m4 based on given instructions. This typically involves copying the compiled binaries to system defined path such as /usr/local/bin or /usr/bin, install all the required libraries file into /usr/local/lib or /usr/lib, adding configuration files to location /etc or /usr/local/etc and adding documentation in directories like /usr/local/share/doc.

cyberithub@ubuntu:~/m4-1.4.19$ sudo make install

 

Step 4: Check M4 Version

After successful installation, you can check the current installed version by using m4 --version command as shown below.

cyberithub@ubuntu:~$ m4 --version
m4 (GNU M4) 1.4.19
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by René Seindal.

 

Step 5: Test M4 

Now that M4 is installed, let's test it by creating a simple macro file called example.m4 with below contents in it:-

define(`cyberithub', `Hello, M4!')dnl
cyberithub

To test, run m4 example.m4 command as shown below. If it works, it should show output Hello, M4!

cyberithub@ubuntu:~$ m4 example.m4
Hello, M4!

 

Step 6: Check all available options

You can check all the command line options available with m4 utility using m4 --help command.

cyberithub@ubuntu:~$ m4 --help

 

Step 7: Uninstall M4 

To uninstall m4 utility, you can use any of the below method depending on how you installed it.

a) Using Apt

If you installed m4 macro processor from ubuntu repo, then run sudo apt remove m4 to remove it from your system.

cyberithub@ubuntu:~$ sudo apt remove m4

b) Using Make

If you installed m4 from source code, then to uninstall first switch to extracted m4 directory and then run sudo make uninstall command as shown below.

cyberithub@ubuntu:~/m4-1.4.19$ sudo make uninstall

Leave a Comment