Makefile 8.2 KB

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