How to use make / jom / nmake on Windows? - windows

I'm trying to get the git commit id at build time with make on Windows.
On Linux Debian I can do it with
var := $(shell git rev-parse --verify master)
all:
echo ${var} > file.txt
cat file.txt
But on Windows 10 I get:
Error: Invalid macro invocation found in Makefile line 4
I'm using jom (a clone of nmake) which came with Qt 5.15 version.
Is it possible to do that with jom/nmake?

Related

How to read file contents as list of variables?

I have some python code which works with a C library that I compile with a Makefile. So I create some install/uninstall/installed routines to load/unload/check my library. I add the python commands to it too so everything works.
Now the problem is, not all the machines have the same python version and python might not be set to the most up to date version. I would like to execute python-{x.y} -m pip {install -e . | uninstall {libname} | show {libname}}.
My current approach was:
create a configured.dat file with the following contents:
python3.4 python3.6 python3.8
And the following Makefile routine:
CONFIGURED_FILE=configured.dat
INSTALLED_PYTHON_VERSIONS :=$(file < $(CONFIGURED_FILE))
RED := \033[0;31m
GREEN := \033[1;32m
CYAN := \033[0;36m
NO_COLOR := \033[0m
ifneq ($(VERBOSE),)
VERBOSE := ''
else
VERBOSE := '-q'
endif
EDITABLE := '-e'
.PHONY: install
install:
# make C libs
$(foreach f,$(INSTALLED_PYTHON_VERSIONS), echo -e 'installing $(CYAN)$f$(NO_COLOR)'; $f -m pip install $(VERBOSE) $(EDITABLE) .;)
On my development machine this works. On my deployment machine it doesn't. The variable INSTALLED_PYTHON_VERSIONS is empty. How? Why? The only change I found between the environments that should impact it is the make version, 3.82 on prod, and 4.3 on dev. Prod is centos 7.9.2009 and dev is ubuntu 22.04.1.
The root problem is the wanting to invoke different python versions, the superficial problem is being unable to read the file contents into a list of variables. A good answer to either would be fine by me.
You found the problem yourself: on one machine you're using GNU make 3.82 and on the other 4.3. According to the GNU make NEWS file, the $(file ...) function was added in GNU make 4.0 (released in 2013, so 9 years ago).
You can just use cat:
INSTALLED_PYTHON_VERSIONS := $(shell cat $(CONFIGURED_FILE))
I should also point out that echo -e is not portable. There are no POSIX-specified options to echo and lots of different implementations accept, or not, different options. You probably want to switch to printf which is portable and well-defined.

Change the SHELL used in TI Code Composer Studio's auto-generated Makefiles on Windows 10

I need the makefile generated by TI Code Composer Studio 10 to use SHELL = sh.exe instead of SHELL = cmd.exe. The insertion of the SHELL line seems to be specific to TI and not Eclipse. I can't figure out how to do this. I've tried setting environment variables at the system level and in the project build settings. I've tried running TI CCS from a bash shell hoping it might pick up its own environment. I've also looked through the Eclipse sources for generating the makefile.
Example:
Everything from SHELL to just before the -include line is TI specific.
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL = cmd.exe
CG_TOOL_ROOT := C:/ti/ccs1040/ccs/tools/compiler/ti-cgt-msp430_20.2.5.LTS
GEN_OPTS__FLAG :=
GEN_CMDS__FLAG :=
ORDERED_OBJS += \
"./msp430fr60x7_1.obj" \
"../lnk_msp430fr6047.cmd" \
$(GEN_CMDS__FLAG) \
-llibmpu_init.a \
-llibmath.a \
-llibc.a \
-include ../makefile.init
Reason: gmake creates batch files for commands like echo and our computers have security software that block randomly created batch files from running. If run from bash/sh, gmake doesn't use intermediate batch files.
Update: I may have a workaround by telling the project to invoke gmake like this: sh.exe -c gmake.exe args. That isn't working fully though as the args do not get passed.
After confirming with TI that the SHELL is hardcoded, this workaround is the solution.
You'll need to:
Create a make.sh shell script to run the real gmake.exe
Create a makefile.defs to fix some SHELL and RM variables inside the TI generated makefile
Install another sh.exe. I used the one installed with Git for Windows. The cygwin sh.exe that comes with the TI compiler doesn't work. This is a shame, because it would be nice to have a solution not requiring another tool.
First, modify your project build settings to run the make script. In TI Code Composer Studio:
Project Menu -> Show Build Settings -> CCS Build -> Builder
[ ] Uncheck "Use default build command"
Build Command: C:/Progra~1/Git/bin/sh.exe ${PROJECT_ROOT}/make.sh ${CCS_UTILS_DIR}/bin/gmake -k -j 8
Note: You have to use the MS-DOS short path for "Program Files," because it's 2021, and Eclipse can't handle spaces in a path.
Create make.sh in the PROJECT_ROOT directory:
#!C:/Progra~1/Git/bin/sh.exe
# The cygwin provided shell from TI doesn't work with make. Use the one from Git instead or even SourceTree's embedded Git shell.
# In TI CCS, Project -> Show Build Settings -> CCS Build -> Builder -> Build Command (Uncheck Use default build command)
# Build Command: C:/Progra~1/Git/bin/sh.exe ${PROJECT_ROOT}/make.sh ${CCS_UTILS_DIR}/bin/gmake -k -j 8
echo "$#"
# debugging
#echo $#
#env | sort
if [ $# -eq 0 ]; then
echo Nothing to do. >&2
exit
fi
export MAKESHELL="$SHELL"
# echo MAKESHELL is \'$MAKESHELL\' inside the script, but will be translated to the DOS path inside make.
"$#"
Create makefile.defs in the PROJECT_ROOT directory. The Eclipse generated makefile includes this file at the very end allowing it to override any settings set by TI.
# The invoking shell sets MAKESHELL so we can grab it here.
SHELL = $(MAKESHELL)
RM = rm -f
$(info "MAKEFLAGS is $(MAKEFLAGS)")
$(info "MAKECMDGOALS is $(MAKECMDGOALS)")
# $(info "SHELL is $(SHELL)")
# $(info "CWD is $(CWD)")
# $(info "PATH is ${PATH}")

how to install and where to install bash bc on windows

I do not know how to install and where to install bc on windows
$ bash -help
GNU bash, version 4.4.23(1)-release-(x86_64-pc-msys)
$ bc
bash: bc: command not found
I use git-bash / mingw64 on windows.
please help
GIT Bash uses MINGW compilation of GNU tools. It uses only selected ones. You can install the whole distribution of the tools from https://www.msys2.org/ and run a command to install bc. And then copy some files to installation folder of Git. This is what you do:
Install before-mentioned msys2 package and run msys2 shell.
Install bc using the following command: pacman -S bc
Go to msys2 directory, for me it's C:\msys64\usr\bin
Copy bc.exe to your Git for Windows directory, for me this is C:\Users\\AppData\Local\Programs\Git\usr\bin
Why do you even need bc on a GIT bash?
A typical usage would be:
Prompt>echo $(1+2 | bc) // or something similar
Recently I've found out that double brackets do the thing, even without bc:
Prompt>$ echo $((1+2))
Prompt>3
Edit after first comment
In case you need floating point calculations, you might use awk, as in this example:
Prompt>awk 'BEGIN {print (20.0+5)/7}'
Prompt>3.57143
There are more examples under this URL.

How to alias a particular cmake command

I'm trying to work around a QtCreator bug (https://bugreports.qt.io/browse/QTCREATORBUG-20972) where QtCreator fails to open a CMake project because it is trying to create a socket file in /tmp/RANDOM_PATH/socket whereas "RANDOM_PATH" does not exist.
I can reproduce the issue manually with:
$ /usr/bin/cmake -E server --pipe=/tmp/not-existing-path/socket
--experimental CMake Error: Internal Error with /tmp/not-existing-path/socket: EACCES
The suggestion given in https://bugreports.qt.io/browse/QTCREATORBUG-18444 is to create an alias of cmake which would report
"serverMode":false
when given the command
cmake -E capabilities
which on my machine (Ubuntu 18.04) outputs:
{"generators":[{"extraGenerators":[],"name":"Watcom WMake","platformSupport":false,"toolsetSupport":false},{"extraGenerators":["CodeBlocks","CodeLite","Sublime Text 2","Kate","Eclipse CDT4","KDevelop3"],"name":"Unix Makefiles","platformSupport":false,"toolsetSupport":false},{"extraGenerators":["CodeBlocks","CodeLite","Sublime Text 2","Kate","Eclipse CDT4"],"name":"Ninja","platformSupport":false,"toolsetSupport":false}],"serverMode":true,"version":{"isDirty":false,"major":3,"minor":10,"patch":2,"string":"3.10.2","suffix":""}}
What's the easiest way to achieve this?
I've tried to add such an alias:
cmake='cmake | sed "s/\"serverMode\":true/\"serverMode\":false/g"'
, but the issue is that the "sed" command needs to be after the arguments given to cmake, and not before.
I see from that bug report:
If you want to run a newer cmake without server-mode, then you will need to write a wrapper around cmake that removes the server-mode support indicator from the output reported by
cmake -E capabilities
That would be something like
cmake() {
if [[ "$*" == "-E capabilities" ]]; then
command cmake "$#" | jq -c 'del(.serverMode)'
else
command cmake "$#"
fi
}
You make have to make that a standalone script rather than a shell function.

Compiling nano hitting problems during make

I am trying to compile nano and hitting some problems.
Details are as follows -- versions I cannot change (compiling on s390 architecture and don't have access to other versions):
Nano source version 2.9.7
Using autoconf version 2.62
Using automake version 1.10
Changed configure script so it looks for tooling version 1.10 instead of 1.15 by altering configure line am__api_version='1.10'
I run configure, and then I run make. On running make I get the following error:
make
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /u/user/source/nano-2.9.7/missing aclocal-1.10 -I m4
main::scan_file() called too early to check prototype at /workarea/tools/automake/bin/aclocal-1.10 line 604.
configure.ac:27: error: Autoconf version 2.69 or higher is required
configure.ac:27: the top level
autom4te: /usr/local/bin/m4 failed with exit status: 63
aclocal-1.10: autom4te failed with exit status: 63
WARNING: 'aclocal-1.10' is probably too old.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
FSUM8226 make: Error code 63
I note on the first line it says : CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /u/user/source/nano-2.9.7/missing aclocal-1.10 -I m4 I don't know how to read this error, given aclocal-1.10 is on my path and installed. When I run aclocal-1.10 from my bash shell I get :
aclocal-1.10
main::scan_file() called too early to check prototype at /workarea/tools/automake/bin/aclocal-1.10 line 604.
aclocal-1.10: `configure.ac' or `configure.in' is required
Update
I went to line 27 of configure.ac and changed the line
AC_PREREQ([2.69]) to AC_PREREQ([2.62]). Now when the make command is issued it fails with the following error:
source/nano-2.9.7: >make
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /u/user/source/nano-2.9.7/missing aclocal-1.10 -I m4
main::scan_file() called too early to check prototype at /workarea/tools/automake/bin/aclocal-1.10 line 604.
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /u/user/source/nano-2.9.7/missing autoheader)
autoheader: error: AC_CONFIG_HEADERS not found in configure.ac
FSUM8226 make: Error code 1
make: './config.h.in' removed.
Please offer guidance and support around how to work around my system imposed limitations in order to compile my favourite command line editor!
Two easy solutions: Update your autoconf package.
Or fix your timestamps, so that autoconf isn't reinvoked, e.g. by touching all files in the distribution.
find . | xargs touch

Resources