1/*
2 * Cygwin shared library rules (DLL versions)
3 */
4
5#define HasSharedLibraries	YES
6#define NeedLibInsideFlag	NO
7#define ForceNormalLib		NO
8#ifndef SharedLibX11
9# define SharedLibX11		YES
10#endif
11#ifndef NormalLibX11
12# define NormalLibX11		NO
13#endif
14#define SharedLibXaw		YES
15#define SharedLibXmu		YES
16#define SharedLibXt		YES
17#define SharedLibFont		NO
18#define SharedLibXaw7		YES
19#define SharedLibXaw6		YES
20#define SharedLibSM		YES
21#define SharedLibICE		YES
22#define SharedLibXext		YES
23#define SharedLibXi		YES
24#define SharedLibXtst		YES
25#define SharedOldX		NO
26#define SharedLibXp		NO
27#define SharedLibGlx		YES
28#define SharedLibDps		NO
29#define SharedLibDpsTk		NO
30#define SharedLibGlu		YES
31#define SharedLibWindowsWM	NO
32#ifndef SharedDataSeparation
33#define SharedDataSeparation	NO
34#endif
35
36#ifndef SharedCodeDef
37#define SharedCodeDef /**/
38#endif
39#ifndef SharedLibraryDef
40#define SharedLibraryDef /**/
41#endif
42#ifndef ShLibIncludeFile
43#define ShLibIncludeFile <cygwin.tmpl>
44#endif
45#ifndef SharedLibraryLoadFlags
46#define SharedLibraryLoadFlags -dll /**/
47#endif
48#ifndef PositionIndependentCFlags
49#define PositionIndependentCFlags -D_DLL
50#endif
51#ifndef PositionIndependentCplusplusFlags
52#define PositionIndependentCplusplusFlags -D_DLL
53#endif
54#ifndef UseExportLists
55#define UseExportLists YES
56#endif
57
58#define SharedLibraryName(libname, rev) \
59Concat3(cyg,libname,-$(shell echo rev|sed s=\\..*==).dll)
60
61#define ImportLibraryName(libname, rev) \
62Concat3(lib,libname,.dll.a)
63
64#define ShortImportLibraryName(libname, rev) \
65Concat3(lib,libname,.dll.a)
66
67/*
68 * SharedDepLibraryTarget - generate rules to create a shared library.
69 */
70
71#ifndef SharedDepLibraryTarget
72# ifdef UseInstalled
73#  ifndef LinkBuildSonameLibrary
74#   define LinkBuildSonameLibrary(lib)
75#  endif
76# else /* !UseInstalled */
77#  ifndef LinkBuildSonameLibrary
78#   define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); @@\
79	cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
80#  endif
81# endif /* UseInstalled */
82
83
84/*
85 * SharedDepLibraryTarget
86 */
87
88#define SharedDepLibraryTarget(libname,rev,deplist,solist,down,up)	@@\
89AllTarget(SharedLibraryName(libname,rev))                             @@\
90									@@\
91SharedLibraryName(libname,rev): deplist 				@@\
92	RemoveFile(ImportLibraryName(libname,rev))			@@\
93	RemoveFile(SharedLibraryName(libname,rev))			@@\
94	MakeDLL(libname,solist,rev)					@@\
95	LinkBuildLibrary(ImportLibraryName(libname,rev))		@@\
96	LinkImportLibrary(ImportLibraryName(libname,rev),LibraryTargetName(libname))	@@\
97	LinkBuildDLL(SharedLibraryName(libname,rev))			@@\
98									@@\
99clean::									@@\
100	RemoveFile(ImportLibraryName(libname,rev))				@@\
101	RemoveFile(SharedLibraryName(libname,rev))			@@\
102
103#endif /* SharedDepLibraryTarget */
104
105/*
106 * SharedDepCplusplusLibraryTarget - generate rules to create a shared library.
107 */
108
109#ifndef SharedDepCplusplusLibraryTarget
110# ifdef UseInstalled
111#  ifndef LinkBuildSonameLibrary
112#   define LinkBuildSonameLibrary(lib)
113#  endif
114# else /* !UseInstalled */
115#  ifndef LinkBuildSonameLibrary
116#   define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); @@\
117	cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
118#  endif
119# endif /* UseInstalled */
120
121
122/*
123 * SharedDepCplusplusLibraryTarget
124 */
125
126#define SharedDepCplusplusLibraryTarget(libname,rev,deplist,solist,down,up) @@\
127AllTarget(SharedLibraryName(libname,rev))                             @@\
128                                                                            @@\
129SharedLibraryName(libname,rev): deplist					@@\
130	RemoveFile(ImportLibraryName(libname,rev))                      @@\
131	RemoveFile(SharedLibraryName(libname,rev))                      @@\
132	MakeCplusplusDLL(libname,solist,rev)                            @@\
133	LinkBuildLibrary(ImportLibraryName(libname,rev))                @@\
134	LinkImportLibrary(ImportLibraryName(libname,rev),LibraryTargetName(libname))	@@\
135	LinkBuildDLL(SharedLibraryName(libname,rev))                    @@\
136                                                                        @@\
137clean::                                                                 @@\
138	RemoveFile(ImportLibraryName(libname,rev))                      @@\
139	RemoveFile(SharedLibraryName(libname,rev))                      @@\
140
141#endif /* SharedDepCplusplusLibraryTarget */
142
143
144/*
145 * SharedDepModuleTarget
146 */
147
148#ifndef SharedDepModuleTarget
149#define SharedDepModuleTarget(name,deps,solist)				@@\
150AllTarget(name)								@@\
151									@@\
152name: deps								@@\
153	$(CC) -o $@ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS) BaseShLibReqs @@\
154									@@\
155clean::									@@\
156	RemoveFile(name)
157#endif /* SharedDepModuleTarget */
158
159
160/*
161 * SharedLibraryDataTarget - generate rules to create shared data file
162 */
163
164#ifndef SharedLibraryDataTarget
165#define SharedLibraryDataTarget(libname,rev,salist)
166#endif
167
168
169/*
170 * InstallSharedLibraryData - generate rules to install the shared library data
171 */
172
173#ifndef InstallSharedLibraryData
174#define InstallSharedLibraryData(libname,rev,dest)
175#endif /* InstallSharedLibraryData */
176
177/*
178 * MakeDLLProg
179 */
180
181#define MakeDLLProg(libname,solist,prog,rev)			        @@\
182	prog -shared -Wl,--out-implib=ImportLibraryName(libname,rev) -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc -Wl,--exclude-libs,ALL -o SharedLibraryName(libname,rev) solist $(REQUIREDLIBS)
183
184/*
185 * MakeDLL
186 */
187
188#define MakeDLL(libname,solist,rev)					@@\
189    MakeDLLProg(libname,solist,$(CC),rev)
190
191/*
192 * MakeCplusplusDLL
193 */
194
195#define MakeCplusplusDLL(libname,solist,rev)				@@\
196    MakeDLLProg(libname,solist,$(CXX),rev)
197
198
199
200/*
201 * SharedLibraryTarget
202 */
203
204#define SharedLibraryTarget(libname,rev,solist,down,up)                 @@\
205AllTarget(SharedLibraryName(libname,rev))				@@\
206                                                                        @@\
207SharedLibraryName(libname,rev): solist					@@\
208	RemoveFile(ImportLibraryName(libname,rev))			@@\
209	RemoveFile(SharedLibraryName(libname,rev))			@@\
210	MakeDLL(libname,solist,rev)					@@\
211	LinkBuildLibrary(ImportLibraryName(libname,rev))		@@\
212	LinkImportLibrary(ImportLibraryName(libname,rev),LibraryTargetName(libname))	@@\
213	LinkBuildDLL(SharedLibraryName(libname,rev))			@@\
214clean::									@@\
215	RemoveFile(ImportLibraryName(libname,rev))			@@\
216	RemoveFile(SharedLibraryName(libname,rev))			@@\
217
218
219/*
220 * InstallLink
221 */
222
223#ifndef InstallLink
224#define InstallLink(step, file, link, dest)                             @@\
225step::                                                                  @@\
226	MakeDir($(DESTDIR)dest)                                         @@\
227	$(LN) -sf file $(DESTDIR)dest/link
228#endif
229
230/*
231 * InstallSharedLibrary
232 */
233
234#define InstallSharedLibrary(libname,rev,dest)                          @@\
235InstallTarget(install,ImportLibraryName(libname,rev),$(INSTLIBFLAGS),$(USRLIBDIR)) @@\
236InstallTarget(install,SharedLibraryName(libname,rev),$(INSTBINFLAGS),$(BINDIR))
237
238
239/*
240 * ProgramTargetName - This can be simply 'target' or 'target.exe' when
241 * building on Cygwin proper, as Cygwin automatically appends .exe to compiled
242 * executables and make, rm, ln, etc. will automatically search for a file
243 * with .exe appended if the raw file name cannot be found.  However,
244 * building with a cross compiler requires 'target.exe', as the cross
245 * compiler doesn't know to append .exe, nor do the cross compiler tools
246 * know to search for files with .exe appended if the raw file name cannot
247 * be found.
248 */
249
250#define ProgramTargetName(target) Concat(target,.exe)
251
252
253/*
254 * HostProgramTargetName - Don't add .exe if cross-compiling.
255 */
256
257#ifndef HostProgramTargetName
258# if CrossCompiling
259#  define HostProgramTargetName(target) target
260# else
261#  define HostProgramTargetName(target) ProgramTargetName(target)
262# endif
263#endif
264
265
266/*
267 * LinkBuildDLL - Cygwin only rule, similar to LinkBuildModule.
268 * Unfortunately, we have to create a copy of each DLL in xc/exports/bin;
269 * linking doesn't work, the executables (e.g. xkbcomp) will report
270 * that they cannot find DLLs (e.g. libX11.dll).
271 */
272
273#ifdef UseInstalled
274#define LinkBuildDLL(lib) $(_NULLCMD_)
275#else
276#define LinkBuildDLL(lib) MakeDir($(BUILDBINDIR))			@@\
277	RemoveFile($(BUILDBINDIR)/lib)					@@\
278	cd $(BUILDBINDIR) && $(CP) $(BUILDBINTOP)/$(CURRENT_DIR)/lib .
279#endif
280
281#ifndef LinkImportLibrary
282#ifdef UseInstalled
283#define LinkImportLibrary(lib, importlib) $(_NULLCMD_)
284#else
285#define LinkImportLibrary(lib, importlib) MakeDir($(BUILDLIBDIR))     @@\
286	RemoveFile($(BUILDLIBDIR)/importlib)                            @@\
287	cd $(BUILDLIBDIR) && $(LN) lib importlib
288#endif
289#endif /* LinkImportLibrary */
290
291
292/*
293 * LinkBuildBinary - This rule normally creates a link in xc/exports/bin
294 * to a binary, but we create an actual copy of the binary.
295 * Creating a link causes the DLLs that the binary depend on, such as
296 * libX11.dll, not to be found.  Copying the binary causes the runtime
297 * directory to be xc/exports/bin, which is the location of the DLLs, thus,
298 * the DLLs can now be found by the binary.  Phew...
299 *
300 * Note that sometimes the binary is not an executable.  One example
301 * is the rgb binary file.
302 *
303 * Passing -p preserves the attributes as the date and prevents useless
304 * rebuilds.
305 *
306 * ProgramTargetName is passed to LinkBuildBinary if the binary
307 * is actually an executable; thus, we do not wrap the binary name
308 * with ProgramTargetName here.
309 */
310
311#ifndef LinkBuildBinary
312#define LinkBuildBinary(binary)						@@\
313all:: binary								@@\
314	MakeDir($(BUILDBINDIR))						@@\
315	RemoveFile($(BUILDBINDIR)/binary)				@@\
316	cd $(BUILDBINDIR) && $(CP) -p $(BUILDBINTOP)/$(CURRENT_DIR)/binary .
317#endif /* LinkBuildBinary */
318
319/*
320 * ProfiledRelocatableTarget - generate rules to produce a  profiled
321 * relocatable object file instead of a library.  Differs from Imake.rules
322 * by passing '--oformat pe-i386' to ld.
323 */
324
325#ifndef ProfiledRelocatableTarget
326#define	ProfiledRelocatableTarget(objname,objlist)			@@\
327AllTarget(Concat(objname,_p.Osuf))					@@\
328									@@\
329Concat(objname,_p.Osuf): objlist $(EXTRALIBRARYDEPS)			@@\
330	RemoveFile($@)							@@\
331	$(LD) -X -r --oformat pe-i386 objlist -o $@
332
333#endif /* ProfiledRelocatableTarget */
334
335
336/*
337 * DebuggedRelocatableTarget - generate rules to produce a debuggable
338 * relocatable object file instead of a library.  Differs from Imake.rules
339 * by passing '--oformat pe-i386' to ld.
340 */
341
342#ifndef DebuggedRelocatableTarget
343#define	DebuggedRelocatableTarget(objname,objlist)			@@\
344AllTarget(Concat(objname,_d.Osuf))					@@\
345									@@\
346Concat(objname,_d.Osuf): objlist $(EXTRALIBRARYDEPS)			@@\
347	RemoveFile($@)							@@\
348	$(LD) -X -r --oformat pe-i386 objlist -o $@
349
350#endif /* DebuggedRelocatableTarget */
351
352
353/*
354 * DependDependencyStatement - Imake.rules wraps $(DEPEND) in
355 * ProgramTargetName(), which causes cross compiling to think that
356 * $(DEPEND) hasn't been built, as $(DEPEND) is a host tool, and should
357 * not be wrapped with ProgramTargetName().  Perhaps there should be
358 * a HostProgramTargetName()...
359 */
360
361#ifndef DependDependencyStatement
362#if HasMakefileSafeInclude
363#define DependDependencyStatement()					@@\
364DependFileName:: $(DEPEND)
365#else
366#define DependDependencyStatement()					@@\
367depend:: $(DEPEND)
368#endif
369#endif
370
371
372/*
373 * DependDependency - Imake.rules wraps $(DEPEND) in ProgramTargetName().
374 * This doesn't work when cross compiling, see the locally defined
375 * DependDependencyStatement comment (above) for more information.
376 */
377
378#ifndef DependDependency
379#ifdef UseInstalled
380#define DependDependency() /**/
381#else
382#define DependDependency()						@@\
383DependDependencyStatement()						@@\
384									@@\
385NoCmpScript($(DEPEND))							@@\
386									@@\
387$(DEPEND):								@@\
388	@echo "checking $@ over in $(DEPENDSRC) first..."; \		@@\
389	cd $(DEPENDSRC) && $(MAKE) makedependonly; \			@@\
390	echo "okay, continuing in $(CURRENT_DIR)"
391
392#endif /* UseInstalled */
393#endif /* DependDependency */
394
395
396/*
397 * ImakeDependency - Imake.rules wraps $(IMAKE) in ProgramTargetName(),
398 * which doesn't work when cross compiling, as imake is supposed to be a
399 * host program.  See the locally defined DependDependencyStatement
400 * comment (above) for more information.
401 */
402
403#ifndef ImakeDependency
404#ifdef UseInstalled
405#define ImakeDependency(target) /**/
406#else
407#define ImakeDependency(target)						@@\
408target:: $(IMAKE)							@@\
409									@@\
410NoCmpScript($(IMAKE) $(IMAKE).Osuf)					@@\
411									@@\
412$(IMAKE) $(IMAKE).Osuf:							@@\
413	-@(cd $(IMAKESRC) && if [ -f Makefile ]; then \			@@\
414	echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) imakeonly; else \	@@\
415	echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \	@@\
416	$(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"; fi; \	@@\
417	echo "okay, continuing in $(CURRENT_DIR)")
418#endif /* UseInstalled */
419#endif /* ImakeDependency */
420
421
422/*
423 * ResourceObjectRule - Build a Windows resource file (.res) into
424 * an object file (.o) that can be linked in with the executable
425 * or library being built.
426 */
427
428#ifndef ResourceObjectRule
429#define ResourceObjectRule(basename,depends,options)			@@\
430AllTarget(basename.RESsuf)						@@\
431basename.RESsuf: basename.RCsuf depends					@@\
432	RemoveFile($@)							@@\
433	ClearmakeOSName \						@@\
434	WindresCmd basename.RCsuf options -O coff -o basename.RESsuf	@@\
435clean::									@@\
436	RemoveFiles(basename.RESsuf)
437
438#endif /* ResourceObjectRule */
439
440/* The arglist can get quite long. Make sure we can delete it though */
441#ifndef MakeFonts
442# define MakeFonts()							@@\
443all::  $(OBJS)								@@\
444									@@\
445MakeFontsDir($(OBJS))							@@\
446									@@\
447clean::									@@\
448	find -name "*.pcf" -o -name "*.pcf.Z" -o -name "*.pcf.gz" | xargs -r rm
449#endif /* MakeFonts */
450
451#ifndef IncludeMakefile
452#define IncludeMakefile(file) @@sinclude file
453#endif
454