2010-05-04 04:46:42 +08:00
# This file is part of Mongoose project, http://code.google.com/p/mongoose
# $Id: Makefile 473 2009-09-02 11:20:06Z valenok $
PROG = mongoose
all :
2012-09-27 07:33:33 +08:00
@echo "make (linux|bsd|solaris|mac|windows|mingw|cygwin)"
2010-05-04 04:46:42 +08:00
# Possible COPT values: (in brackets are rough numbers for 'gcc -O2' on i386)
2012-08-19 19:22:28 +08:00
# -DHAVE_MD5 - use system md5 library (-2kb)
# -DNDEBUG - strip off all debug code (-5kb)
# -DDEBUG - build debug version (very noisy) (+7kb)
# -DNO_CGI - disable CGI support (-5kb)
# -DNO_SSL - disable SSL functionality (-2kb)
2012-09-28 06:58:35 +08:00
# -DNO_SSL_DL - link against system libssl library (-1kb)
2012-08-19 19:22:28 +08:00
# -DCONFIG_FILE=\"file\" - use `file' as the default config file
# -DSSL_LIB=\"libssl.so.<version>\" - use system versioned SSL shared object
2010-11-29 21:46:42 +08:00
# -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
2012-09-28 06:58:35 +08:00
# -DUSE_LUA - embed Lua in Mongoose (+100kb)
2010-05-04 04:46:42 +08:00
##########################################################################
### UNIX build: linux, bsd, mac, rtems
##########################################################################
2012-10-02 05:24:22 +08:00
# To build with Lua, download and unzip Lua 5.2.1 source code into the
# mongoose directory, and then add $(LUA_FLAGS) to CFLAGS below
2012-09-27 06:37:03 +08:00
LUA = lua-5.2.1/src
2013-01-24 05:14:11 +08:00
LUA_FLAGS = -I$( LUA) -L$( LUA) -llua -lm
2012-09-27 06:37:03 +08:00
2013-01-22 01:51:56 +08:00
CFLAGS = -std= c99 -O2 -W -Wall -pedantic -pthread $( COPT)
2012-09-22 19:52:47 +08:00
LIB = lib$( PROG) .so$( MONGOOSE_LIB_SUFFIX)
2010-05-04 04:46:42 +08:00
2010-12-01 17:25:12 +08:00
# Make sure that the compiler flags come last in the compilation string.
# If not so, this can break some on some Linux distros which use
# "-Wl,--as-needed" turned on by default in cc command.
# Also, this is turned in many other distros in static linkage builds.
2010-05-04 04:46:42 +08:00
linux :
2013-01-22 01:51:56 +08:00
$( CC) mongoose.c main.c -o $( PROG) -ldl $( CFLAGS)
2010-05-04 04:46:42 +08:00
2013-01-22 01:51:56 +08:00
mac : bsd
2010-05-04 04:46:42 +08:00
bsd :
2013-01-22 01:51:56 +08:00
$( CC) mongoose.c main.c -o $( PROG) $( CFLAGS)
2010-05-04 04:46:42 +08:00
2013-01-22 01:51:56 +08:00
solaris :
$( CC) mongoose.c main.c -lnsl -lsocket -o $( PROG) $( CFLAGS)
2013-01-17 07:43:06 +08:00
cocoa :
2013-01-22 01:51:56 +08:00
$( CC) mongoose.c main.c -DUSE_COCOA $( CFLAGS) -framework Cocoa -ObjC -arch i386 -arch x86_64 -o Mongoose
2013-01-17 07:43:06 +08:00
V = ` perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' mongoose.c` ; DIR = dmg/Mongoose.app && rm -rf $$ DIR && mkdir -p $$ DIR/Contents/{ MacOS,Resources} && install -m 644 build/mongoose_*.png $$ DIR/Contents/Resources/ && install -m 644 build/Info.plist $$ DIR/Contents/ && install -m 755 Mongoose $$ DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create Mongoose_$$ V.dmg -volname " Mongoose $$ V " -srcfolder dmg -ov #; rm -rf dmg
2010-05-04 04:46:42 +08:00
2013-01-24 05:14:11 +08:00
unix_unit_test : $( LUA_OBJECTS )
$( CC) test/unit_test.c -o unit_test -I. $( LUA_FLAGS) $( CFLAGS) -g -O0
2013-01-22 16:59:13 +08:00
./unit_test
2010-05-04 04:46:42 +08:00
##########################################################################
### WINDOWS build: Using Visual Studio or Mingw
##########################################################################
2010-08-29 01:05:21 +08:00
# Using Visual Studio 6.0. To build Mongoose:
2012-09-20 21:55:09 +08:00
# o Set MSVC variable below to where VS 6.0 is installed on your system
2010-08-29 01:05:21 +08:00
# o Run "PATH_TO_VC6\bin\nmake windows"
2010-05-04 04:46:42 +08:00
2012-09-20 21:55:09 +08:00
MSVC = e:/vc6
CYA = e:/cyassl-2.0.0rc2
2012-08-19 19:22:28 +08:00
#DBG = /Zi /DDEBUG /Od
DBG = /DNDEBUG /O1
2012-09-20 21:55:09 +08:00
CL = $( MSVC) /bin/cl /MD /TC /nologo $( DBG) /Gz /W3 /DNO_SSL_DL \
2013-01-24 05:14:11 +08:00
/I$( MSVC) /include /I$( LUA) /I. /GA
2013-01-22 16:59:13 +08:00
MSLIB = /link /incremental:no /libpath:$( MSVC) /lib /machine:IX86 \
user32.lib shell32.lib comdlg32.lib ws2_32.lib advapi32.lib \
cyassl.lib lua.lib
2012-09-20 21:55:09 +08:00
CYAFL = /c /I $( CYA) /include -I $( CYA) /include/openssl /I$( MSVC) /INCLUDE \
2011-07-22 04:50:18 +08:00
/I $( CYA) /ctaocrypt/include /D _LIB /D OPENSSL_EXTRA
2010-09-08 04:06:06 +08:00
2012-09-27 06:37:03 +08:00
LUA_SOURCES = $( LUA) /lapi.c $( LUA) /lcode.c $( LUA) /lctype.c \
$( LUA) /ldebug.c $( LUA) /ldo.c $( LUA) /ldump.c \
$( LUA) /lfunc.c $( LUA) /lgc.c $( LUA) /llex.c \
$( LUA) /lmem.c $( LUA) /lobject.c $( LUA) /lopcodes.c \
$( LUA) /lparser.c $( LUA) /lstate.c $( LUA) /lstring.c \
$( LUA) /ltable.c $( LUA) /ltm.c $( LUA) /lundump.c \
$( LUA) /lvm.c $( LUA) /lzio.c $( LUA) /lauxlib.c \
$( LUA) /lbaselib.c $( LUA) /lbitlib.c $( LUA) /lcorolib.c \
$( LUA) /ldblib.c $( LUA) /liolib.c $( LUA) /lmathlib.c \
$( LUA) /loslib.c $( LUA) /lstrlib.c $( LUA) /ltablib.c \
$( LUA) /loadlib.c $( LUA) /linit.c
2012-09-27 15:27:45 +08:00
LUA_OBJECTS = $( LUA_SOURCES:%.c= %.o)
CYA_SOURCES = $( CYA) /src/cyassl_int.c $( CYA) /src/cyassl_io.c \
$( CYA) /src/keys.c $( CYA) /src/tls.c $( CYA) /src/ssl.c \
$( CYA) /ctaocrypt/src/aes.c $( CYA) /ctaocrypt/src/arc4.c \
$( CYA) /ctaocrypt/src/asn.c $( CYA) /ctaocrypt/src/coding.c \
$( CYA) /ctaocrypt/src/ctc_asm.c $( CYA) /ctaocrypt/src/ctc_misc.c \
$( CYA) /ctaocrypt/src/cyassl_memory.c $( CYA) /ctaocrypt/src/des3.c \
$( CYA) /ctaocrypt/src/dh.c $( CYA) /ctaocrypt/src/dsa.c \
$( CYA) /ctaocrypt/src/ecc.c $( CYA) /ctaocrypt/src/hc128.c \
$( CYA) /ctaocrypt/src/hmac.c $( CYA) /ctaocrypt/src/integer.c \
$( CYA) /ctaocrypt/src/md4.c $( CYA) /ctaocrypt/src/md5.c \
$( CYA) /ctaocrypt/src/pwdbased.c $( CYA) /ctaocrypt/src/rabbit.c \
$( CYA) /ctaocrypt/src/random.c $( CYA) /ctaocrypt/src/ripemd.c \
$( CYA) /ctaocrypt/src/rsa.c $( CYA) /ctaocrypt/src/sha.c \
$( CYA) /ctaocrypt/src/sha256.c $( CYA) /ctaocrypt/src/sha512.c \
$( CYA) /ctaocrypt/src/tfm.c
2010-09-08 04:06:06 +08:00
2012-09-20 21:55:09 +08:00
cyassl.lib :
2012-09-27 06:37:03 +08:00
$( CL) /Fo$( CYA) / $( CYA_SOURCES) $( CYAFL) $( DEF)
$( MSVC) /bin/lib $( CYA) /*.obj /out:$@
lua.lib :
$( CL) /c /Fo$( LUA) / $( LUA_SOURCES)
$( MSVC) /bin/lib $( LUA_SOURCES:%.c= %.obj) /out:$@
2010-06-15 17:49:52 +08:00
2013-01-22 16:59:13 +08:00
windows_unit_test : cyassl .lib lua .lib
$( CL) test/unit_test.c $( MSLIB) /out:unit_test.exe
./unit_test.exe
2012-09-27 06:37:03 +08:00
windows : cyassl .lib lua .lib
2013-01-03 02:21:46 +08:00
$( MSVC) /bin/rc build\r es.rc
2013-01-24 05:14:11 +08:00
$( CL) main.c mongoose.c /DUSE_LUA $( MSLIB) build\r es.res \
2013-01-22 16:59:13 +08:00
/out:$( PROG) .exe /subsystem:windows
2013-01-17 07:43:06 +08:00
# $(CL) mongoose.c /GD $(LINK) /DLL /DEF:build\dll.def /out:$(PROG).dll
2010-05-04 04:46:42 +08:00
# Build for Windows under MinGW
2012-08-19 19:22:28 +08:00
#MINGWDBG= -DDEBUG -O0 -ggdb
2010-05-04 04:46:42 +08:00
MINGWDBG = -DNDEBUG -Os
2012-09-14 00:39:02 +08:00
MINGWOPT = -W -Wall -mthreads -Wl,--subsystem,console $( MINGWDBG) -DHAVE_STDINT $( GCC_WARNINGS) $( COPT)
#MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,windows $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
2010-05-04 04:46:42 +08:00
mingw :
2013-01-03 02:21:46 +08:00
windres build\r es.rc build\r es.o
2012-08-19 19:22:28 +08:00
$( CC) $( MINGWOPT) mongoose.c -lws2_32 \
2012-09-22 19:52:47 +08:00
-shared -Wl,--out-implib= $( PROG) .lib -o $( PROG) .dll
2013-01-18 21:22:44 +08:00
$( CC) $( MINGWOPT) mongoose.c main.c build\r es.o \
-lws2_32 -ladvapi32 -lcomdlg32 -o $( PROG) .exe
2010-05-04 04:46:42 +08:00
2012-09-27 07:33:33 +08:00
# Build for Windows under Cygwin
#CYGWINDBG= -DDEBUG -O0 -ggdb
CYGWINDBG = -DNDEBUG -Os
CYGWINOPT = -W -Wall -mthreads -Wl,--subsystem,console $( CYGWINDBG) -DHAVE_STDINT $( GCC_WARNINGS) $( COPT)
cygwin :
2013-01-03 02:21:46 +08:00
windres ./build/res.rc ./build/res.o
2012-09-27 07:33:33 +08:00
$( CC) $( CYGWINOPT) mongoose.c -lws2_32 \
-shared -Wl,--out-implib= $( PROG) .lib -o $( PROG) .dll
2013-01-03 02:21:46 +08:00
$( CC) $( CYGWINOPT) -Ibuild mongoose.c main.c ./build/res.o \
-lws2_32 -ladvapi32 -o $( PROG) .exe
2010-05-04 04:46:42 +08:00
##########################################################################
### Manuals, cleanup, test, release
##########################################################################
man :
2010-08-31 00:13:26 +08:00
groff -man -T ascii mongoose.1 | col -b > mongoose.txt
groff -man -T ascii mongoose.1 | less
2010-05-04 04:46:42 +08:00
# "TEST=unit make test" - perform unit test only
# "TEST=embedded" - test embedded API by building and testing test/embed.c
# "TEST=basic_tests" - perform basic tests only (no CGI, SSI..)
2012-08-19 19:22:28 +08:00
tests :
2010-05-04 04:46:42 +08:00
perl test/test.pl $( TEST)
release : clean
2013-01-10 05:21:04 +08:00
F = mongoose-` perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' mongoose.c` .tgz ; cd .. && tar -czf x mongoose/{ LICENSE,Makefile,examples,test,build,*.[ ch] ,*.md} && mv x mongoose/$$ F
2010-05-04 04:46:42 +08:00
clean :
2013-01-18 18:43:52 +08:00
cd examples && $( MAKE) clean
rm -rf *.o *.core $( PROG) *.obj *.so $( PROG) .txt *.dSYM *.tgz \
$( PROG) .exe *.dll *.lib build/res.o build/res.RES *.dSYM