Standardized all libraries to have the same name, and removed which_lib

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/tools/make/trunk@23411 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2006-09-08 11:19:09 +00:00
parent 6092b77725
commit b6d7b6ebc0
18 changed files with 1888 additions and 4688 deletions

View file

@ -1,3 +1,45 @@
2006-09-08 Nicola Pero <nicola.pero@meta-innovation.com>
* common.make: Removed '_s' library name suffix for static
libraries. All libraries have the same name now!
(WHICH_LIB_SCRIPT): Variable removed.
* Instance/application.make (ALL_GUI_LIBS): Do not filter the
libraries using which_lib.
* Instance/bundle.make (ALL_BUNDLE_LIBS): Same change.
* Instance/ctool.make (ALL_TOOL_LIBS): Same change.
* Instance/framework.make (INTERNAL_LIBRARIES_DEPEND_UPON): Same change.
* Instance/gswapp.make (ALL_GSW_LIBS): Same change.
* Instance/gswbundle.make (GSWBUNDLE_INSTALL_DIR): Same change.
* Instance/library.make (INTERNAL_LIBRARIES_DEPEND_UPON): Same change.
* Instance/objc.make (ALL_OBJC_LIBS): Same change.
* Instance/palette.make (ALL_PALETTE_LIBS): Same change.
* Instance/service.make (ALL_SERVICE_LIBS): Same change.
* Instance/tool.make (ALL_TOOL_LIBS): Same change.
* Instance/palette.make: Removed duplicated (and commented out)
code for using all libs on some systems.
* GNUmakefile.in (all): Do not build which_lib.
(which_lib$(EXEEXT)): Rule removed.
(install): Do not install which_lib.
(uninstall): Do not uninstall which_lib.
(clean): Do not clean which_lib.
* configure.ac: Removed all the 'Miscellaneous headers' config, which
was only used when building which_lib.c
(AC_CONFIG_HEADER): Removed.
* configure: Regenerated.
* config.h.in: Removed.
* GNUmakefile.in (generated-files): Removed config.h
(config.h): Removed rule.
(all): Print a message so people are not confused when 'all' does
nothing.
* which_lib.c: File removed.
2006-09-07 Nicola Pero <nicola.pero@meta-innovation.com>
* common.make: Removed 'p' library name suffix for profile

View file

@ -107,22 +107,15 @@ INSTANCE_SHARED_MAKE_FILES = bundle.make headers.make java.make \
INSTANCE_DOC_MAKE_FILES = autogsdoc.make gsdoc.make install_files.make \
javadoc.make latex.make texi.make
all: generated-files which_lib$(EXEEXT)
# Please note that you should use a bit of care in the following rule,
# because it must work in a directory which is not the source
# directory - so for example $<, rather than which_lib.c, must be
# used. (I mean: 'cd core/make; cd ..; mkdir make-build; cd
# make-build; ../make/configure --disable-import; make;' must work)
which_lib$(EXEEXT): which_lib.c config.h
$(CC) @CFLAGS@ -Wall -I. -o $@ $<
ifeq ($(messages),yes)
EC =
else
EC = @
endif
all: generated-files
$(EC)(echo "Thanks. You can install now.")
move_obsolete:
$(EC)(echo "Moving paths from old heirarchy: "; \
$(srcdir)/move_obsolete_paths.sh "$(GNUSTEP_SYSTEM_ROOT)" "$(GNUSTEP_LOCAL_ROOT)" "$(GNUSTEP_USER_ROOT)")
@ -148,9 +141,7 @@ install: all @GNUSTEP_MOVE_OBSOLETE@
$(srcdir)/mkinstalldirs "$(GNUSTEP_CONFIG_FILE_DIR)"; \
$(INSTALL_DATA) GNUstep.conf "$(GNUSTEP_CONFIG_FILE)")
-$(EC) rm -f "$(GNUSTEP_SYSTEM_ROOT)/Makefiles"
$(EC)(echo "Installing gnustep-make support software"; \
$(INSTALL_PROGRAM) -m 755 which_lib$(EXEEXT) \
$(makedir)/$(GNUSTEP_TARGET_DIR))
$(EC)(echo "Installing gnustep-make support software")
$(EC)(for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
clean_vendor.sh cpu.sh GNUstep-reset.sh \
@ -205,7 +196,6 @@ install: all @GNUSTEP_MOVE_OBSOLETE@
# @echo ""
uninstall:
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/which_lib$(EXEEXT)
for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
clean_vendor.sh cpu.sh ld_lib_path.sh os.sh \
@ -249,8 +239,7 @@ uninstall:
# To really uninstall all of GNUstep, a 'rm -Rf ${GNUSTEP_ROOT}' should do.
clean:
rm -f *~ which_lib$(EXEEXT) \
Master/*~ Instance/*~ Instance/Shared/*~
rm -f *~ Master/*~ Instance/*~ Instance/Shared/*~
distclean: clean
rm -f GNUmakefile config.make config.h
@ -317,7 +306,7 @@ rpm: test-RPM_TOPDIR dist
fi; \
$${rpmbuild} -ba gnustep-make.spec
generated-files: GNUmakefile GNUstep.sh GNUstep.csh fixpath.sh config.h config.make debugapp openapp opentool gnustep-make.spec executable.template
generated-files: GNUmakefile GNUstep.sh GNUstep.csh fixpath.sh config.make debugapp openapp opentool gnustep-make.spec executable.template
GNUmakefile: GNUmakefile.in config.status
$(SHELL) config.status
@ -331,9 +320,6 @@ GNUstep.csh: GNUstep.csh.in
fixpath.sh: fixpath.sh.in
$(SHELL) config.status
config.h: config.h.in
$(SHELL) config.status
config.make: config.make.in Version
$(SHELL) config.status --recheck

View file

@ -59,14 +59,11 @@ ifeq ($(APP_INSTALL_DIR),)
endif
ALL_GUI_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_GUI_LIBS) $(AUXILIARY_GUI_LIBS) $(GUI_LIBS) \
$(BACKEND_LIBS) $(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) \
$(FND_LIBS) $(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) $(OBJC_LIBS) \
$(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS)
APP_DIR_NAME = $(GNUSTEP_INSTANCE:=.$(APP_EXTENSION))
APP_DIR = $(GNUSTEP_BUILD_DIR)/$(APP_DIR_NAME)

View file

@ -78,11 +78,8 @@ BUNDLE_LIBS += $(ADDITIONAL_GUI_LIBS) $(AUXILIARY_GUI_LIBS) $(BACKEND_LIBS) \
endif
ALL_BUNDLE_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(BUNDLE_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(ALL_LIB_DIRS) \
$(BUNDLE_LIBS)
ifeq ($(BUILD_DLL),yes)
BUNDLE_OBJ_EXT = $(DLL_LIBEXT)

View file

@ -46,12 +46,9 @@ endif
internal-ctool-uninstall_
ALL_TOOL_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) \
$(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(TARGET_SYSTEM_LIBS)
#
# Compilation targets

View file

@ -162,11 +162,8 @@ LIBRARIES_DEPEND_UPON += $(filter-out -l$(GNUSTEP_INSTANCE), \
endif
INTERNAL_LIBRARIES_DEPEND_UPON = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(LIBRARIES_DEPEND_UPON) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(LIBRARIES_DEPEND_UPON)
ifeq ($(FOUNDATION_LIB),gnu)

View file

@ -75,14 +75,11 @@ endif
# Libraries that go before the WO libraries
ALL_GSW_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_GSW_LIBS) $(AUXILIARY_GSW_LIBS) $(GSW_LIBS) \
$(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) \
$(FND_LIBS) $(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) \
$(OBJC_LIBS) $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(OBJC_LIBS) $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS)
GSWAPP_DIR_NAME = $(GNUSTEP_INSTANCE:=.$(GSWAPP_EXTENSION))
GSWAPP_DIR = $(GNUSTEP_BUILD_DIR)/$(GSWAPP_DIR_NAME)

View file

@ -88,10 +88,7 @@ endif
$(FND_LIBS) $(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) \
$(OBJC_LIBS) $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS)
#ALL_GSWBUNDLE_LIBS =
#ALL_GSWBUNDLE_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) $(ALL_LIB_DIRS) $(ALL_GSWBUNDLE_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) libext=$(LIBEXT) \
shared_libext=$(SHARED_LIBEXT))
#ALL_GSWBUNDLE_LIBS = $(ALL_LIB_DIRS) $(ALL_GSWBUNDLE_LIBS)
internal-gswbundle-all_:: $(GNUSTEP_OBJ_DIR) \
build-bundle-dir \

View file

@ -120,11 +120,8 @@ LIBRARIES_DEPEND_UPON += $(filter-out -l$(LIBRARY_NAME_WITHOUT_LIB), \
endif
INTERNAL_LIBRARIES_DEPEND_UPON = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(LIBRARIES_DEPEND_UPON) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(LIBRARIES_DEPEND_UPON)
ifeq ($(shared), yes)

View file

@ -46,12 +46,9 @@ OBJC_PROGRAM_INSTALL_DIR = $(GNUSTEP_TOOLS)
endif
ALL_OBJC_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) $(OBJC_LIBS) \
$(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(TARGET_SYSTEM_LIBS)
internal-objc_program-all_:: \
$(GNUSTEP_OBJ_DIR) \

View file

@ -43,19 +43,7 @@ endif
internal-palette-uninstall_ \
internal-palette-copy_into_dir
# On Solaris we don't need to specifies the libraries the palette needs.
# How about the rest of the systems? ALL_PALETTE_LIBS is temporary empty.
#ALL_PALETTE_LIBS = $(ADDITIONAL_GUI_LIBS) $(AUXILIARY_GUI_LIBS) $(BACKEND_LIBS) \
# $(GUI_LIBS) $(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) \
# $(FND_LIBS) $(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) $(OBJC_LIBS) \
# $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS)
#ALL_PALETTE_LIBS := \
# $(shell $(WHICH_LIB_SCRIPT) $(ALL_LIB_DIRS) $(ALL_PALETTE_LIBS) \
# debug=$(debug) profile=$(profile) shared=$(shared) libext=$(LIBEXT) \
# shared_libext=$(SHARED_LIBEXT))
# On windows, this is unfortunately required.
ifeq ($(BUILD_DLL), yes)
LINK_PALETTE_AGAINST_ALL_LIBS = yes
endif
@ -74,11 +62,8 @@ PALETTE_LIBS += $(ADDITIONAL_GUI_LIBS) $(AUXILIARY_GUI_LIBS) $(BACKEND_LIBS) \
endif
ALL_PALETTE_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(PALETTE_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(PALETTE_LIBS)
ifeq ($(BUILD_DLL),yes)
PALETTE_OBJ_EXT = $(DLL_LIBEXT)

View file

@ -41,14 +41,11 @@ endif
# Libraries that go before the GUI libraries
ALL_SERVICE_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_GUI_LIBS) $(AUXILIARY_GUI_LIBS) \
$(GUI_LIBS) $(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) \
$(FND_LIBS) $(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) \
$(OBJC_LIBS) $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(OBJC_LIBS) $(SYSTEM_LIBS) $(TARGET_SYSTEM_LIBS)
# Don't include these definitions the first time make is invoked. This part is
# included when make is invoked the second time from the %.build rule (see

View file

@ -53,13 +53,10 @@ ifeq ($(FINAL_TOOL_INSTALL_DIR),)
endif
ALL_TOOL_LIBS = \
$(shell $(WHICH_LIB_SCRIPT) \
$(ALL_LIB_DIRS) \
$(ADDITIONAL_TOOL_LIBS) $(AUXILIARY_TOOL_LIBS) $(FND_LIBS) \
$(ADDITIONAL_OBJC_LIBS) $(AUXILIARY_OBJC_LIBS) $(OBJC_LIBS) \
$(TARGET_SYSTEM_LIBS) \
debug=$(debug) profile=$(profile) shared=$(shared) \
libext=$(LIBEXT) shared_libext=$(SHARED_LIBEXT))
$(TARGET_SYSTEM_LIBS)
#
# Compilation targets

View file

@ -70,12 +70,6 @@ CONFIG_OS_SCRIPT = $(GNUSTEP_MAKEFILES)/os.sh
CLEAN_CPU_SCRIPT = $(GNUSTEP_MAKEFILES)/clean_cpu.sh
CLEAN_VENDOR_SCRIPT = $(GNUSTEP_MAKEFILES)/clean_vendor.sh
CLEAN_OS_SCRIPT = $(GNUSTEP_MAKEFILES)/clean_os.sh
ifeq ($(GNUSTEP_FLATTENED),)
WHICH_LIB_SCRIPT \
= $(GNUSTEP_MAKEFILES)/$(GNUSTEP_HOST_CPU)/$(GNUSTEP_HOST_OS)/which_lib
else
WHICH_LIB_SCRIPT = $(GNUSTEP_MAKEFILES)/which_lib
endif
LD_LIB_PATH_SCRIPT = $(GNUSTEP_MAKEFILES)/ld_lib_path.sh
TRANSFORM_PATHS_SCRIPT = $(GNUSTEP_MAKEFILES)/transform_paths.sh
REL_PATH_SCRIPT = $(GNUSTEP_MAKEFILES)/relative_path.sh
@ -435,7 +429,6 @@ else
LIB_LINK_CMD = $(STATIC_LIB_LINK_CMD)
OBJ_DIR_PREFIX += static_
AFTER_INSTALL_LIBRARY_CMD = $(AFTER_INSTALL_STATIC_LIB_CMD)
LIBRARY_NAME_SUFFIX := _s
endif
ifeq ($(profile), yes)

View file

@ -1,100 +0,0 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <ctype.h> header file. */
#undef HAVE_CTYPE_H
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the <dir.h> header file. */
#undef HAVE_DIR_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `geteuid' function. */
#undef HAVE_GETEUID
/* Define to 1 if you have the `getlogin' function. */
#undef HAVE_GETLOGIN
/* Define to 1 if you have the `getpwnam' function. */
#undef HAVE_GETPWNAM
/* Define to 1 if you have the `getpwuid' function. */
#undef HAVE_GETPWUID
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strchr' function. */
#undef HAVE_STRCHR
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

5530
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,6 @@
AC_INIT
AC_PREREQ(2.57)
AC_CONFIG_SRCDIR([application.make])
AC_CONFIG_HEADER(config.h)
#--------------------------------------------------------------------
# Setup the library combination
@ -711,14 +710,6 @@ fi
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$gs_cv_objc_libdir"
export LD_LIBRARY_PATH
#--------------------------------------------------------------------
# Miscellaneous headers (only used for compiling which_lib.c and user_home.c)
#--------------------------------------------------------------------
AC_HEADER_DIRENT
AC_CHECK_HEADERS(sys/param.h sys/file.h dir.h string.h stdlib.h sys/types.h dnl
fcntl.h limits.h utime.h sys/stat.h pwd.h unistd.h ctype.h)
AC_CHECK_FUNCS(getpwnam getpwuid geteuid getlogin strchr)
#--------------------------------------------------------------------
# Check if libobjc was compiled with thread support.
#--------------------------------------------------------------------

View file

@ -1,793 +0,0 @@
/*
which_lib.c
Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
Author: Nicola Pero <nicola@brainstorm.co.uk>
Date: January 2002
Based on the original which_lib.c by Ovidiu Predescu,
Author: Ovidiu Predescu <ovidiu@net-community.com>
Date: October 1997
This file is part of the GNUstep Makefile Package.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*
Command line arguments are:
* a list of library search paths in the GCC notation, as in
-L/usr/lib/opt/hack/
-L/usr/GNUstep/Local/Library/Libraries/ix86/linux-gnu/gnu-gnu-gnu
-L/usr/GNUstep/System/Library/Libraries/ix86/linux-gnu/gnu-gnu-gnu
(order is important, paths are searched in the order they are listed);
* a list of libraries in the GCC notation, as in
-lgnustep-base -lgnustep-gui -lobjc
* flags specifying whether a static/shared library is
to be preferred, as in shared=yes
The tool outputs the same list of library search paths and the list
of libraries it received in input, with an important modification:
each library name is modified to match the available version of the
library (by appending nothing for a normal or debug library, _s for
a static one) -- giving preference to libraries matching the
specified shared library flags. For example, if shared=yes is
specified, and libgnustep-base.so is in the library search path,
which_lib will replace -lgnustep-base with -lgnustep-base in the
output.
Here is exactly how the search is performed:
The tool first searches into the list of directories for a library
exactly matching the name and the type required. If found, it's
used.
If none is found, the library looks for an approximate match, as
detailed in the following list. Each search in the following list
is performed on the list of directories, and uses the shared flags
as specified.
If none is still found and shared=yes, the tool looks for any
available shared library with that name.
If none is still found, the tool looks for any available static
library with that name (regardless of any shared flag).
If still not found, the tool outputs the unmodified library name (as
in -lgnustep-base) ... perhaps the library is somewhere else in the
linker path ... otherwise that will normally result in a linker
error later on.
*/
#include "config.h"
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_CTYPE_H
# include <ctype.h>
#endif
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#include <fcntl.h>
#if HAVE_DIRENT_H
# include <dirent.h>
#else
# define dirent direct
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
/* determine filesystem max path length */
# include <limits.h> /* for PATH_MAX */
#ifdef _POSIX_VERSION
# include <utime.h>
#else
# if HAVE_SYS_PARAM_H
# include <sys/param.h> /* for MAXPATHLEN */
# endif
#endif
#ifndef PATH_MAX
# ifdef _POSIX_VERSION
# define PATH_MAX _POSIX_PATH_MAX
# else
# ifdef MAXPATHLEN
# define PATH_MAX MAXPATHLEN
# else
# define PATH_MAX 1024
# endif
# endif
#endif
#if HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
/* Extension used for shared and non-shared libraries. */
char* libext = ".a";
char* shared_libext = ".so";
/* If set to 1, all code will print out information about what it
does. */
int show_all = 0;
/* Strips off carriage returns, newlines and spaces at the end of the
string. (this removes some \r\n issues on Windows) */
static void stripstr (char *s)
{
unsigned len;
if (s == NULL)
{
return;
}
len = strlen (s);
while (len > 0)
{
len--;
if (isspace(s[len]))
{
s[len] = '\0';
}
}
}
/* Normalize the directory, and checks that it exists on disk and is a
directory. Return the normalized path, or NULL if the path does
not exist on disk, or is not a valid directory. */
static char *normalize_and_check_dir (char *path)
{
int length = strlen (path);
char *normalized_path = NULL;
struct stat statbuf;
#ifdef __MINGW32__
if (path[0] == '/' && path[1] == '/')
{
/* Convert //server/ to a format Windows functions understand. */
char *s;
/* Convert //server/path/to/ --> server/path/to/ */
normalized_path = malloc (length * sizeof (char));
strcpy (normalized_path, &(path[2]));
/* Convert server/path/to/ --> server:/path/to/ */
s = strchr (normalized_path, '/');
if (s)
{
/* The index of the '/' after 'server' in the original path. */
int index = 2 + (s - normalized_path);
*s = ':';
strcpy (s + 1, &(path[index]));
}
}
else
#endif
{
normalized_path = malloc ((length + 1) * sizeof (char));
strcpy (normalized_path, path);
}
/* Now check that the path exists and is a directory. */
if (stat (normalized_path, &statbuf) < 0)
/* Error occured or dir doesn't exist */
{
if (show_all)
{
fprintf (stderr, "Library path '%s' doesn't exist - ignored\n",
normalized_path);
}
free (normalized_path);
return NULL;
}
else if ((statbuf.st_mode & S_IFMT) != S_IFDIR)
/* Not a directory */
{
if (show_all)
{
fprintf (stderr, "Library path '%s' isn't a directory - ignored\n",
normalized_path);
}
free (normalized_path);
return NULL;
}
stripstr (normalized_path);
return normalized_path;
}
/* Search for a library with library_name, suffix suffix and
extension ext.
library_name must not contain the suffix, so library_name should
be something like 'gnustep-base'.
suffix is the wanted suffix (valid suffixes are "", _s).
Must not be NULL.
ext is the wanted extension (normally, either .so or .a). Must
not be NULL.
Return 0 if it doesn't find anything matching.
Return 1 if a library with the appropriate suffix/extension/type
matches in 'path' and print to stdout the name of the library. */
static int search_for_lib_with_suffix_and_ext (const char *library_name,
char **library_paths,
int paths_no,
char *suffix,
char *ext)
{
/* Iterate over the library_paths, looking for the library. */
int i;
for (i = 0; i < paths_no; i++)
{
char full_filename[PATH_MAX + 1];
struct stat statbuf;
#ifdef __MINGW32__
if (strcmp (ext, ".dll.a") == 0)
{
/* Mingw can link against dlls directly, so if we're
* currently searching for libxxx.dll.a, make a try first at
* xxx.dll. The standard algorithm will search for
* libxxx.dll.a (and failing that libxxx.a) later.
*/
strcpy (full_filename, library_paths[i]);
strcat (full_filename, "/");
strcat (full_filename, library_name);
strcat (full_filename, suffix);
strcat (full_filename, ".dll");
if (show_all)
{
fprintf (stderr, " %s\n", full_filename);
}
if (stat (full_filename, &statbuf) >= 0)
{
goto library_found;
}
}
#endif
strcpy (full_filename, library_paths[i]);
strcat (full_filename, "/lib");
strcat (full_filename, library_name);
strcat (full_filename, suffix);
strcat (full_filename, ext);
if (show_all)
{
fprintf (stderr, " %s\n", full_filename);
}
if (stat (full_filename, &statbuf) < 0)
/* Error - likely that file doesn't exist. */
{
continue;
}
#ifdef __MINGW32__
library_found:
#endif
if ((statbuf.st_mode & S_IFMT) == S_IFREG)
/* Found it! */
{
if (show_all)
{
fprintf (stderr, " Found!\n");
}
printf (" -l%s", library_name);
if (*suffix)
{
printf ("%s", suffix);
}
return 1;
}
}
return 0;
}
/* Search for a library with library_name, extension ext and any
valid suffix.
The same comments as for 'search_for_lib_with_suffix_and_ext' apply,
except that any valid suffix is accepted (valid suffixes are: "",
_s).
*/
static int search_for_lib_with_ext (const char *library_name,
int library_name_len,
char **library_paths,
int paths_no,
char *ext)
{
/* Iterate over the library_paths, looking for the library. */
int i;
for (i = 0; i < paths_no; i++)
{
DIR* dir;
struct dirent* dirbuf;
int found = 0;
if (show_all)
{
fprintf (stderr, " %s/lib%s??%s\n", library_paths[i],
library_name, ext);
}
dir = opendir (library_paths[i]);
if (dir == NULL)
{
/* For some reasons, we can't read that path. Perhaps
someone removed the directory while we were running :-) */
continue;
}
while ((dirbuf = readdir (dir)))
{
/* Skip if it doesn't begin with 'lib'. This implicitly
skips "." and ".." in case they are returned. */
if (dirbuf->d_name[0] != 'l')
{
continue;
}
if (dirbuf->d_name[1] != 'i')
{
continue;
}
if (dirbuf->d_name[2] != 'b')
{
continue;
}
/* Skip if it does not match the library name. */
if (strncmp (dirbuf->d_name + 3, library_name, library_name_len))
{
continue;
}
else
{
int filelen, extlen;
filelen = strlen (dirbuf->d_name);
extlen = strlen (ext);
if (filelen - extlen <= 0)
{
/* Quite worrying this case. */
continue;
}
if (show_all)
{
fprintf (stderr, " Considering %s\n", dirbuf->d_name);
}
/* First check if the extension matches */
if (strcmp (dirbuf->d_name + filelen - extlen, ext))
{
/* No luck, skip this file */
continue;
}
/* The extension matches. Check the last remaining bit
- that the remaining string we have not checked is
one of the allowed suffixes. The allowed suffixes
are: "", _s. */
{
char f_suffix[5];
int j;
int suffix_len = filelen - (3 /* 'lib' */
+ library_name_len
/* library_name */
+ extlen /* .so/.a */);
switch (suffix_len)
{
/* In the following cases, 'break' means found,
'continue' means not found. */
case 0:
{
/* nothing - it's Ok. */
break;
}
case 1:
{
continue;
}
case 2:
{
/* Must be one of _s */
char c;
if (dirbuf->d_name[3 + library_name_len] != '_')
{
continue;
}
c = dirbuf->d_name[3 + library_name_len + 1];
if (c != 's')
{
continue;
}
break;
}
default:
{
continue;
}
}
/* If we're here, it's because it was found! */
if (show_all)
{
fprintf (stderr, " Found!\n");
}
for (j = 0; j < suffix_len; j++)
{
f_suffix[j] = dirbuf->d_name[library_name_len + 3 + j];
}
f_suffix[j] = '\0';
printf (" -l%s%s", library_name, f_suffix);
found = 1;
break;
}
}
}
closedir (dir);
if (found)
{
return 1;
}
}
return 0;
}
/* Search for the library everywhere, and returns the library name. */
static void output_library_name (const char *library_name,
char** library_paths, int paths_no,
int shared,
char *libname_suffix)
{
char *extension = shared ? shared_libext : libext;
int library_name_len = strlen (library_name);
if (show_all)
{
fprintf (stderr, "\n>>Library %s:\n", library_name);
}
/* We first perform the search of a matching library in all dirs. */
if (show_all)
{
fprintf (stderr, "Scanning all paths for an exact match\n");
}
if (search_for_lib_with_suffix_and_ext (library_name,
library_paths, paths_no,
libname_suffix,
extension))
{
return;
}
/* The library was not found. Try various approximations first,
slightly messing the original profile requests, but still
honouring the shared=yes|no requirement. */
if (show_all)
{
fprintf (stderr, "Scanning all paths for an approximate match\n");
}
/* The library was still not found. Try to get whatever library we
have there. */
/* If a shared library is needed try to find a shared one first.
Any shared library is all right. */
if (shared)
{
if (show_all)
{
fprintf (stderr,
"Scanning all paths for any shared lib with that name\n");
}
if (search_for_lib_with_ext (library_name, library_name_len,
library_paths, paths_no, shared_libext))
{
return;
}
}
/* Last hope - return a static library with name 'library_name'.
Any static library is all right. */
if (show_all)
{
fprintf (stderr,
"Scanning all paths for any static lib with that name\n");
}
if (search_for_lib_with_ext (library_name, library_name_len,
library_paths, paths_no, libext))
{
return;
}
/* We couldn't locate the library. Output the library name we were
given, without any modification. Possibly it's somewhere else on
the linker path, otherwise (more likely) a linker error will
occur. Nothing we can do about it. */
if (show_all)
{
fprintf (stderr, "Library not found, using unmodified library name\n");
}
printf (" -l%s", library_name);
return;
}
int main (int argc, char** argv)
{
int i;
/* Type of libraries we prefer. */
int shared = 1;
/* Suffix of the libraries we prefer - something like "" or
"_s" */
char libname_suffix[5];
/* Array of strings that are the library paths passed on the command
line. If we are on Windows, we convert library paths to a format
that Windows functions understand before we save the paths in
library_paths, so that you could pass them to Windows functions
accessing the filesystem. We also check that the paths actually
exist on disk, and are directories, before putting them in the
array. */
int paths_no = 0;
char** library_paths = NULL;
/* The list of libraries */
int libraries_no = 0;
char** all_libraries = NULL;
/* Other flags which are printed to the output as they are. */
int other_flags_no = 0;
char** other_flags = NULL;
#ifdef __WIN32__
setmode(1, O_BINARY);
setmode(2, O_BINARY);
#endif
if (argc == 1)
{
printf ("usage: %s [-Lpath ...] -llibrary shared=yes|no "
"libext=string shared_libext=string "
"[show_all=yes]\n", argv[0]);
exit (1);
}
for (i = 1; i < argc; i++)
{
/* First switch basing on the first letter of each argument,
then compare. */
switch (argv[i][0])
{
case '-':
{
if (argv[i][1] == 'l')
{
if (all_libraries)
{
all_libraries = realloc (all_libraries,
(libraries_no + 1)
* sizeof (char*));
}
else
{
all_libraries = malloc ((libraries_no + 1)
* sizeof (char*));
}
all_libraries[libraries_no] = malloc (strlen (argv[i]) - 1);
strcpy (all_libraries[libraries_no], argv[i] + 2);
stripstr (all_libraries[libraries_no]);
libraries_no++;
continue;
}
else if (argv[i][1] == 'L')
{
char *lib_path = normalize_and_check_dir (argv[i] + 2);
/* Always print out the library search path flag,
regardless. */
printf (" %s", argv[i]);
if (lib_path != NULL)
{
if (library_paths)
{
library_paths = realloc (library_paths,
(paths_no + 1)
* sizeof (char*));
}
else
{
library_paths = malloc ((paths_no + 1)
* sizeof(char*));
}
library_paths[paths_no] = lib_path;
paths_no++;
}
continue;
}
break;
}
case 'l':
{
if (!strncmp (argv[i], "libext=", 7))
{
libext = malloc (strlen (argv[i] + 7) + 1);
strcpy (libext, argv[i] + 7);
continue;
}
break;
}
case 's':
{
if (!strncmp (argv[i], "shared=", 7))
{
shared = !strncmp (argv[i] + 7, "yes", 3);
continue;
}
else if (!strncmp (argv[i], "shared_libext=", 14))
{
shared_libext = malloc (strlen (argv[i] + 14) + 1);
strcpy (shared_libext, argv[i] + 14);
continue;
}
else if (!strncmp (argv[i], "show_all=", 9))
{
show_all = !strncmp (argv[i] + 9, "yes", 3);
continue;
}
break;
}
default:
break;
}
/* The flag is something different; keep it in the `other_flags' */
if (other_flags)
{
other_flags = realloc (other_flags,
(other_flags_no + 1) * sizeof (char*));
}
else
{
other_flags = malloc ((other_flags_no + 1) * sizeof (char*));
}
other_flags[other_flags_no] = malloc (strlen (argv[i]) + 1);
strcpy (other_flags[other_flags_no], argv[i]);
other_flags_no++;
}
/* Determine the exact libname_suffix of the libraries we are
looking for. */
libname_suffix[0] = '_';
libname_suffix[1] = '\0';
libname_suffix[2] = '\0';
libname_suffix[3] = '\0';
libname_suffix[4] = '\0';
i = 1;
if (!shared)
{
libname_suffix[i] = 's';
i++;
}
if (i == 1)
{
libname_suffix[0] = '\0';
}
if (show_all)
{
fprintf (stderr, ">>Input:\n");
fprintf (stderr, "shared = %d\n", shared);
fprintf (stderr, "libname_suffix = %s\n", libname_suffix);
fprintf (stderr, "libext = %s\n", libext);
fprintf (stderr, "shared_libext = %s\n", shared_libext);
fprintf (stderr, "library names:\n");
for (i = 0; i < libraries_no; i++)
{
fprintf (stderr, " %s\n", all_libraries[i]);
}
fprintf (stderr, "library paths:\n");
for (i = 0; i < paths_no; i++)
{
fprintf (stderr, " %s\n", library_paths[i]);
}
fprintf (stderr, "other flags:\n");
for (i = 0; i < other_flags_no; i++)
{
fprintf (stderr, " %s\n", other_flags[i]);
}
}
/* Now output the libraries. */
for (i = 0; i < libraries_no; i++)
{
/* Search for the library, and print (using -l%s) the library
name to standard output. */
output_library_name (all_libraries[i], library_paths,
paths_no, shared, libname_suffix);
}
/* Output the other flags */
for (i = 0; i < other_flags_no; i++)
{
printf (" %s", other_flags[i]);
}
printf (" ");
return 0;
}