Please help improving my function

[email protected] Thu, 20 Oct 2005 10:19:55 +0200
Newsgroups gmane.emacs.xemacs.general
Message-ID <OF339908D7.17BD8E11-ONC12570A0.002BA08D-C12570A0.002DC504@pruftechnik.com>
Hello,

For cross-compiling my qt software, I need different environment sets and 
Makefiles. I wrote these two functions to switch between them:

(defun set-arm-environment()
  "Set environment variables so that compilation for arm is possible"
  (interactive)
  (progn
    ( setenv "QTDIR" "/opt/qt/arm/qt3" )
    ( setenv "LD_LIBRARY_PATH" "/opt/qt/arm/qt3/lib" )
    ( setenv "QMAKESPEC" "qws/linux-arm-g++" )
    ( message "Running qmake" )
    ( call-process "rm" nil ( get-buffer "*scratch*" ) t "-fv" ( concat ( 
getenv "DAFIT" ) "/Makefile" ) )
    ( call-process "qmake" nil ( get-buffer "*scratch*" ) t
                   ( concat ( getenv "DAFIT" ) "/zmainarm.pro" )
                   "-o"
                   ( concat ( getenv "DAFIT" ) "/Makefile" )
                   )
    ( message "Environment set to arm" )
    )
  )

(defun set-x86-environment()
  "Set environment variables so that compilation for x86 is possible"
  (interactive)
  (progn
    ( setenv "QTDIR" "/opt/qt/x86/qt3" )
    ( setenv "LD_LIBRARY_PATH" "/opt/qt/x86/qt3/lib" )
    ( setenv "QMAKESPEC" )
    ( message "Running qmake" )
    ( call-process "rm" nil ( get-buffer "*scratch*" ) t "-fv" ( concat ( 
getenv "DAFIT" ) "/Makefile" ) )
    ( call-process "qmake" nil ( get-buffer "*scratch*" ) t
 
This works ok, but has two drawbacks:

1) When I call set-arm-environment to set the environment variables and 
the Makefile _is_ allready an arm Makefile, I have to wait for the qmake 
process nevertheless. This can take quite a time.

2) When I fire up my emacs, no environment is set and I have to call 
set-xxx-environment manually


Solving 1) could be easy: Just grep the Makefile for "CC       = 
arm-linux-gcc". If this exists, it's an arm Makefile, otherwise x86 and I 
can decide how to go on. The question is: how do I do this in elisp ?

Solving 2) is a bit more tricky. I need to find out if I'm working on the 
cross-compile project and then call set-xxx-environment depending on the 
actual Makefile. Hmm, if I know how to do 1), the latter part should be 
easy.

It would be great if any of you had some suggestions how I can solve my 
Problems.


TIA,

Markus Grunwald