added jam build system, please try it out - the advantage would be that it already...
[supertux.git] / mk / jam / library.jam
1 #============================================================================
2 # Rules for library creation
3 #============================================================================
4
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
12 ##    library.
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
17 ##    leading "lib".
18 rule Library
19 {
20     # check options
21     CheckOptions noinstall independent shared : $(3) : $(<) ;
22
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 ;
28
29     $(<)_TYPE = library ;
30     $(<)_OBJECTS = $(objects) ;
31     $(<)_SOURCES = $(sources) ;
32     $(<)_TARGET = $(target) ;
33     $(<)_OPTIONS = $(3) ;
34
35     # create target clean rule
36     Always $(<)clean ;
37     NotFile $(<)clean ;
38     Clean $(<)clean : $(objects) ; # create target clean rule 
39
40     # so 'jam foo' works when it's really foo.exe (Windows) or foo.app (MacOS/X)
41     if $(target) != $(<)
42     {
43         Depends $(<) : $(target) ;
44         NotFile $(<) ;                                                              }
45
46     # library depends on its member objects
47     if ! [ IsElem independent : $(3) ]
48     {
49         if $(KEEPOBJS)
50         {
51             Depends obj : $(objects) ;
52         }
53         else
54         {
55             Depends libs : $(<) ;
56         }
57     }
58
59     # Generate install rules
60     if ! [ IsElem noinstall : $(3) ]
61     {
62         install_targets = [ DoInstall $(target) : $(libdir) ] ;
63         Depends install_lib : $(install_targets) ;
64     }
65
66     if [ IsElem shared : $(3) ]
67     {
68         if ! $(LIBTOOL) {
69             exit "LIBTOOL not defined, can't create dynamic library." ;
70         }
71         no_scan_archive = 1 ;
72         DoLibToolClean ;
73
74         if $(install_targets) {
75             INSTALL on $(install_targets) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
76             InvokeLibtoolFinish $(install_targets) ;
77         }
78     }
79
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.
84     if ! $(target:D)
85     {
86         MakeLocate $(target) $(target)($(objects:BS)) : $(LOCATE_TARGET) ;
87     }
88
89     if ! $(no_scan_archive)
90     {
91         # If we can scan the library, we make the library depend
92         # on its members and each member depend on the on-disk
93         # object file.
94         Depends $(target) : $(target)($(objects:BS)) ;
95
96         local i ;
97         for i in $(objects)
98         {
99             Depends $(target)($(i:BS)) : $(i) ;
100         }
101     } else {
102         Depends $(target) : $(objects) ;
103     }
104
105     if $(CRELIB) { CreLib $(target) : $(objects[1]) ; }
106
107     SystemLinkLibrary $(<) : $(objects) : $(3) ;
108
109     # If we can't scan the library, we have to leave the .o's around.
110     if ! ( $(no_scan_archive) || $(NOARUPDATE) )
111     {
112         RmTemps $(target) : $(objects) ;
113     }
114
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) ;
120 }
121
122 ##  LibraryVersion
123 ##    Specify the version of a library. The version should have the form
124 ##    major:minor:patchlevel
125 rule LibraryVersion
126 {
127     LFLAGS on $($(<)_TARGET) = -version-info $(>) ;
128 }
129
130 #----------------------------------------------------------------------------
131 # private part
132
133 # default implementation of SystemLinkLibrary
134 rule SystemLinkLibrary
135 {
136     local target = $($(<)_TARGET) ;
137    
138     if [ IsElem shared : $(3) ] {
139         LINK on $(target) = "$(LIBTOOL) --mode=link $(LINK) -rpath $(libdir)" ;
140         LinkLibrary $(target) : $(>) ;
141     } else {
142         Archive $(target) : $(>) ;
143         if $(RANLIB) { Ranlib $(target) ; }
144     }
145                                                                                 
146     Clean clean : $(target) ;
147     Clean $(<)clean : $(target) ;
148 }
149
150 actions together Ranlib
151 {
152     $(RANLIB) $(<)
153 }
154
155 actions LinkLibrary bind NEEDLIBS bind EXTRAOBJECTS
156 {
157     $(LINK) -o $(<) $(>) $(EXTRAOBJECTS) $(NEEDLIBS) $(LFLAGS)
158 }
159
160 # Construct pseudo target libs which is used instead of the pseudo target lib
161 # in Jambase
162 Depends lib : libs ;
163 NotFile libs ;
164