Package: pymake2
pymake2 is a simple Python-based make system. It brings simplicity and
flexibility of Python language to makefiles. The name ‘pymake2’ is
chosen because ‘pymake’ is already used for another tool that
re-implements the GNU make in python. pymake2 is different from pymake
as it does not try to re-implements GNU make, but a new simple make
system that uses Python for makefiles to leverage the language richness
and flexibility. pymake2 parses makefile-like python scripts and
provides useful messages to help understand what goes wrong during the
build process.How to install pymake2You can usepipto automatically download and installpymake2from the PyPi repository using the following command:for the current user (user-site-packages):pip install --user pymake2for system-wide installation:sudo pip install pymake2You can always clone the repository and install it manually by
running the following command:python setup.py installUsing pymake2#> pymake2 -h
usage: pymake2 [-h] [-f MakefilePath] [-j Jobs] Target

pymake2 is a simple make system implemented in python

positional arguments:
  Target           the make target in the makefile

optional arguments:
  -h, --help       show this help message and exit
  -f MakefilePath  to pass a makefile, default = ./makefile.py
  -j Jobs          number of jobs used in the make process
#>pymake2 looks into the current working directory for the defaultmakefile.pyand provides tab-auto-complete for the targets in that
makefile. If the option-f/path/to/makefile.pyis used, pymake2
provides tab-auto-complete for the targets in selected makefile instead.The following snippet shows a makefile example for arbitrary gcc-based
C99 project.frompymake2import*Debug=True# <-- set it to True to enable more debugging messages# HighlightErrors = True # To enable the highliterHighlightWarnings=True# To enable the highliterHighlightNotes=True# To enable the highliter# Custom Highlighting using regular expressionshl(regx(r'error:.+'),colors.IRed)# hl(regx(r'expression'), colors.IGreen, colors.On_Cyan)# hl('c', colors.IGreen)CC='gcc'CFLAGS='-g -O2 -std=c99'LINKFLAGS=''executable='a.out'BUILDdir='./Build/'src_files=find(root='./',filter='*.c')obj_files=replace(src_files,'.c','.o')obj_files=retarget(obj_files,BUILDdir,'')@targetdefall(Tlink):# depends on Target linkprintcolor('Build Succeeded',colors.IGreen)returnTrue@targetdefTlink(Tcompile):# depends on Target compilereturnlink(CC,LINKFLAGS,obj_files,executable)@targetdefTcompile(src_files):# depends on srource filesreturncompile(CC,CFLAGS,src_files,obj_files)@targetdefclean():retV=run(eval('rm -r $(BUILDdir)'))retV=run(eval('rm $(executable)'))returnTrueFirst of all,makefile.pymust import pymake2. To enable detailed
error messages in the build process,Debugvariable should be set to
True. The above snippet is self-explanatory to any one used to work with
makefiles.The following makefile example is for arbitrary latex project:frompymake2import*Debug=True# <-- set it to True to enable more debugging messagesHighlightErrors=True# To enable the highliterHighlightWarnings=True# To enable the highliterHighlightNotes=True# To enable the highliterlatexfile='main.tex'pdffile='main.pdf'@targetdefall(pdf):printcolor('Build Succeded',colors.Green)returnTrue@targetdefpdf(latexfile):ifrun(eval('pdflatex -shell-escape -halt-on-error $(latexfile)'),True,True):printcolor('Build Succeded',fg='32',B=True)run(eval('evince $(pdffile)&'))returnTrue@targetdefclean():retV=run(eval('rm -f *.aux *.log *.blg *.bbl *.synctex.gz *.out *.cut $(pdffile) *.vtc'),True)returnretVFeatures of pymake2makefile.pyfollows similar approach of GNU make, but with the
flexibility of Pythonpymake2 automatically highlights error, warning, and info messages
produced by the compiler or the linker. This is especially useful
when the used toolchain does not prints colorful outputs. As shown in
the snippet above, to get highlighted outputs, you need to enableHighlightErrors,HighlightWarnings, andHighlightNotes,
or use custom highlighting as needed. The highlighted outputs only
works with the commands provided by pymake2 such ascompile,link, andarchiveand not withshell,sh, orruncommands.theevalfunction recognizes the format of makefile-like
variables, such as$(BUILDdir)and$(CC), …etc. This
feature helps to port existing makefiles to pymake2. In addition, theevalfunction evaluates environment variables in the same way.
However, variables defined in the makefile has precedence over the
environment variables. In other words, redefining environment
variables in the makefile overrides them.the target function accepts unlimited number of arguments to specify
dependencies.the dependency can be another target function/s, or a list of
files.pymake2 tries to satisfy all the dependences before invoking the
target function.if a target function is in the dependency list of another target
function, it must return True upon success.pymake2 provides a set of helper functions; below I list some of
them, seemake.pyin the source files for more details about
their parameters.shell('cmd')andsh('cmd'): runs the shell command and
return the output.run('cmd'): runs the shell command without returning the
output.compile(...): if necessary, compiles the source files using
the specified compiler along with the passed flags.link(...): if necessary, links the object files to provide the
executable using the passed linker and flags.archive(...): if necessary, archives the object files to
provide the output library using the passed archiver such asgcc-aralong with the passed flags.pymake2 automatically recognizes space-separated lists (used in
makefiles for source or object files) and converts them to Python
lists. Therefore, the commands provided by pymake2 such ascompileandlinkaccepts both formats (Python list, and
space-separated list).ScreenshotsSuccesfull build with highlighted compile warnings.alt textRebuilding the same target yields already satisfied dependencies and not
need to recompile and link.alt textBuilding for the targetTlibfailed after cleaning as it depends on
all object filesOBJ_All.alt textLicensepymake2 is distributed under MIT license.Copyright (c) 2016 Saud WaslyPermission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.