Re: [AD] allegro-config (4.0.3 beta 1) breaks on NetBSD

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Thursday 02 January 2003 09:33, Eric Botcazou wrote:
[snip - /usr/local/include isn't in NetBSD's default path]
> Thanks for the report. Peter, what do you think about that ?

I'm not Peter, but I may have a solution. Basically, it's a C program 
which is called with parameters such as CFLAGS and which generates a 
new allegro-config script (similar to getting allegro-config from 
allegro-config.in, I believe). However, it does some extra tests (after 
the library has been installed) to determine whether the -I flag is 
needed, so it outputs a custom allegro-config script for your system.

The only thing is, I have no idea how to fit it in with the machinations 
of configure; I'm sure it's pretty simple (since its command line 
arguments are the same as the macros/variables used in 
allegro-config.in).

I could probably write it as a shell script if there is demand for that?

Bye for now,
-- 
Laurence Withers,  lwithers@xxxxxxxxxx
(GnuPG 04A646EA) http://www.lwithers.demon.co.uk/
/* make-allegro-config.c
 *
 *  A small utility to create an appropriate`allegro-config' script for
 *  Allegro. The utility takes various parameters as input (such as 
 *  installation prefix) and examines the user's environment. It prints 
 *  an appropriate shell script on stdout.
 *
 *  The script needs to be run after the Allegro library and header files
 *  have been installed.
 */
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>



/* determine_Ipath()
 *
 *  Determines whether a -Ipath flag needs to be passed to the C compiler
 *  to get at Allegro's headers. This is because gcc3 complains if we
 *  unconditionally pass -Ipath and `path' happens to be one of its standard
 *  include directories (quite likely, but not always, on eg. BSD).
 *
 *  Returns non-zero if -Ipath is required, else zero.
 */
int determine_Ipath(const char* cc, const char* cflags)
{
    int result = 0;
    char* buf = malloc(strlen(cc) + strlen(cflags) + 100);
    FILE* fp = fopen("mkalcfg-test.c", "w");
    if(!fp) return 1; // safe option
    
    fprintf(fp, "#include <allegro.h>\n");
    fprintf(fp, "BITMAP* some_symbol;\n\n");
    fclose(fp);
    
    sprintf(buf, "%s %s -c mkalcfg-test.c -o mkalcfg-test.o", cc, cflags);
    result = system(buf);
    
    free(buf);
    remove("mkalcfg-test.c");
    remove("mkalcfg-test.o");
    
    return result;
}



/* print_prelude()
 *
 *  Prints the top part of the shell script. This section shouldn't 
 *  change, since it is all descriptive.
 */
void print_prelude(void)
{
    printf("#!/bin/sh\n"
        "#\n"
        "#  Note: allegro-config is generated by make-allegro-config.c.\n"
        "#\n"
        "#  This script returns suitable commandline options for compiling programs\n"
        "#  using the Allegro library, for example:\n"
        "#\n"
        "#     gcc myprog.c -o myprog `allegro-config --libs`\n"
        "#\n"
        "#  This is heavily based on a similar script from GTK.\n"
        "\n");
}



/* print_version()
 *
 *  Prints the version string.
 */
void print_version(const char* ver_string)
{
    printf("version=%s\n", ver_string);
    printf("\n");
}



/* print_lib_type()
 *
 *  Prints the type of library to link.
 */
void print_lib_type(const char* static_libs, const char* lib_type)
{
    printf("static_libs=%s\n", static_libs);
    printf("lib_type=%s\n", lib_type);
}



/* print_prefix()
 *
 *  Prints the path prefix (and exec prefix, if required).
 */
void print_prefix(const char* prefix, const char* exec_prefix)
{
    printf("prefix=%s\n", prefix);
    if(strcmp(prefix, exec_prefix)) {
        printf("exec_prefix=%s\n", exec_prefix);
        printf("exec_prefix_set=yes\n");
    } else {
        printf("exec_prefix=$prefix\n");
        printf("exec_prefix_set=no\n");
    }
    printf("\n");
}



/* print_ldflags()
 *
 *  Prints the linker flags to be used with Allegro. If the `-s' flag has
 *  been used when building the lib, strip it out here, so that user
 *  programs don't inherit it.
 */
void print_ldflags(const char* ldflags)
{
    if(strstr(ldflags, " -s")) {
        char* search = 0;
        char* buf = strdup(ldflags);
        while((search = strstr(buf, " -s"))) {
            memmove(search, search + 3, strlen(search + 2));
        }
        printf("allegro_ldflags=\"%s\"\n", buf);
        free(buf);
    } else {
        printf("allegro_ldflags=\"%s\"\n", ldflags);
    }
}



/* print_libs()
 *
 *  Prints the libraries used by Allegro, which must also be linked in.
 */
void print_libs(const char* libs)
{
    printf("allegro_libs=\"%s\"\n", libs);
}



/* print_cflags()
 *
 *  Prints the C flags used by Allegro.
 */
void print_cflags(const char* cflags, const char* cppflags,
    int need_Ipath, const char* prefix)
{
    if(need_Ipath) {
        printf("allegro_cflags=\"-I%s/include %s\"\n", prefix, cflags);
        printf("allegro_cppflags=\"-I%s/include %s\"\n", prefix, cppflags);
    } else {
        printf("allegro_cflags=\"%s\"\n", cflags);
        printf("allegro_cppflags=\"%s\"\n", cppflags);
    }
    printf("\n");
}



/* print_usage()
 *
 *  Prints the usage information. This shouldn't change.
 */
void print_usage(void)
{
    printf("usage()\n"
        "{\n"
        "   cat <<EOF\n"
        "\n"
        "Usage: allegro-config [OPTIONS] [LIBRARIES]\n"
        "\n"
        "Options:\n"
        "    --prefix[=DIR]\n"
        "    --exec-prefix[=DIR]\n"
        "    --version[=VERSION]\n"
        "    --cflags\n"
        "    --cppflags\n"
        "    --libs\n"
        "    --static\n"
        "    --shared\n"
        "    --env\n"
        "\n"
        "Libraries:\n"
        "    release\n"
        "    debug\n"
        "    profile\n"
        "EOF\n"
        "   exit $1\n"
        "}\n"
        "\n"
        "if test $# -eq 0; then\n"
        "    usage 1 1>&2\n"
        "fi\n"
        "\n");
}



/* print_script()
 *
 *  Prints the main body of the script. This section shouldn't change,
 *  since it relies on variables set above.
 */
void print_script(void)
{
    printf("while test $# -gt 0; do\n"
        "    case \"$1\" in\n"
        "        -*=*) optarg=`echo \"$1\" | sed 's/[-_a-zA-Z0-9]*=//'` ;;\n"
        "        *) optarg= ;;\n"
        "    esac\n"
        "\n"
        "    case $1 in\n"
        "\n"
        "        --prefix=*)\n"
        "            prefix=$optarg\n"
        "            if test $exec_prefix_set = no; then\n"
        "                exec_prefix=$optarg\n"
        "            fi\n"
        "        ;;\n"
        "\n"
        "        --prefix)\n"
        "            echo_prefix=yes\n"
        "        ;;\n"
        "\n"
        "        --exec-prefix=*)\n"
        "            exec_prefix=$optarg\n"
        "            exec_prefix_set=yes\n"
        "        ;;\n"
        "\n"
        "        --exec-prefix)\n"
        "            echo_exec_prefix=yes\n"
        "        ;;\n"
        "\n"
        "        --version=*)\n"
        "            version=$optarg\n"
        "        ;;\n"
        "\n"
        "        --version)\n"
        "            echo $version\n"
        "        ;;\n"
        "\n"
        "        --cflags)\n"
        "            echo_cflags=yes\n"
        "        ;;\n"
        "\n"
        "        --cppflags)\n"
        "            echo_cppflags=yes\n"
        "        ;;\n"
        "\n"
        "        --libs)\n"
        "            echo_libs=yes\n"
        "        ;;\n"
        "\n"
        "        --static)\n"
        "            static_libs=yes\n"
        "            echo_libs=yes\n"
        "        ;;\n"
        "\n"
        "        --shared)\n"
        "            static_libs=no\n"
        "            echo_libs=yes\n"
        "        ;;\n"
        "\n"
        "        --env)\n"
        "            echo_env=yes\n"
        "        ;;\n"
        "\n"
        "        release)\n"
        "            lib_type=alleg\n"
        "        ;;\n"
        "\n"
        "        debug)\n"
        "            allegro_cflags=-DDEBUGMODE $allegro_cflags\n"
        "            allegro_cppflags=-DDEBUGMODE $allegro_cppflags\n"
        "            lib_type=alld\n"
        "        ;;\n"
        "\n"
        "        profile)\n"
        "            lib_type=allp\n"
        "        ;;\n"
        "\n"
        "        *)\n"
        "            usage 1 1>&2\n"
        "        ;;\n"
        "\n"
        "    esac\n"
        "    shift\n"
        "done\n"
        "\n"
        "if test \"$echo_prefix\" = \"yes\"; then\n"
        "    echo $prefix\n"
        "fi\n"
        "\n"
        "if test \"$echo_exec_prefix\" = \"yes\"; then\n"
        "    echo $exec_prefix\n"
        "fi\n"
        "\n"
        "if test \"$echo_cflags\" = \"yes\"; then\n"
        "    echo $allegro_cflags\n"
        "fi\n"
        "\n"
        "if test \"$echo_cppflags\" = \"yes\"; then\n"
        "    echo $allegro_cppflags\n"
        "fi\n"
        "\n"
        "if test \"$echo_libs\" = \"yes\"; then\n"
        "    libdirs=-L${exec_prefix}/lib\n"
        "    if test \"$static_libs\" = \"yes\"; then\n"
        "        echo $libdirs $allegro_ldflags -l${lib_type} $allegro_libs\n"
        "    else\n"
        "        echo $libdirs $allegro_ldflags -l${lib_type}-${version} -l${lib_type}_unsharable\n"
        "    fi\n"
        "fi\n"
        "\n"
        "if test \"$echo_env\" = \"yes\"; then\n"
        "    echo \"export PATH=\\$PATH:$prefix/bin\"\n"
        "    echo \"export LD_LIBRARY_PATH=\\$LD_LIBRARY_PATH:$prefix/lib\"\n"
        "    echo \"export LIBRARY_PATH=\\$LIBRARY_PATH:$prefix/lib\"\n"
        "    echo \"export C_INCLUDE_PATH=\\$C_INCLUDE_PATH:$prefix/include\"\n"
        "    echo \"export CPLUS_INCLUDE_PATH=\\$CPLUS_INCLUDE_PATH:$prefix/include\"\n"
        "    echo \"export OBJC_INCLUDE_PATH=\\$OBJC_INCLUDE_PATH:$prefix/include\"\n"
        "fi\n"
        "\n");
}



/* ARG_*
 *
 *  These define the position (and number) of commandline arguments. The
 *  utility is intended to be called from a shellscript or makefile, so
 *  this simple mechanism should be sufficient.
 */
#define ARG_ver_string 1
#define ARG_prefix 2
#define ARG_exec_prefix 3
#define ARG_static_libs 4
#define ARG_lib_type 5
#define ARG_ldflags 6
#define ARG_libs 7
#define ARG_compiler 8
#define ARG_cflags 9
#define ARG_cppflags 10
#define ARG_COUNT 11



/* main()
 */
int main(int argc, char* argv[])
{
    int need_Ipath;
    
    if(argc != ARG_COUNT) {
    }
    
    need_Ipath = determine_Ipath(argv[ARG_compiler], argv[ARG_cflags]);

    print_prelude();
    print_version(argv[ARG_ver_string]);
    print_prefix(argv[ARG_prefix], argv[ARG_exec_prefix]);
    print_lib_type(argv[ARG_static_libs], argv[ARG_lib_type]);
    print_ldflags(argv[ARG_ldflags]);
    print_libs(argv[ARG_libs]);
    print_cflags(argv[ARG_cflags], argv[ARG_cppflags], need_Ipath, argv[ARG_prefix]);
    print_usage();
    print_script();
    
    return 0;
}




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/