Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. #-----------------------------------------------------------------------------#
  2. # PhysicsFS -- A filesystem abstraction.
  3. #
  4. # Please see the file LICENSE in the source's root directory.
  5. # This file written by Ryan C. Gordon.
  6. #-----------------------------------------------------------------------------#
  7. #-----------------------------------------------------------------------------#
  8. # Makefile for building PhysicsFS on Unix-like systems. Follow the
  9. # instructions for editing this file, then run "make" on the command line.
  10. #-----------------------------------------------------------------------------#
  11. #-----------------------------------------------------------------------------#
  12. # Set to your liking.
  13. #-----------------------------------------------------------------------------#
  14. CC = gcc
  15. LINKER = gcc
  16. #-----------------------------------------------------------------------------#
  17. # If this makefile fails to detect Cygwin correctly, or you want to force
  18. # the build process's behaviour, set it to "true" or "false" (w/o quotes).
  19. #-----------------------------------------------------------------------------#
  20. #cygwin := true
  21. #cygwin := false
  22. cygwin := autodetect
  23. #-----------------------------------------------------------------------------#
  24. # Set this to true if you want to create a debug build.
  25. #-----------------------------------------------------------------------------#
  26. #debugging := false
  27. debugging := true
  28. #-----------------------------------------------------------------------------#
  29. # Set the archive types you'd like to support.
  30. # Note that various archives may need external libraries.
  31. #-----------------------------------------------------------------------------#
  32. use_archive_zip := true
  33. use_archive_grp := true
  34. #-----------------------------------------------------------------------------#
  35. # Set to "true" if you'd like to build a DLL. Set to "false" otherwise.
  36. #-----------------------------------------------------------------------------#
  37. #build_dll := false
  38. build_dll := true
  39. #-----------------------------------------------------------------------------#
  40. # Set one of the below. Currently, none of these are used.
  41. #-----------------------------------------------------------------------------#
  42. #use_asm = -DUSE_I386_ASM
  43. use_asm = -DUSE_PORTABLE_C
  44. #-----------------------------------------------------------------------------#
  45. # Set this to where you want PhysicsFS installed. It will put the
  46. # files in $(install_prefix)/bin, $(install_prefix)/lib, and
  47. # $(install_prefix)/include ...
  48. #-----------------------------------------------------------------------------#
  49. install_prefix := /usr/local
  50. #-----------------------------------------------------------------------------#
  51. #-----------------------------------------------------------------------------#
  52. #-----------------------------------------------------------------------------#
  53. #-----------------------------------------------------------------------------#
  54. # Everything below this line is probably okay.
  55. #-----------------------------------------------------------------------------#
  56. #-----------------------------------------------------------------------------#
  57. #-----------------------------------------------------------------------------#
  58. #-----------------------------------------------------------------------------#
  59. #-----------------------------------------------------------------------------#
  60. # CygWin autodetect.
  61. #-----------------------------------------------------------------------------#
  62. ifeq ($(strip $(cygwin)),autodetect)
  63. ifneq ($(strip $(shell gcc -v 2>&1 |grep "cygwin")),)
  64. cygwin := true
  65. else
  66. cygwin := false
  67. endif
  68. endif
  69. #-----------------------------------------------------------------------------#
  70. # Platform-specific binary stuff.
  71. #-----------------------------------------------------------------------------#
  72. ifeq ($(strip $(cygwin)),true)
  73. # !!! FIXME
  74. build_dll := false
  75. # !!! FIXME
  76. ASM = nasmw
  77. EXE_EXT = .exe
  78. DLL_EXT = .dll
  79. STATICLIB_EXT = .a
  80. ASMOBJFMT = win32
  81. ASMDEFS = -dC_IDENTIFIERS_UNDERSCORED
  82. CFLAGS += -DC_IDENTIFIERS_UNDERSCORED
  83. else
  84. ASM = nasm
  85. EXE_EXT =
  86. DLL_EXT = .so
  87. STATICLIB_EXT = .a
  88. ASMOBJFMT = elf
  89. endif
  90. ifeq ($(strip $(build_dll)),true)
  91. LIB_EXT := $(DLL_EXT)
  92. SHAREDFLAGS += -shared
  93. else
  94. LIB_EXT := $(STATICLIB_EXT)
  95. endif
  96. #-----------------------------------------------------------------------------#
  97. # Version crapola.
  98. #-----------------------------------------------------------------------------#
  99. VERMAJOR := $(shell grep "define PHYSFS_VER_MAJOR" physfs.h | sed "s/\#define PHYSFS_VER_MAJOR //")
  100. VERMINOR := $(shell grep "define PHYSFS_VER_MINOR" physfs.h | sed "s/\#define PHYSFS_VER_MINOR //")
  101. VERPATCH := $(shell grep "define PHYSFS_VER_PATCH" physfs.h | sed "s/\#define PHYSFS_VER_PATCH //")
  102. VERMAJOR := $(strip $(VERMAJOR))
  103. VERMINOR := $(strip $(VERMINOR))
  104. VERPATCH := $(strip $(VERPATCH))
  105. VERFULL := $(VERMAJOR).$(VERMINOR).$(VERPATCH)
  106. #-----------------------------------------------------------------------------#
  107. # General compiler, assembler, and linker flags.
  108. #-----------------------------------------------------------------------------#
  109. BINDIR := bin
  110. SRCDIR := .
  111. CFLAGS += $(use_asm) -I$(SRCDIR) -I/usr/include/readline -D_REENTRANT -fsigned-char -DPLATFORM_UNIX
  112. CFLAGS += -Wall -Werror -fno-exceptions -fno-rtti -ansi
  113. #-pedantic
  114. LDFLAGS += -lm
  115. ifeq ($(strip $(debugging)),true)
  116. CFLAGS += -DDEBUG -g -fno-omit-frame-pointer
  117. LDFLAGS += -g -fno-omit-frame-pointer
  118. else
  119. CFLAGS += -DNDEBUG -O2 -fomit-frame-pointer
  120. LDFLAGS += -O2 -fomit-frame-pointer
  121. endif
  122. ASMFLAGS := -f $(ASMOBJFMT) $(ASMDEFS)
  123. TESTLDFLAGS := -lreadline
  124. #-----------------------------------------------------------------------------#
  125. # Source and target names.
  126. #-----------------------------------------------------------------------------#
  127. PUREBASELIBNAME := physfs
  128. ifeq ($(strip $(cygwin)),true)
  129. BASELIBNAME := $(strip $(PUREBASELIBNAME))
  130. else
  131. BASELIBNAME := lib$(strip $(PUREBASELIBNAME))
  132. endif
  133. MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  134. TESTSRCS := test/test_physfs.c
  135. MAINSRCS := physfs.c physfs_byteorder.c archivers/dir.c
  136. ifeq ($(strip $(use_archive_zip)),true)
  137. MAINSRCS += archivers/zip.c archivers/unzip.c
  138. CFLAGS += -DPHYSFS_SUPPORTS_ZIP
  139. LDFLAGS += -lz
  140. ifeq ($(strip $(cygwin)),true)
  141. EXTRABUILD += zlib114/zlib114.a
  142. CFLAGS += -Izlib114
  143. LDFLAGS += -Lzlib114
  144. endif
  145. endif
  146. ifeq ($(strip $(use_archive_grp)),true)
  147. MAINSRCS += archivers/grp.c
  148. CFLAGS += -DPHYSFS_SUPPORTS_GRP
  149. endif
  150. ifeq ($(strip $(cygwin)),true)
  151. MAINSRCS += platform/win32.c
  152. CFLAGS += -DWIN32
  153. else
  154. MAINSRCS += platform/unix.c
  155. endif
  156. TESTEXE := $(BINDIR)/test_physfs$(EXE_EXT)
  157. # Rule for getting list of objects from source
  158. MAINOBJS1 := $(MAINSRCS:.c=.o)
  159. MAINOBJS2 := $(MAINOBJS1:.cpp=.o)
  160. MAINOBJS3 := $(MAINOBJS2:.asm=.o)
  161. MAINOBJS := $(foreach f,$(MAINOBJS3),$(BINDIR)/$(f))
  162. MAINSRCS := $(foreach f,$(MAINSRCS),$(SRCDIR)/$(f))
  163. TESTOBJS1 := $(TESTSRCS:.c=.o)
  164. TESTOBJS2 := $(TESTOBJS1:.cpp=.o)
  165. TESTOBJS3 := $(TESTOBJS2:.asm=.o)
  166. TESTOBJS := $(foreach f,$(TESTOBJS3),$(BINDIR)/$(f))
  167. TESTSRCS := $(foreach f,$(TESTSRCS),$(SRCDIR)/$(f))
  168. CLEANUP = $(wildcard *.exe) $(wildcard *.obj) \
  169. $(wildcard $(BINDIR)/*.exe) $(wildcard $(BINDIR)/*.obj) \
  170. $(wildcard *~) $(wildcard *.err) \
  171. $(wildcard .\#*) core
  172. #-----------------------------------------------------------------------------#
  173. # Rules.
  174. #-----------------------------------------------------------------------------#
  175. # Rules for turning source files into .o files
  176. $(BINDIR)/%.o: $(SRCDIR)/%.cpp
  177. $(CC) -c -o $@ $< $(CFLAGS)
  178. $(BINDIR)/%.o: $(SRCDIR)/%.c
  179. $(CC) -c -o $@ $< $(CFLAGS)
  180. $(BINDIR)/%.o: $(SRCDIR)/%.asm
  181. $(ASM) $(ASMFLAGS) -o $@ $<
  182. .PHONY: all clean distclean listobjs install
  183. all: $(BINDIR) $(EXTRABUILD) $(MAINLIB) $(TESTEXE)
  184. $(MAINLIB) : $(BINDIR) $(MAINOBJS)
  185. $(LINKER) -o $(MAINLIB) $(SHAREDFLAGS) $(MAINOBJS) $(LDFLAGS)
  186. $(TESTEXE) : $(MAINLIB) $(TESTOBJS)
  187. $(LINKER) -o $(TESTEXE) $(TESTOBJS) -L$(BINDIR) -l$(strip $(PUREBASELIBNAME)) $(LDFLAGS) $(TESTLDFLAGS)
  188. install: all
  189. rm -f $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERMAJOR)).$(strip $(VERMINOR)).*
  190. mkdir -p $(install_prefix)/bin
  191. mkdir -p $(install_prefix)/lib
  192. mkdir -p $(install_prefix)/include
  193. cp $(SRCDIR)/physfs.h $(install_prefix)/include
  194. cp $(TESTEXE) $(install_prefix)/bin
  195. ifeq ($(strip $(cygwin)),true)
  196. cp $(MAINLIB) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  197. else
  198. cp $(MAINLIB) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL))
  199. ln -sf $(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL)) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  200. ln -sf $(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL)) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERMAJOR))
  201. chmod 0755 $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL))
  202. chmod 0644 $(install_prefix)/include/physfs.h
  203. endif
  204. $(BINDIR):
  205. mkdir -p $(BINDIR)
  206. mkdir -p $(BINDIR)/archivers
  207. mkdir -p $(BINDIR)/platform
  208. mkdir -p $(BINDIR)/test
  209. ifeq ($(strip $(cygwin)),true)
  210. zlib114/zlib114.a:
  211. cd zlib114 ; $(MAKE) CC=$(CC)
  212. endif
  213. distclean: clean
  214. clean:
  215. rm -f $(CLEANUP)
  216. rm -rf $(BINDIR)
  217. ifeq ($(strip $(cygwin)),true)
  218. cd zlib114 ; $(MAKE) clean
  219. endif
  220. listobjs:
  221. @echo SOURCES:
  222. @echo $(MAINSRCS)
  223. @echo
  224. @echo OBJECTS:
  225. @echo $(MAINOBJS)
  226. @echo
  227. @echo BINARIES:
  228. @echo $(MAINLIB)
  229. showcfg:
  230. @echo "Using CygWin : $(cygwin)"
  231. @echo "Debugging : $(debugging)"
  232. @echo "ASM flag : $(use_asm)"
  233. @echo "Building DLLs : $(build_dll)"
  234. @echo "Install prefix : $(install_prefix)"
  235. @echo "PhysFS version : $(VERFULL)"
  236. @echo "Supports .GRP : $(use_archive_grp)"
  237. @echo "Supports .ZIP : $(use_archive_zip)"
  238. #-----------------------------------------------------------------------------#
  239. # This section is pretty much just for Ryan's use to make distributions.
  240. # You Probably Should Not Touch.
  241. #-----------------------------------------------------------------------------#
  242. # These are the files needed in a binary distribution, regardless of what
  243. # platform is being used.
  244. BINSCOMMON := LICENSE.TXT physfs.h
  245. .PHONY: package msbins win32bins nocygwin
  246. package: clean
  247. cd .. ; mv physfs physfs-$(VERFULL) ; tar -cyvvf ./physfs-$(VERFULL).tar.bz2 --exclude="*CVS*" physfs-$(VERFULL) ; mv physfs-$(VERFULL) physfs
  248. ifeq ($(strip $(cygwin)),true)
  249. msbins: win32bins
  250. win32bins: clean all
  251. echo -e "\r\n\r\n\r\nHEY YOU.\r\n\r\n\r\nTake a look at README-win32bins.txt FIRST.\r\n\r\n\r\n--ryan. (icculus@clutteredmind.org)\r\n\r\n" |zip -9rz ../physfs-win32bins-$(shell date +%m%d%Y).zip $(MAINLIB) $(EXTRAPACKAGELIBS) README-win32bins.txt
  252. else
  253. msbins: nocygwin
  254. win32bins: nocygwin
  255. nocygwin:
  256. @echo This must be done on a Windows box in the Cygwin environment.
  257. endif
  258. #-----------------------------------------------------------------------------#
  259. # That's all, folks.
  260. #-----------------------------------------------------------------------------#
  261. # end of Makefile ...