1 #============================================================================
2 # Rules for library creation
3 #============================================================================
5 ## Library libname : sources [ : options ]
6 ## Build a library out of sourcefiles. All sourcefiles will be passed
7 ## to the Objects rule which tries to compile them into object-files. You
8 ## can create rules for your own filetypes with the UserObject rule. Header
9 ## files will just be ignored. They are only used for MSVC projectfile
10 ## generation. If additional objects are given (fourth argument), they
11 ## should be the output of CompileObjects, and will be included in the
13 ## Available options are 'shared' if you want to build a shared library on
14 ## platforms which support that. You can specify the 'noinstall' option if
15 ## you don't want an install target is generated.
16 ## Don't specify any extensions for the library name, also leave out the
21 CheckOptions noinstall independent shared : $(3) : $(<) ;
23 local no_scan_archive = $(NOARSCAN) ;
24 local target = [ ConstructLibraryTarget $(<) : $(3) ] ;
25 local sources = [ DoSourceGrist $(>) ] ;
26 local objects = [ CompileObjects $(sources) : $(3) ] ;
27 local install_targets ;
30 $(<)_OBJECTS = $(objects) ;
31 $(<)_SOURCES = $(sources) ;
32 $(<)_TARGET = $(target) ;
35 # create target clean rule
38 Clean $(<)clean : $(objects) ; # create target clean rule
40 # so 'jam foo' works when it's really foo.exe (Windows) or foo.app (MacOS/X)
43 Depends $(<) : $(target) ;
46 # library depends on its member objects
47 if ! [ IsElem independent : $(3) ]
51 Depends obj : $(objects) ;
59 # Generate install rules
60 if ! [ IsElem noinstall : $(3) ]
62 install_targets = [ DoInstall $(target) : $(libdir) ] ;
63 Depends install_lib : $(install_targets) ;
66 if [ IsElem shared : $(3) ]
69 exit "LIBTOOL not defined, can't create dynamic library." ;
74 if $(install_targets) {
75 INSTALL on $(install_targets) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
76 InvokeLibtoolFinish $(install_targets) ;
80 # Set LOCATE for the library and its contents. The bound
81 # value shows up as $(NEEDLIBS) on the Link actions.
82 # For compatibility, we only do this if the library doesn't
83 # already have a path.
86 MakeLocate $(target) $(target)($(objects:BS)) : $(LOCATE_TARGET) ;
89 if ! $(no_scan_archive)
91 # If we can scan the library, we make the library depend
92 # on its members and each member depend on the on-disk
94 Depends $(target) : $(target)($(objects:BS)) ;
99 Depends $(target)($(i:BS)) : $(i) ;
102 Depends $(target) : $(objects) ;
105 if $(CRELIB) { CreLib $(target) : $(objects[1]) ; }
107 SystemLinkLibrary $(<) : $(objects) : $(3) ;
109 # If we can't scan the library, we have to leave the .o's around.
110 if ! ( $(no_scan_archive) || $(NOARUPDATE) )
112 RmTemps $(target) : $(objects) ;
115 # Import default flags
116 CppFlags $(<) : $(CPPFLAGS) $(LIBRARY_CPPFLAGS) ;
117 CFlags $(<) : $(CFLAGS) $(LIBRARY_CFLAGS) ;
118 C++Flags $(<) : $(C++FLAGS) $(LIBRARY_C++FLAGS) ;
119 LFlags $(<) : $(LFLAGS) $(LIBRARY_LFLAGS) ;
123 ## Specify the version of a library. The version should have the form
124 ## major:minor:patchlevel
127 LFLAGS on $($(<)_TARGET) = -version-info $(>) ;
130 #----------------------------------------------------------------------------
133 # default implementation of SystemLinkLibrary
134 rule SystemLinkLibrary
136 local target = $($(<)_TARGET) ;
138 if [ IsElem shared : $(3) ] {
139 LINK on $(target) = "$(LIBTOOL) --mode=link $(LINK) -rpath $(libdir)" ;
140 LinkLibrary $(target) : $(>) ;
142 Archive $(target) : $(>) ;
143 if $(RANLIB) { Ranlib $(target) ; }
146 Clean clean : $(target) ;
147 Clean $(<)clean : $(target) ;
150 actions together Ranlib
155 actions LinkLibrary bind NEEDLIBS bind EXTRAOBJECTS
157 $(LINK) -o $(<) $(>) $(EXTRAOBJECTS) $(NEEDLIBS) $(LFLAGS)
160 # Construct pseudo target libs which is used instead of the pseudo target lib