Makefile
changeset 9 1155788ccbe3
child 11 677e01f5109e
equal deleted inserted replaced
8:41e4c6031535 9:1155788ccbe3
       
     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 
       
     9 #-----------------------------------------------------------------------------#
       
    10 # Makefile for building PhysicsFS on Unix-like systems. Follow the
       
    11 #  instructions for editing this file, then run "make" on the command line.
       
    12 #-----------------------------------------------------------------------------#
       
    13 
       
    14 
       
    15 #-----------------------------------------------------------------------------#
       
    16 # Set to your liking.
       
    17 #-----------------------------------------------------------------------------#
       
    18 CC = gcc
       
    19 LINKER = gcc
       
    20 
       
    21 
       
    22 #-----------------------------------------------------------------------------#
       
    23 # If this makefile fails to detect Cygwin correctly, or you want to force
       
    24 #  the build process's behaviour, set it to "true" or "false" (w/o quotes).
       
    25 #-----------------------------------------------------------------------------#
       
    26 #cygwin := true
       
    27 #cygwin := false
       
    28 cygwin := autodetect
       
    29 
       
    30 #-----------------------------------------------------------------------------#
       
    31 # Set this to true if you want to create a debug build.
       
    32 #-----------------------------------------------------------------------------#
       
    33 #debugging := false
       
    34 debugging := true
       
    35 
       
    36 #-----------------------------------------------------------------------------#
       
    37 # Set the archive types you'd like to support.
       
    38 #  Note that various archives may need external libraries.
       
    39 #-----------------------------------------------------------------------------#
       
    40 use_archive_zip := false
       
    41 
       
    42 #-----------------------------------------------------------------------------#
       
    43 # Set to "true" if you'd like to build a DLL. Set to "false" otherwise.
       
    44 #-----------------------------------------------------------------------------#
       
    45 #build_dll := false
       
    46 build_dll := true
       
    47 
       
    48 
       
    49 #-----------------------------------------------------------------------------#
       
    50 # Set one of the below. Currently, none of these are used.
       
    51 #-----------------------------------------------------------------------------#
       
    52 #use_asm = -DUSE_I386_ASM
       
    53 use_asm = -DUSE_PORTABLE_C
       
    54 
       
    55 
       
    56 #-----------------------------------------------------------------------------#
       
    57 #-----------------------------------------------------------------------------#
       
    58 #-----------------------------------------------------------------------------#
       
    59 #-----------------------------------------------------------------------------#
       
    60 # Everything below this line is probably okay.
       
    61 #-----------------------------------------------------------------------------#
       
    62 #-----------------------------------------------------------------------------#
       
    63 #-----------------------------------------------------------------------------#
       
    64 #-----------------------------------------------------------------------------#
       
    65 
       
    66 
       
    67 #-----------------------------------------------------------------------------#
       
    68 # CygWin autodetect.
       
    69 #-----------------------------------------------------------------------------#
       
    70 
       
    71 ifeq ($(strip $(cygwin)),autodetect)
       
    72   ifneq ($(strip $(shell gcc -v 2>&1 |grep "cygwin")),)
       
    73     cygwin := true
       
    74   else
       
    75     cygwin := false
       
    76   endif
       
    77 endif
       
    78 
       
    79 
       
    80 #-----------------------------------------------------------------------------#
       
    81 # Platform-specific binary stuff.
       
    82 #-----------------------------------------------------------------------------#
       
    83 
       
    84 ifeq ($(strip $(cygwin)),true)
       
    85   # !!! FIXME
       
    86   build_dll := false
       
    87   # !!! FIXME
       
    88 
       
    89   ASM = nasmw
       
    90   EXE_EXT = .exe
       
    91   DLL_EXT = .dll
       
    92   STATICLIB_EXT = .a
       
    93   ASMOBJFMT = win32
       
    94   ASMDEFS = -dC_IDENTIFIERS_UNDERSCORED
       
    95   CFLAGS += -DC_IDENTIFIERS_UNDERSCORED
       
    96 else
       
    97   ASM = nasm
       
    98   EXE_EXT =
       
    99   DLL_EXT = .so
       
   100   STATICLIB_EXT = .a
       
   101   ASMOBJFMT = elf
       
   102 endif
       
   103 
       
   104 ifeq ($(strip $(build_dll)),true)
       
   105 LIB_EXT := $(DLL_EXT)
       
   106 LDFLAGS += -shared
       
   107 else
       
   108 LIB_EXT := $(STATICLIB_EXT)
       
   109 endif
       
   110 
       
   111 #-----------------------------------------------------------------------------#
       
   112 # General compiler, assembler, and linker flags.
       
   113 #-----------------------------------------------------------------------------#
       
   114 
       
   115 BINDIR := bin
       
   116 SRCDIR := .
       
   117 
       
   118 CFLAGS += $(use_asm) -I$(SRCDIR) -D_REENTRANT -fsigned-char -DPLATFORM_UNIX
       
   119 CFLAGS += -Wall -Werror -fno-exceptions -fno-rtti -ansi -pendantic
       
   120 
       
   121 LDFLAGS += -lm
       
   122 
       
   123 ifeq ($(strip $(debugging)),true)
       
   124   CFLAGS += -DDEBUG -g -fno-omit-frame-pointer
       
   125   LDFLAGS += -g -fno-omit-frame-pointer
       
   126 else
       
   127   CFLAGS += -DNDEBUG -O2 -fomit-frame-pointer
       
   128   LDFLAGS += -O2 -fomit-frame-pointer
       
   129 endif
       
   130 
       
   131 ASMFLAGS := -f $(ASMOBJFMT) $(ASMDEFS)
       
   132 
       
   133 
       
   134 #-----------------------------------------------------------------------------#
       
   135 # Source and target names.
       
   136 #-----------------------------------------------------------------------------#
       
   137 
       
   138 BASELIBNAME := physfs
       
   139 MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
       
   140 
       
   141 MAINSRCS := physfs.c unix.c dir.c
       
   142 
       
   143 ifeq ($(strip $(use_archive_zip)),true)
       
   144 MAINSRCS += zip.c
       
   145 CFLAGS += -DPHYSFS_SUPPORTS_ZIP
       
   146 endif
       
   147 
       
   148 # Rule for getting list of objects from source
       
   149 MAINOBJS1 := $(MAINSRCS:.c=.o)
       
   150 MAINOBJS2 := $(MAINOBJS1:.cpp=.o)
       
   151 MAINOBJS3 := $(MAINOBJS2:.asm=.o)
       
   152 
       
   153 MAINOBJS := $(foreach f,$(MAINOBJS3),$(BINDIR)/$(f))
       
   154 MAINSRCS := $(foreach f,$(MAINSRCS),$(SRCDIR)/$(f))
       
   155 
       
   156 CLEANUP = $(wildcard *.exe) $(wildcard *.obj) \
       
   157           $(wildcard $(BINDIR)/*.exe) $(wildcard $(BINDIR)/*.obj) \
       
   158           $(wildcard *~) $(wildcard *.err) \
       
   159           $(wildcard .\#*) core
       
   160 
       
   161 
       
   162 #-----------------------------------------------------------------------------#
       
   163 # Rules.
       
   164 #-----------------------------------------------------------------------------#
       
   165 
       
   166 # Rules for turning source files into .o files
       
   167 $(BINDIR)/%.o: $(SRCDIR)/%.cpp
       
   168 	$(CC) -c -o $@ $< $(CFLAGS)
       
   169 
       
   170 $(BINDIR)/%.o: $(SRCDIR)/%.c
       
   171 	$(CC) -c -o $@ $< $(CFLAGS)
       
   172 
       
   173 $(BINDIR)/%.o: $(SRCDIR)/%.asm
       
   174 	$(ASM) $(ASMFLAGS) -o $@ $<
       
   175 
       
   176 .PHONY: all clean listobjs
       
   177 
       
   178 all: $(BINDIR) $(MAINLIB)
       
   179 
       
   180 $(MAINLIB) : $(BINDIR) $(MAINOBJS)
       
   181 	$(LINKER) -o $(MAINLIB) $(LDFLAGS) $(MAINOBJS)
       
   182 
       
   183 $(BINDIR):
       
   184 	mkdir -p $(BINDIR)
       
   185 
       
   186 clean:
       
   187 	rm -f $(CLEANUP)
       
   188 	rm -rf $(BINDIR)
       
   189 
       
   190 listobjs:
       
   191 	@echo SOURCES:
       
   192 	@echo $(MAINSRCS)
       
   193 	@echo
       
   194 	@echo OBJECTS:
       
   195 	@echo $(MAINOBJS)
       
   196 	@echo
       
   197 	@echo BINARIES:
       
   198 	@echo $(MAINLIB)
       
   199 
       
   200 showcfg:
       
   201 	@echo "Using CygWin   : $(cygwin)"
       
   202 	@echo "Debugging      : $(debugging)"
       
   203 	@echo "ASM flag       : $(use_asm)"
       
   204 	@echo "Building DLLs  : $(build_dll)"
       
   205 	@echo "Supports .ZIP  : $(use_archive_zip)"
       
   206 
       
   207 #-----------------------------------------------------------------------------#
       
   208 # This section is pretty much just for Ryan's use to make distributions.
       
   209 #  You Probably Should Not Touch.
       
   210 #-----------------------------------------------------------------------------#
       
   211 
       
   212 # These are the files needed in a binary distribution, regardless of what
       
   213 #  platform is being used.
       
   214 BINSCOMMON := LICENSE.TXT physfs.h
       
   215 
       
   216 .PHONY: package msbins win32bins nocygwin
       
   217 package: clean
       
   218 	cd .. ; zip -9rz ./physfs-src-$(shell date +%m%d%Y).zip physfs -x "*CVS*" < physfs/FILEID.DIZ
       
   219 
       
   220 
       
   221 ifeq ($(strip $(cygwin)),true)
       
   222 msbins: win32bins
       
   223 
       
   224 win32bins: clean all
       
   225 	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
       
   226 
       
   227 else
       
   228 
       
   229 msbins: nocygwin
       
   230 win32bins: nocygwin
       
   231 
       
   232 nocygwin:
       
   233 	@echo This must be done on a Windows box in the Cygwin environment.
       
   234 
       
   235 endif
       
   236 
       
   237 #-----------------------------------------------------------------------------#
       
   238 # That's all, folks.
       
   239 #-----------------------------------------------------------------------------#
       
   240 
       
   241 # end of Makefile ...