473,804 Members | 4,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python in Makefile Question

Hello,

I'd like to ask a question concerning a python script in a makefile.
Suppose I have a C++ project (sorry for raising this in a Python newsgroup),
with some makefile for it. Before compiling the code, I'd like to check that
there are no C++ convention violations (e.g., identifiers beginning with an
underscore). So my makefile looks something like this:

target: ...
verify.py
$(CC) ...

verify.py is a python script that checks for convention violations, i.e.,
its first line is

#! /usr/bin/env python

I can't figure out the following:
1. How can I get the python script to return a value to make, so that if it
decides that there are convention violations make will fail?
2. How can I pass information from the makefile to the python script, e.g.,
the base directory to check?

Thanks,

Efrat

Jul 18 '05 #1
4 4477
Efrat Regev wrote:
Hello,

I'd like to ask a question concerning a python script in a makefile. Suppose I have a C++ project (sorry for raising this in a Python newsgroup), with some makefile for it. Before compiling the code, I'd like to check that there are no C++ convention violations (e.g., identifiers beginning with an underscore). So my makefile looks something like this:

target: ...
verify.py
$(CC) ...

verify.py is a python script that checks for convention violations, i.e., its first line is

#! /usr/bin/env python

I can't figure out the following:
1. How can I get the python script to return a value to make, so that if it decides that there are convention violations make will fail?
raise SystemExit(1)
2. How can I pass information from the makefile to the python script, e.g., the base directory to check?


Use command-line arguments. The Python equivalent of "argv" is
"sys.argv".

Jul 18 '05 #2
Efrat Regev wrote:
1. How can I get the python script to return a value to make, so that if it
decides that there are convention violations make will fail?
You can set the return code of your Python script through sys.exit (3)
2. How can I pass information from the makefile to the python script, e.g.,
the base directory to check?


Python side:
Commandline arguments can be read through the list sys.argv. Parsing of
commandline options can be done with the module optparse.

Makefile side:
I don't know if there is a special variable in GNU make for the
directory of the current target. Why don't you set the default for the
directory option to the current directory? Most Makefiles won't work
anyway if they are called from a different directory.

Daniel
Jul 18 '05 #3

"Efrat Regev" <ef*********@ya hoo.com> wrote in message
news:MK******** ************@ad elphia.com...
Hello,

I'd like to ask a question concerning a python script in a makefile.
...

Many thanks for the very useful (and very quick) answers!

Efrat
Jul 18 '05 #4
Another option would be to move from Makefiles to AAP, the build
mechanism for vim. We did just that, and are very happy with it. Aap is
python based, so the kind of question you have is very easily handled
within the 'aap' file.

http://www.a-a-p.org/

Aap has the advantage that you don't need to define the dependencies
yourself, it understands C files, and does the work for you. Our
Makefile shrunk by a factor of 5 after converting to aap.

Highly recommended.

Bart van Deenen.

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2312
by: rick_muller | last post by:
I'm interested in parsing a (simple) Makefile using Python. I need to write a packager for a program I'm supporting, and would like to read the list of files in the makefile so that I only have to update that list once. That is, I have a statement (actually multiple statements) in the Makefile that looks like: FILES = a.f b.f c.c d.py e.c \ f.f g.f h.c
1
1931
by: Matej Kenda | last post by:
Hi all, This message is to let you know that I have successfully compiled the latest sources from the 2.3 branch on the abovementioned OS using the HP ansiC compiler version 5.50. Final status: success, it works fine ---
0
2132
by: Li Daobing | last post by:
I can't use .def(str(self)) I write a simple example, without `str', I can build it well, but with this one, I can't build //Rational.cpp #include <boost/python.hpp> #include <iostream> using namespace std; using namespace boost::python;
4
4065
by: rkoida | last post by:
Hello evryone I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file is #Makefile and some scripts to give output #numbers #Change till sign #END
9
1797
by: Andy Leszczynski | last post by:
Hi, I run Mandrake 10.0 with python 2.3 installed by default. I want to keep it as it is but need another, very customized Python installation based of 2.3 as well. I would prefer to have it the way it is on Windows, one folder e.g. /opt/mypython with all the stuff under that. It would be unlike that standard installation where everything is scattered across /usr /bin/ /.../doc. That way I can easily tar it and distribute to whatever...
3
1710
by: Paul Mc Gee | last post by:
hi everyone i have just downloaded the latest version of postgresql and was doing the installation according to the article at http://www.faqs.org/docs/ppbook/x486.htm when i got to the point where the perl and python modules are to be installed. the distribution used in that article is an older version of postgresql and i cant seem to find where the perl and python modules are in the current release. when it didnt work for me i just...
2
5958
by: lickspittle | last post by:
Hi, I tried porting Python to the Nintendo DS, and it was surprisingly easy. Installing something called devkitPro, devkitARM, libNDS, msys, msys-DTK and then just using that to cross compile a python installation. Heres a screenshot of it running in the Dualis emulator. It runs flawlessly for what has been compiled into it: http://img520.imageshack.us/img520/2145/python240cj.jpg
0
2280
by: follower | last post by:
This post is mostly Google-bait for anyone else that might want to compile SpiderMonkey ( libjs / libjs.so / libjs.dylib ) for OS X (10.4.5 in my case) and then use it with Python's ctypes. I can't say this will work for anyone else, but it worked for me... Using: http://ftp.mozilla.org/pub/mozilla.org/js/js-1.5.tar.gz First up:
0
1212
by: Tamer Higazi | last post by:
Hi people! I want to compile the Java Python Extension which I downloaded through CVS "http://jpe.cvs.sourceforge.net/jpe/" Building JPE by bootstrapping the makefile system with the cmd: "python makefile.py" from the top source directory.
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.