Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. #-----------------------------------------------------------------------------#
  46. #-----------------------------------------------------------------------------#
  47. #-----------------------------------------------------------------------------#
  48. # Everything below this line is probably okay.
  49. #-----------------------------------------------------------------------------#
  50. #-----------------------------------------------------------------------------#
  51. #-----------------------------------------------------------------------------#
  52. #-----------------------------------------------------------------------------#
  53. curdate := $(shell date +%m%d%Y)
  54. #-----------------------------------------------------------------------------#
  55. # CygWin autodetect.
  56. #-----------------------------------------------------------------------------#
  57. ifeq ($(strip $(cygwin)),autodetect)
  58. ifneq ($(strip $(shell gcc -v 2>&1 |grep "cygwin")),)
  59. cygwin := true
  60. else
  61. cygwin := false
  62. endif
  63. endif
  64. #-----------------------------------------------------------------------------#
  65. # Platform-specific binary stuff.
  66. #-----------------------------------------------------------------------------#
  67. ifeq ($(strip $(cygwin)),true)
  68. # !!! FIXME
  69. build_dll := false
  70. # !!! FIXME
  71. ASM = nasmw
  72. EXE_EXT = .exe
  73. DLL_EXT = .dll
  74. STATICLIB_EXT = .a
  75. ASMOBJFMT = win32
  76. ASMDEFS = -dC_IDENTIFIERS_UNDERSCORED
  77. CFLAGS += -DC_IDENTIFIERS_UNDERSCORED
  78. else
  79. ASM = nasm
  80. EXE_EXT =
  81. DLL_EXT = .so
  82. STATICLIB_EXT = .a
  83. ASMOBJFMT = elf
  84. endif
  85. ifeq ($(strip $(build_dll)),true)
  86. LIB_EXT := $(DLL_EXT)
  87. SHAREDFLAGS += -shared
  88. else
  89. LIB_EXT := $(STATICLIB_EXT)
  90. endif
  91. #-----------------------------------------------------------------------------#
  92. # General compiler, assembler, and linker flags.
  93. #-----------------------------------------------------------------------------#
  94. BINDIR := bin
  95. SRCDIR := .
  96. CFLAGS += $(use_asm) -I$(SRCDIR) -I/usr/include/readline -D_REENTRANT -fsigned-char -DPLATFORM_UNIX
  97. CFLAGS += -Wall -Werror -fno-exceptions -fno-rtti -ansi -pedantic
  98. LDFLAGS += -lm
  99. ifeq ($(strip $(debugging)),true)
  100. CFLAGS += -DDEBUG -g -fno-omit-frame-pointer
  101. LDFLAGS += -g -fno-omit-frame-pointer
  102. else
  103. CFLAGS += -DNDEBUG -O2 -fomit-frame-pointer
  104. LDFLAGS += -O2 -fomit-frame-pointer
  105. endif
  106. ASMFLAGS := -f $(ASMOBJFMT) $(ASMDEFS)
  107. TESTLDFLAGS := -lreadline
  108. #-----------------------------------------------------------------------------#
  109. # Source and target names.
  110. #-----------------------------------------------------------------------------#
  111. BASELIBNAME := physfs
  112. MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
  113. TESTSRCS := test/test_physfs.c
  114. MAINSRCS := physfs.c platform/unix.c archivers/dir.c
  115. ifeq ($(strip $(use_archive_zip)),true)
  116. MAINSRCS += archivers/zip.c archivers/unzip.c
  117. CFLAGS += -DPHYSFS_SUPPORTS_ZIP
  118. LDFLAGS += -lz
  119. endif
  120. ifeq ($(strip $(use_archive_grp)),true)
  121. MAINSRCS += archivers/grp.c
  122. CFLAGS += -DPHYSFS_SUPPORTS_GRP
  123. endif
  124. TESTEXE := $(BINDIR)/test_physfs$(EXE_EXT)
  125. # Rule for getting list of objects from source
  126. MAINOBJS1 := $(MAINSRCS:.c=.o)
  127. MAINOBJS2 := $(MAINOBJS1:.cpp=.o)
  128. MAINOBJS3 := $(MAINOBJS2:.asm=.o)
  129. MAINOBJS := $(foreach f,$(MAINOBJS3),$(BINDIR)/$(f))
  130. MAINSRCS := $(foreach f,$(MAINSRCS),$(SRCDIR)/$(f))
  131. TESTOBJS1 := $(TESTSRCS:.c=.o)
  132. TESTOBJS2 := $(TESTOBJS1:.cpp=.o)
  133. TESTOBJS3 := $(TESTOBJS2:.asm=.o)
  134. TESTOBJS := $(foreach f,$(TESTOBJS3),$(BINDIR)/$(f))
  135. TESTSRCS := $(foreach f,$(TESTSRCS),$(SRCDIR)/$(f))
  136. CLEANUP = $(wildcard *.exe) $(wildcard *.obj) \
  137. $(wildcard $(BINDIR)/*.exe) $(wildcard $(BINDIR)/*.obj) \
  138. $(wildcard *~) $(wildcard *.err) \
  139. $(wildcard .\#*) core
  140. #-----------------------------------------------------------------------------#
  141. # Rules.
  142. #-----------------------------------------------------------------------------#
  143. # Rules for turning source files into .o files
  144. $(BINDIR)/%.o: $(SRCDIR)/%.cpp
  145. $(CC) -c -o $@ $< $(CFLAGS)
  146. $(BINDIR)/%.o: $(SRCDIR)/%.c
  147. $(CC) -c -o $@ $< $(CFLAGS)
  148. $(BINDIR)/%.o: $(SRCDIR)/%.asm
  149. $(ASM) $(ASMFLAGS) -o $@ $<
  150. .PHONY: all clean distclean listobjs
  151. all: $(BINDIR) $(MAINLIB) $(TESTEXE)
  152. $(MAINLIB) : $(BINDIR) $(MAINOBJS)
  153. $(LINKER) -o $(MAINLIB) $(LDFLAGS) $(SHAREDFLAGS) $(MAINOBJS)
  154. $(TESTEXE) : $(MAINLIB) $(TESTOBJS)
  155. $(LINKER) -o $(TESTEXE) $(LDFLAGS) $(TESTLDFLAGS) $(TESTOBJS) $(MAINLIB)
  156. $(BINDIR):
  157. mkdir -p $(BINDIR)
  158. mkdir -p $(BINDIR)/archivers
  159. mkdir -p $(BINDIR)/platform
  160. mkdir -p $(BINDIR)/test
  161. distclean: clean
  162. clean:
  163. rm -f $(CLEANUP)
  164. rm -rf $(BINDIR)
  165. listobjs:
  166. @echo SOURCES:
  167. @echo $(MAINSRCS)
  168. @echo
  169. @echo OBJECTS:
  170. @echo $(MAINOBJS)
  171. @echo
  172. @echo BINARIES:
  173. @echo $(MAINLIB)
  174. showcfg:
  175. @echo "Using CygWin : $(cygwin)"
  176. @echo "Debugging : $(debugging)"
  177. @echo "ASM flag : $(use_asm)"
  178. @echo "Building DLLs : $(build_dll)"
  179. @echo "Supports .ZIP : $(use_archive_zip)"
  180. #-----------------------------------------------------------------------------#
  181. # This section is pretty much just for Ryan's use to make distributions.
  182. # You Probably Should Not Touch.
  183. #-----------------------------------------------------------------------------#
  184. # These are the files needed in a binary distribution, regardless of what
  185. # platform is being used.
  186. BINSCOMMON := LICENSE.TXT physfs.h
  187. .PHONY: package msbins win32bins nocygwin
  188. package: clean
  189. cd .. ; mv physfs physfs-$(curdate) ; tar -cyvvf ./physfs-$(curdate).tar.bz2 --exclude="*CVS*" physfs-$(curdate) ; mv physfs-$(curdate) physfs
  190. ifeq ($(strip $(cygwin)),true)
  191. msbins: win32bins
  192. win32bins: clean all
  193. 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@linuxgames.com)\r\n\r\n" |zip -9rz ../physfs-win32bins-$(shell date +%m%d%Y).zip $(MAINLIB) $(EXTRAPACKAGELIBS) README-win32bins.txt
  194. else
  195. msbins: nocygwin
  196. win32bins: nocygwin
  197. nocygwin:
  198. @echo This must be done on a Windows box in the Cygwin environment.
  199. endif
  200. #-----------------------------------------------------------------------------#
  201. # That's all, folks.
  202. #-----------------------------------------------------------------------------#
  203. # end of Makefile ...