tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Sugggestion: Add lib type *.c for tcc_add_library() o


From: lifenjoiner
Subject: Re: [Tinycc-devel] Sugggestion: Add lib type *.c for tcc_add_library() on windows ('-l' option parse)
Date: Thu, 19 Jun 2014 00:22:51 +0800

Hi there,

Here is my patch for "libtcc.c" for the minimum change I can do the best maybe.

Attachments also content a small program that can be used as a test. I use:
"tcc %CFLAGS% -vvv WinHash.c -ladvapi32 -lntdll -lgetopt -lshlwapi -DHashMain 
-lshell32"

If you still think this feature is useless, forget it!
"w32api" is really useful, but NOT convenient for TCC to build the libs.


---------------- whole tcc_add_library() ----------------------
/* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
{
#ifdef TCC_TARGET_PE
    const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", 
"%s/lib%s.dll", "%s/lib%s.a", "%s/%s.c", NULL };
    const char **pp = s->static_link ? libs + 4 : libs;
/*+*/    const char *filename;
#else
    const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
    const char **pp = s->static_link ? libs + 1 : libs;
#endif
    while (*pp) {
        if (0 == tcc_add_library_internal(s, *pp,
/*+*/            libraryname, 0, s->library_paths, s->nb_library_paths)) {
/*+*/#ifdef TCC_TARGET_PE
/*+*/            /* extra search for c file together with def file if there is 
no dll */
/*+*/            if (pp < libs + 2) {
/*+*/                filename = tcc_strdup(s->target_deps[s->nb_target_deps - 
1]);
/*+*/                strcpy(tcc_fileextension(filename), ".dll");
/*+*/                if (tcc_open(s, filename) < 0) {
/*+*/                    strcpy(tcc_fileextension(filename), ".c");
/*+*/                    tcc_add_file_internal(s, filename, 0);
/*+*/                } else
/*+*/                    tcc_close();
/*+*/            }
/*+*/#endif
            return 0;
/*+*/        }
        ++pp;
    }
    return -1;
}
---------------- replace all "/*+*/" to "" ------------------


> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On Behalf Of
> address@hidden
> Sent: Wednesday, June 18, 2014 8:59 PM
> To: address@hidden
> Subject: Re: [Tinycc-devel] Sugggestion: Add lib type *.cfortcc_add_library()
> on windows ('-l' option parse)
> 
> 
> > > With this patch, we won't need to make the "libname".a library, and
> > > also can use -l option. It will search for the *.def file, if succeed
> > > it will do an extra search for the *.c file.
> >
> > And what if "dllname.c" is the source of "dllname.dll" as it much
> > more likely happens in peoples' projects?
> 
> You are right. I missed this case as my projects are always small. Considering
> this, it needs a double check for non-dynamic linking. I'm considering how to
> do it. Then it will be just an optional usage, and the original usage will not
> be effected.
> 
> >
> > Then your patch would load both the dll and its source, causing
> > strange behavior that people cannot explain, due to a side-effect
> > from a "feature" that isn't documented anywhere.
> >
> > As to the other part - searching ".c" as library:  If you think
> > that is useful then why is it for windows users only?  And how are
> > people supposed to benefit if it is not documented?
> 
> In tcc_add_library(), other platforms except windows, the libs searching list
> shows:
> const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
> No *.def files to be used.
> I work only on windows.
> 
> Sorry not document it, and too nervous to wait a so long time to get a 
> valuable
> opinion, I committed my patch.
> 
> >
> > > I use my patched version all the time. It works well.
> >
> > Fine, great.  But do we really need this in everybody's public
> > "mob" version? :P
> >
> > --- grischka

Attachment: libtcc.c-patch.txt
Description: Text document

Attachment: WinHash.h
Description: Binary data

Attachment: WinHash.c
Description: Binary data


reply via email to

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