gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] RE: Getting full pathname of running executable


From: Camm Maguire
Subject: Re: [Gcl-devel] RE: Getting full pathname of running executable
Date: 19 Sep 2003 11:13:38 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi Mike!  Thanks as always for your tremendous efforts!

"Mike Thomas" <address@hidden> writes:

> Hi Camm.
> 
> The reason the new 2.6.1 didn't work today is that I discovered that the new
> "make install" hard-wired *system-directory* code has broken the Windows
> installer, which runs saved_gcl on the target machine during installation to
> write out bat and sh startup scripts in the new bin directory.
> 

Please accept my apologies.

> The scripts actually refer to *system-directory*, expecting it to be set
> correctly on the target machine, rather than referring to the machine on
> which the installer was built.
> 

OK, there have been two pathname related changes recently:

1) *system-directory* -- We primarily needed this change to build
    axiom with gcl installed externally.  Axiom makes several
    intermediary images in its source tree, and these need to be able
    to find files in the GCL install directory.  (At least
    cmpinclude.h, and gcl_collectfn AFAIR).  So we made
    *system-directory* persistent.  When not set, it defaults to the
    directory name of argv[0] as before.  In any case, it is overrided
    by a -dir command line option as before.  But once set and
    si::save-system'ed, its binding persists until you explicitly
    change it.  This seems logical to me, as you're not necessarily
    moving your 'system' related files in your h, autoload, etc.
    directories when you just save-system.  If you are moving the
    tree, as when running 'make install', then you can explicitly set
    the variable to its new location as done in the top level
    makefile.

2) Optional full path kcl_self detection via the GET_FULL_SELF_PATH
    macro.  This is so people can dispense with the shell script
    wrapper if they please.  The information in that wrapper is almost
    all contained in the image itself now.  The argv[0] info can now
    be obtained automatically for kcl_self; -dir is no longer needed
    to specify a *system-directory*; C_INCLUDE_PATH is now obviated by
    the automatic addition of the CFLAGS -I*system-directory*/../h.

Of course suggestions for improvements here are most welcome.

I'm not sure about the details of your installer's construction, but
can't you get the right setting via the $(INSTALL_LIB_DIR) make
variable?  The relevant makefile snippet is (of course) 

        cd $(DESTDIR)$(INSTALL_LIB_DIR)/$(PORTDIR) && \
                mv $(FLISP)$(EXE) temp && \
                echo "(setq si::*system-directory* 
\"$(INSTALL_LIB_DIR)/$(PORTDIR)\")(si::save-system \"$(FLISP)$(EXE)\")" | 
./temp && \
                rm -f temp


> Please pardon my ignorance of the semantics of argv[0], but what is wrong
> with the code in "o/main.c" which has been up until now setting the
> executable path dynamically (and correctly on Windows at least)?
> 

The problem with the old setup is that if someone saves a local image,
they still expect to be able to compile, load, describe and save from
that image itself.  We need some way of finding the other installed
files, as well as the running executable image.  Actually, I now see
that we still have work to do in this area with *lib-directory* and/or
*load-path* and *info-paths*.  I'll put this on the TODO list.
Suggestions of course always welcome!

> Where were you planning to put the new code discussed last week (included
> below)?
> 

Would you like me to?  I thought it might be better if you test it
first and then commit it if OK, since you have the working Windows
compile setup.  In general, I get nervous about changing anything with
a mingw (or xBSD, macos, ...) filename :-).  This snippet should go in
a GET_FULL_PATH_SELF macro in your .h file.

Take care,



> Cheers
> 
> Mike Thomas
> 
> 
> 
> 
> | -----Original Message-----
> | From: address@hidden
> | [mailto:address@hidden
> | Behalf Of Mike Thomas
> | Sent: Wednesday, September 10, 2003 11:52 AM
> | To: Camm Maguire; address@hidden
> | Cc: Aurelien Chanudet
> | Subject: [Gcl-devel] RE: Getting full pathname of running executable
> |
> |
> | Hi Camm.
> |
> | Windows:
> |
> | ================================================================
> | #include <windows.h>
> | #include <stdio.h>
> |
> | #define BUF_SIZE 80
> |
> | int main ( int argc, char ** argv )
> | {
> |   char ourpath[BUF_SIZE];
> |   GetModuleFileName ( NULL, &ourpath[0], BUF_SIZE );
> |   fprintf ( stdout, "The executable is in %s\n", &ourpath[0]  );
> |
> |   return 0;
> | }
> |
> | ================================================================
> |
> | address@hidden ~
> | $ gcc filename.c -o filename.exe
> |
> | address@hidden ~
> | $ ./filename
> | The executable is in C:\msys\1.0\home\miketh\filename.exe
> |
> | address@hidden ~
> | $ cd /c
> |
> | address@hidden /c
> | $ ~/filename
> | The executable is in C:\msys\1.0\home\miketh\filename.exe
> |
> | ================================================================
> |
> | DWORD GetModuleFileName(
> |   HMODULE hModule,
> |   LPTSTR lpFilename,
> |   DWORD nSize
> | );
> |
> | Parameters
> | hModule
> | [in] Handle to the module whose path is being requested. If this parameter
> | is NULL, GetModuleFileName retrieves the path for the current module.
> | lpFilename
> | [out] Pointer to a buffer that receives a null-terminated string that
> | specifies the fully-qualified path of the module. If the length
> | of the path
> | exceeds the size specified by the nSize parameter, the function
> | succeeds and
> | the string is truncated to nSize characters and null terminated.
> | The path can have the prefix "\\?\", depending on how the module
> | was loaded.
> | For more information, see Naming a File.
> |
> | nSize
> | [in] Size of the lpFilename buffer, in TCHARs.
> | Return Values
> | If the function succeeds, the return value is the length of the string
> | copied to the buffer, in TCHARs. If the buffer is too small to hold the
> | module name, the string is truncated to nSize, and the function returns
> | nSize.
> |
> | If the function fails, the return value is zero. To get extended error
> | information, call GetLastError.
> | ================================================================
> |
> |
> | | -----Original Message-----
> | | From: Camm Maguire [mailto:address@hidden
> | | Sent: Wednesday, September 10, 2003 11:19 AM
> | | To: address@hidden
> | | Cc: Mike Thomas; Aurelien Chanudet
> | | Subject: Getting full pathname of running executable
> | |
> | |
> | | This nonportable proc dependant code is the best I can think of at the
> | | moment.  Alternatives, esp. on Windows/Mac?
> | |
> | |   int p;
> | |   char b[PATH_MAX],q[PATH_MAX];
> | |
> | |   p=getpid();
> | |   snprintf(q,sizeof(q),"/proc/%d/exe",p);
> | |   realpath(q,b);
> | |
> | | Take care,
> | |
> | | --
> | | Camm Maguire
> | address@hidden
> | |
> | ==========================================================================
> | | "The earth is but one country, and mankind its citizens."  --
> | Baha'u'llah
> | |
> | |
> |
> |
> |
> |
> | _______________________________________________
> | Gcl-devel mailing list
> | address@hidden
> | http://mail.gnu.org/mailman/listinfo/gcl-devel
> |
> |
> 
> 
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]