Makefile.orig 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. .PHONY: all clean install
  2. DLOPEN=1
  3. #USE_ZLIB=1
  4. prefix=/usr/local
  5. exec_prefix=${prefix}
  6. includedir=${prefix}/include
  7. libdir=${exec_prefix}/lib
  8. INSTALL=/usr/bin/install -c
  9. INSTALL_PROGRAM=${INSTALL}
  10. INSTALL_DATA=${INSTALL} -m 644
  11. #RANLIB=ranlib
  12. CC=gcc
  13. CFLAGS0:=$(CFLAGS) -I. -Wall -W -O3 -DHAVE_CONFIG_H
  14. CFLAGS=$(CFLAGS0) -DDLL
  15. ifdef DLOPEN
  16. CFLAGS+=-DDLOPEN
  17. endif
  18. ifneq ($(findstring darwin,$(OSTYPE)),darwin) # for example "darwin7.0"
  19. # On Mac OS X using -s gives the following warning:
  20. # /usr/bin/libtool: -static not specified, -s invalid
  21. LDFLAGS+=-s
  22. endif
  23. # The test for Cygwin should be done before the test for DJGPP, because the
  24. # environment variable DJGPP can be set in Bash for people who have installed
  25. # both GCC (and friends) ports.
  26. GCC_WIN=0
  27. ifeq ($(OSTYPE),cygwin) # test cygwin before DJGPP
  28. GCC_WIN=1
  29. endif
  30. ifeq ($(OSTYPE),msys) # test msys (MinGW's POSIX build env.) before DJGPP
  31. GCC_WIN=1
  32. endif
  33. LIBNAME=discmage
  34. OBJECTS=libdm_misc.o dllinit.o misc.o misc_wav.o format/format.o format/cdi.o \
  35. format/nero.o format/cue.o format/toc.o format/other.o
  36. ifneq ($(OSTYPE),beos)
  37. LDFLAGS+=-lm
  38. endif
  39. ifdef USE_ZLIB
  40. LDFLAGS+=-lz
  41. OBJECTS+=map.o misc_z.o unzip.o
  42. else
  43. ifeq ($(GCC_WIN),1)
  44. else
  45. ifdef DJGPP # DJGPP code in dllinit needs map code
  46. OBJECTS+=map.o
  47. endif # DJGPP
  48. endif # GCC_WIN
  49. endif # USE_ZLIB
  50. ifeq ($(OSTYPE),cygwin) # test cygwin before DJGPP
  51. FULLLIBNAME=$(LIBNAME).dll
  52. GCCA_DIR=/lib/gcc/i686-pc-cygwin/4.9.3/
  53. ifdef DLOPEN
  54. ENTRY=__cygwin_dll_entry@12
  55. else
  56. ENTRY=_DllMain@12
  57. endif
  58. LDFLAGS+=-L$(GCCA_DIR) -lgcc -lcygwin -lkernel32 --dll -e $(ENTRY)
  59. # kernel32 for DLOPEN and DisableThreadLibraryCalls()
  60. else
  61. ifeq ($(OSTYPE),msys) # test msys before DJGPP
  62. FULLLIBNAME=$(LIBNAME).dll
  63. GCCA_DIR=/mingw/lib/gcc/mingw32/4.8.1/
  64. LDFLAGS+=-L$(GCCA_DIR) -lgcc -L/mingw/lib -lkernel32 -lmsvcrt --dll -e _DllMain@12
  65. # MSYS problem: Specifying the library directory is necessary when compiling on
  66. # a different filesystem than the filesystem that MinGW is installed on.
  67. else
  68. ifdef DJGPP
  69. FULLLIBNAME=$(LIBNAME).dxe
  70. GCCA_DIR=c:/djgpp/lib/gcc/djgpp/5.30
  71. LDFLAGS+=-L$(GCCA_DIR) -lgcc
  72. OBJECTS+=dxe_misc.o
  73. else # UNIX, BeOS or Mac OS X (Darwin)
  74. CFLAGS+=-fPIC
  75. ifeq ($(findstring darwin,$(OSTYPE)),darwin)
  76. FULLLIBNAME=$(LIBNAME).dylib
  77. else
  78. FULLLIBNAME=$(LIBNAME).so
  79. endif
  80. ifndef DLOPEN # GNU specific: "simply expanded variable"
  81. FULLLIBNAME:=$(addprefix lib,$(FULLLIBNAME))
  82. endif
  83. ifeq ($(OSTYPE),beos)
  84. LDFLAGS+=-nostart
  85. else
  86. ifeq ($(findstring darwin,$(OSTYPE)),darwin)
  87. LDFLAGS+=-dynamiclib
  88. else
  89. LDFLAGS+=-shared
  90. endif # darwin
  91. endif # beos
  92. endif # DJGPP
  93. endif # msys
  94. endif # cygwin
  95. all: $(FULLLIBNAME)
  96. clean:
  97. ifeq ($(GCC_WIN),1)
  98. rm -f $(FULLLIBNAME) $(LIBNAME).a $(OBJECTS) *.core *.stackdump *.o tmp.*
  99. else
  100. ifdef DJGPP
  101. del $(FULLLIBNAME)
  102. ifndef DLOPEN
  103. del $(LIBNAME).a
  104. endif
  105. del *.o
  106. del format\*.o
  107. else # UNIX, BeOS or Mac OS X (Darwin)
  108. rm -f $(FULLLIBNAME) $(OBJECTS) *.core *.stackdump *.o
  109. endif # DJGPP
  110. endif # GCC_WIN
  111. distclean: clean
  112. ifeq ($(GCC_WIN),1)
  113. rm -f Makefile config.log config.status config.cache config.h
  114. else
  115. ifdef DJGPP
  116. del Makefile
  117. del config.log
  118. del config.status
  119. del config.cache
  120. del config.h
  121. else
  122. rm -f Makefile config.log config.status config.cache config.h
  123. endif # DJGPP
  124. endif # GCC_WIN
  125. .c.o:
  126. $(CC) $(CFLAGS) -c $< -o $@
  127. ifeq ($(GCC_WIN),1)
  128. DLLTOOLFLAGS=-d $(LIBNAME).def -b tmp.base -e tmp.exp -D $(FULLLIBNAME)
  129. ifndef DLOPEN
  130. DLLTOOLFLAGS+=-l $(LIBNAME).a
  131. $(FULLLIBNAME) $(LIBNAME).a: $(OBJECTS)
  132. else
  133. $(FULLLIBNAME): $(OBJECTS)
  134. endif
  135. # echo EXPORTS > tmp.def
  136. ## nm $(OBJECTS) | grep ' T _' | sed 's/.* T _//' >> tmp.def
  137. # nm $(OBJECTS) | grep '^........ [T] _' | sed 's/[^_]*_//' >> tmp.def
  138. # We use nm instead of dlltool --output-def, so that we don't have to
  139. # specify explicitly (in the source code) which symbols should be exported.
  140. # We don't create the .def file automatically anymore. Using nm resulted in a
  141. # (too large?) .def file which resulted in a non-working DLL when using Cygwin.
  142. ld --base-file tmp.base $(OBJECTS) $(LDFLAGS) -o $(FULLLIBNAME)
  143. dlltool $(DLLTOOLFLAGS)
  144. ld tmp.exp $(OBJECTS) $(LDFLAGS) -o $(FULLLIBNAME)
  145. else
  146. ifdef DJGPP
  147. ifndef DLOPEN
  148. $(FULLLIBNAME) $(LIBNAME).a: $(OBJECTS) djimport.o dlopen.o
  149. else
  150. $(FULLLIBNAME): $(OBJECTS)
  151. endif
  152. dxegen $(FULLLIBNAME) _import_export $(OBJECTS) $(LDFLAGS)
  153. ifndef DLOPEN
  154. # Recompile map.c, because it has to be a normal object file for the import
  155. # library (no references to import_export)
  156. $(CC) $(CFLAGS0) -c map.c -o map.o
  157. ar rs $(LIBNAME).a djimport.o map.o dlopen.o
  158. endif
  159. else # UNIX, BeOS or Mac OS X (Darwin)
  160. # UNIX uses LD_LIBRARY_PATH for dynamic linking, BeOS uses LIBRARY_PATH, Darwin
  161. # uses LD_LIBRARY_PATH, DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH
  162. $(FULLLIBNAME): $(OBJECTS)
  163. $(CC) $(OBJECTS) $(LDFLAGS) -o $(FULLLIBNAME)
  164. endif # DJGPP
  165. endif # GCC_WIN
  166. install:
  167. ifndef DLOPEN
  168. [ -d $(DESTDIR)$(libdir) ] || \
  169. (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
  170. $(INSTALL_DATA) $(FULLLIBNAME) $(DESTDIR)$(libdir)/$(FULLLIBNAME)
  171. # $(RANLIB) $(DESTDIR)$(libdir)/$(FULLLIBNAME)
  172. # $(LIBTOOL) --mode=install $(INSTALL) $(FULLLIBNAME) $(libdir)/$(FULLLIBNAME)
  173. [ -d $(DESTDIR)$(includedir) ] || \
  174. (mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
  175. $(INSTALL_DATA) lib$(LIBNAME).h $(DESTDIR)$(includedir)
  176. endif
  177. uninstall:
  178. ifndef DLOPEN
  179. rm -f $(DESTDIR)$(libdir)/$(FULLLIBNAME)
  180. rm -f $(DESTDIR)$(includedir)/lib$(LIBNAME).h
  181. endif
  182. # Dependencies
  183. MISC_Z_H_DEPS=misc_z.h unzip.h
  184. MISC_H_DEPS=misc.h $(MISC_Z_H_DEPS) getopt.h
  185. DXEDLL_PRIV_H_DEPS=dxedll_priv.h dxedll_pub.h
  186. libdm_misc.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  187. format/format.h $(DXEDLL_PRIV_H_DEPS) misc_wav.h
  188. dllinit.o: config.h libdiscmage.h dxedll_pub.h $(DXEDLL_PRIV_H_DEPS) map.h
  189. misc.o: config.h $(MISC_Z_H_DEPS) $(MISC_H_DEPS) $(DXEDLL_PRIV_H_DEPS)
  190. misc_wav.o: config.h $(MISC_H_DEPS) misc_wav.h
  191. format/format.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  192. format/format.h format/cdi.h format/cue.h format/nero.h \
  193. format/other.h format/toc.h $(DXEDLL_PRIV_H_DEPS)
  194. format/cdi.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  195. format/format.h $(DXEDLL_PRIV_H_DEPS)
  196. format/nero.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  197. format/format.h $(DXEDLL_PRIV_H_DEPS)
  198. format/cue.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  199. format/format.h $(DXEDLL_PRIV_H_DEPS)
  200. format/toc.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  201. format/format.h $(DXEDLL_PRIV_H_DEPS)
  202. format/other.o: config.h $(MISC_H_DEPS) libdiscmage.h libdm_misc.h \
  203. format/format.h $(DXEDLL_PRIV_H_DEPS)
  204. map.o: config.h map.h $(DXEDLL_PRIV_H_DEPS)
  205. misc_z.o: config.h $(MISC_Z_H_DEPS) $(MISC_H_DEPS) map.h unzip.h \
  206. $(DXEDLL_PRIV_H_DEPS)
  207. unzip.o: config.h unzip.h
  208. dxe_misc.o: config.h dxedll_pub.h
  209. djimport.o: config.h dlopen.h dxedll_pub.h libdiscmage.h
  210. dlopen.o: config.h dlopen.h dxedll_pub.h map.h