Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 -pedantic
  113. LDFLAGS += -lm
  114. ifeq ($(strip $(debugging)),true)
  115. CFLAGS += -DDEBUG -g -fno-omit-frame-pointer
  116. LDFLAGS += -g -fno-omit-frame-pointer
  117. else
  118. CFLAGS += -DNDEBUG -O2 -fomit-frame-pointer
  119. LDFLAGS += -O2 -fomit-frame-pointer
  120. endif
  121. ASMFLAGS := -f $(ASMOBJFMT) $(ASMDEFS)
  122. TESTLDFLAGS := -lreadline
  123. #-----------------------------------------------------------------------------#
  124. # Source and target names.
  125. #-----------------------------------------------------------------------------#
  126. BASELIBNAME := physfs
  127. ifneq ($(strip $(cygwin)),true)
  128. BASELIBNAME := lib$(strip $(BASELIBNAME))
  129. endif
  130. MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  131. TESTSRCS := test/test_physfs.c
  132. MAINSRCS := physfs.c platform/unix.c archivers/dir.c
  133. ifeq ($(strip $(use_archive_zip)),true)
  134. MAINSRCS += archivers/zip.c archivers/unzip.c
  135. CFLAGS += -DPHYSFS_SUPPORTS_ZIP
  136. LDFLAGS += -lz
  137. endif
  138. ifeq ($(strip $(use_archive_grp)),true)
  139. MAINSRCS += archivers/grp.c
  140. CFLAGS += -DPHYSFS_SUPPORTS_GRP
  141. endif
  142. TESTEXE := $(BINDIR)/test_physfs$(EXE_EXT)
  143. # Rule for getting list of objects from source
  144. MAINOBJS1 := $(MAINSRCS:.c=.o)
  145. MAINOBJS2 := $(MAINOBJS1:.cpp=.o)
  146. MAINOBJS3 := $(MAINOBJS2:.asm=.o)
  147. MAINOBJS := $(foreach f,$(MAINOBJS3),$(BINDIR)/$(f))
  148. MAINSRCS := $(foreach f,$(MAINSRCS),$(SRCDIR)/$(f))
  149. TESTOBJS1 := $(TESTSRCS:.c=.o)
  150. TESTOBJS2 := $(TESTOBJS1:.cpp=.o)
  151. TESTOBJS3 := $(TESTOBJS2:.asm=.o)
  152. TESTOBJS := $(foreach f,$(TESTOBJS3),$(BINDIR)/$(f))
  153. TESTSRCS := $(foreach f,$(TESTSRCS),$(SRCDIR)/$(f))
  154. CLEANUP = $(wildcard *.exe) $(wildcard *.obj) \
  155. $(wildcard $(BINDIR)/*.exe) $(wildcard $(BINDIR)/*.obj) \
  156. $(wildcard *~) $(wildcard *.err) \
  157. $(wildcard .\#*) core
  158. #-----------------------------------------------------------------------------#
  159. # Rules.
  160. #-----------------------------------------------------------------------------#
  161. # Rules for turning source files into .o files
  162. $(BINDIR)/%.o: $(SRCDIR)/%.cpp
  163. $(CC) -c -o $@ $< $(CFLAGS)
  164. $(BINDIR)/%.o: $(SRCDIR)/%.c
  165. $(CC) -c -o $@ $< $(CFLAGS)
  166. $(BINDIR)/%.o: $(SRCDIR)/%.asm
  167. $(ASM) $(ASMFLAGS) -o $@ $<
  168. .PHONY: all clean distclean listobjs install
  169. all: $(BINDIR) $(MAINLIB) $(TESTEXE)
  170. $(MAINLIB) : $(BINDIR) $(MAINOBJS)
  171. $(LINKER) -o $(MAINLIB) $(LDFLAGS) $(SHAREDFLAGS) $(MAINOBJS)
  172. $(TESTEXE) : $(MAINLIB) $(TESTOBJS)
  173. $(LINKER) -o $(TESTEXE) $(LDFLAGS) $(TESTLDFLAGS) $(TESTOBJS) $(MAINLIB)
  174. install: all
  175. mkdir -p $(install_prefix)/bin
  176. mkdir -p $(install_prefix)/lib
  177. mkdir -p $(install_prefix)/include
  178. cp $(SRCDIR)/physfs.h $(install_prefix)/include
  179. cp $(TESTEXE) $(install_prefix)/bin
  180. ifeq ($(strip $(cygwin)),true)
  181. cp $(MAINLIB) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  182. else
  183. cp $(MAINLIB) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL))
  184. ln -sf $(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL)) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  185. ln -sf $(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL)) $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERMAJOR))
  186. chmod 0755 $(install_prefix)/lib/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)).$(strip $(VERFULL))
  187. chmod 0644 $(install_prefix)/include/physfs.h
  188. endif
  189. $(BINDIR):
  190. mkdir -p $(BINDIR)
  191. mkdir -p $(BINDIR)/archivers
  192. mkdir -p $(BINDIR)/platform
  193. mkdir -p $(BINDIR)/test
  194. distclean: clean
  195. clean:
  196. rm -f $(CLEANUP)
  197. rm -rf $(BINDIR)
  198. listobjs:
  199. @echo SOURCES:
  200. @echo $(MAINSRCS)
  201. @echo
  202. @echo OBJECTS:
  203. @echo $(MAINOBJS)
  204. @echo
  205. @echo BINARIES:
  206. @echo $(MAINLIB)
  207. showcfg:
  208. @echo "Using CygWin : $(cygwin)"
  209. @echo "Debugging : $(debugging)"
  210. @echo "ASM flag : $(use_asm)"
  211. @echo "Building DLLs : $(build_dll)"
  212. @echo "Install prefix : $(install_prefix)"
  213. @echo "PhysFS version : $(VERFULL)"
  214. @echo "Supports .ZIP : $(use_archive_zip)"
  215. #-----------------------------------------------------------------------------#
  216. # This section is pretty much just for Ryan's use to make distributions.
  217. # You Probably Should Not Touch.
  218. #-----------------------------------------------------------------------------#
  219. # These are the files needed in a binary distribution, regardless of what
  220. # platform is being used.
  221. BINSCOMMON := LICENSE.TXT physfs.h
  222. .PHONY: package msbins win32bins nocygwin
  223. package: clean
  224. cd .. ; mv physfs physfs-$(VERFULL) ; tar -cyvvf ./physfs-$(VERFULL).tar.bz2 --exclude="*CVS*" physfs-$(VERFULL) ; mv physfs-$(VERFULL) physfs
  225. ifeq ($(strip $(cygwin)),true)
  226. msbins: win32bins
  227. win32bins: clean all
  228. 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
  229. else
  230. msbins: nocygwin
  231. win32bins: nocygwin
  232. nocygwin:
  233. @echo This must be done on a Windows box in the Cygwin environment.
  234. endif
  235. #-----------------------------------------------------------------------------#
  236. # That's all, folks.
  237. #-----------------------------------------------------------------------------#
  238. # end of Makefile ...