Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # This Makefile is part of Mongoose web server project,
  2. # https://github.com/valenok/mongoose
  3. #
  4. # Example custom build:
  5. # COPT="-g -O0 -DNO_SSL_DL -DUSE_LUA -llua -lcrypto -lssl" make linux
  6. #
  7. # Flags are:
  8. # -DHAVE_MD5 - use system md5 library (-2kb)
  9. # -DNDEBUG - strip off all debug code (-5kb)
  10. # -DDEBUG - build debug version (very noisy) (+7kb)
  11. # -DNO_CGI - disable CGI support (-5kb)
  12. # -DNO_SSL - disable SSL functionality (-2kb)
  13. # -DNO_SSL_DL - link against system libssl library (-1kb)
  14. # -DCONFIG_FILE=\"file\" - use `file' as the default config file
  15. # -DSSL_LIB=\"libssl.so.<version>\" - use system versioned SSL shared object
  16. # -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
  17. # -DUSE_LUA - embed Lua in Mongoose (+100kb)
  18. PROG = mongoose
  19. CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread $(COPT)
  20. # To build with Lua, download and unzip Lua 5.2.1 source code into the
  21. # mongoose directory, and then add $(LUA_FLAGS) to CFLAGS below
  22. LUA = lua-5.2.1/src
  23. LUA_FLAGS = -I$(LUA) -L$(LUA) -llua -lm
  24. LUA_SOURCES = $(LUA)/lapi.c $(LUA)/lcode.c $(LUA)/lctype.c \
  25. $(LUA)/ldebug.c $(LUA)/ldo.c $(LUA)/ldump.c \
  26. $(LUA)/lfunc.c $(LUA)/lgc.c $(LUA)/llex.c \
  27. $(LUA)/lmem.c $(LUA)/lobject.c $(LUA)/lopcodes.c \
  28. $(LUA)/lparser.c $(LUA)/lstate.c $(LUA)/lstring.c \
  29. $(LUA)/ltable.c $(LUA)/ltm.c $(LUA)/lundump.c \
  30. $(LUA)/lvm.c $(LUA)/lzio.c $(LUA)/lauxlib.c \
  31. $(LUA)/lbaselib.c $(LUA)/lbitlib.c $(LUA)/lcorolib.c \
  32. $(LUA)/ldblib.c $(LUA)/liolib.c $(LUA)/lmathlib.c \
  33. $(LUA)/loslib.c $(LUA)/lstrlib.c $(LUA)/ltablib.c \
  34. $(LUA)/loadlib.c $(LUA)/linit.c
  35. LUA_OBJECTS = $(LUA_SOURCES:%.c=%.o)
  36. # Using Visual Studio 6.0. To build Mongoose:
  37. # Set MSVC variable below to where VS 6.0 is installed on your system
  38. # Run "PATH_TO_VC6\bin\nmake windows"
  39. MSVC = e:/vc6
  40. DBG = /Zi /Od
  41. #DBG = /DNDEBUG /O1
  42. CL = $(MSVC)/bin/cl /MD /TC /nologo $(DBG) /Gz /W3 /DNO_SSL_DL \
  43. /I$(MSVC)/include /I$(LUA) /I. /I$(YASSL) /I$(YASSL)/cyassl /GA
  44. MSLIB = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
  45. user32.lib shell32.lib comdlg32.lib ws2_32.lib advapi32.lib \
  46. cyassl.lib lua.lib
  47. # Stock windows binary builds with Lua and YASSL library.
  48. YASSL = e:/cyassl-2.4.6
  49. #YASSL = ~/stuff/cyassl-2.4.6
  50. YASSL_FLAGS = -I $(YASSL) -I $(YASSL)/cyassl \
  51. -D _LIB -D OPENSSL_EXTRA -D HAVE_ERRNO_H \
  52. -D HAVE_GETHOSTBYNAME -D HAVE_INET_NTOA -D HAVE_LIMITS_H \
  53. -D HAVE_MEMSET -D HAVE_SOCKET -D HAVE_STDDEF_H -D HAVE_STDLIB_H \
  54. -D HAVE_STRING_H -D HAVE_SYS_STAT_H -D HAVE_SYS_TYPES_H
  55. YASSL_SOURCES = \
  56. $(YASSL)/src/internal.c $(YASSL)/src/io.c $(YASSL)/src/keys.c \
  57. $(YASSL)/src/ssl.c $(YASSL)/src/tls.c $(YASSL)/ctaocrypt/src/hmac.c \
  58. $(YASSL)/ctaocrypt/src/random.c $(YASSL)/ctaocrypt/src/sha.c \
  59. $(YASSL)/ctaocrypt/src/sha256.c $(YASSL)/ctaocrypt/src/logging.c \
  60. $(YASSL)/ctaocrypt/src/error.c $(YASSL)/ctaocrypt/src/rsa.c \
  61. $(YASSL)/ctaocrypt/src/des3.c $(YASSL)/ctaocrypt/src/asn.c \
  62. $(YASSL)/ctaocrypt/src/coding.c $(YASSL)/ctaocrypt/src/arc4.c \
  63. $(YASSL)/ctaocrypt/src/md4.c $(YASSL)/ctaocrypt/src/md5.c \
  64. $(YASSL)/ctaocrypt/src/dh.c $(YASSL)/ctaocrypt/src/dsa.c \
  65. $(YASSL)/ctaocrypt/src/pwdbased.c $(YASSL)/ctaocrypt/src/aes.c \
  66. $(YASSL)/ctaocrypt/src/md2.c $(YASSL)/ctaocrypt/src/ripemd.c \
  67. $(YASSL)/ctaocrypt/src/sha512.c $(YASSL)/src/sniffer.c \
  68. $(YASSL)/ctaocrypt/src/rabbit.c $(YASSL)/ctaocrypt/src/misc.c \
  69. $(YASSL)/ctaocrypt/src/tfm.c $(YASSL)/ctaocrypt/src/integer.c \
  70. $(YASSL)/ctaocrypt/src/ecc.c $(YASSL)/src/ocsp.c $(YASSL)/src/crl.c \
  71. $(YASSL)/ctaocrypt/src/hc128.c $(YASSL)/ctaocrypt/src/memory.c
  72. all:
  73. @echo "make (linux|bsd|solaris|mac|windows|mingw|cygwin)"
  74. # Make sure that the compiler flags come last in the compilation string.
  75. # If not so, this can break some on some Linux distros which use
  76. # "-Wl,--as-needed" turned on by default in cc command.
  77. # Also, this is turned in many other distros in static linkage builds.
  78. linux:
  79. $(CC) mongoose.c main.c -o $(PROG) -ldl $(CFLAGS)
  80. mac: bsd
  81. bsd:
  82. $(CC) mongoose.c main.c -o $(PROG) $(CFLAGS)
  83. bsd_yassl:
  84. $(CC) mongoose.c main.c -o $(PROG) $(CFLAGS) $(YASSL_SOURCES) $(YASSL_FLAGS) -DNO_SSL_DL
  85. solaris:
  86. $(CC) mongoose.c main.c -lnsl -lsocket -o $(PROG) $(CFLAGS)
  87. cocoa:
  88. $(CC) mongoose.c main.c -DUSE_COCOA $(CFLAGS) -framework Cocoa -ObjC -arch i386 -arch x86_64 -o Mongoose
  89. 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
  90. u: $(LUA_OBJECTS)
  91. $(CC) test/unit_test.c -o unit_test -I. $(LUA_FLAGS) $(CFLAGS) -g -O0
  92. ./unit_test
  93. cyassl.lib:
  94. $(CL) /c /Fo$(YASSL)/ $(YASSL_SOURCES) $(YASSL_FLAGS) $(DEF)
  95. $(MSVC)/bin/lib $(YASSL)/*.obj /out:$@
  96. lua.lib:
  97. $(CL) /c /Fo$(LUA)/ $(LUA_SOURCES)
  98. $(MSVC)/bin/lib $(LUA_SOURCES:%.c=%.obj) /out:$@
  99. w: cyassl.lib lua.lib
  100. $(CL) test/unit_test.c $(MSLIB) /out:unit_test.exe
  101. ./unit_test.exe
  102. windows: cyassl.lib lua.lib
  103. $(MSVC)/bin/rc build\res.rc
  104. $(CL) main.c mongoose.c /DUSE_LUA $(MSLIB) build\res.res \
  105. /out:$(PROG).exe /subsystem:windows
  106. # Build for Windows under MinGW
  107. #MINGWDBG= -DDEBUG -O0 -ggdb
  108. MINGWDBG= -DNDEBUG -Os
  109. MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
  110. mingw:
  111. windres build\res.rc build\res.o
  112. $(CC) $(MINGWOPT) mongoose.c -lws2_32 \
  113. -shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
  114. $(CC) $(MINGWOPT) mongoose.c main.c build\res.o \
  115. -lws2_32 -ladvapi32 -lcomdlg32 -o $(PROG).exe
  116. # Build for Windows under Cygwin
  117. #CYGWINDBG= -DDEBUG -O0 -ggdb
  118. CYGWINDBG= -DNDEBUG -Os
  119. CYGWINOPT= -W -Wall -mthreads -Wl,--subsystem,console $(CYGWINDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
  120. cygwin:
  121. windres ./build/res.rc ./build/res.o
  122. $(CC) $(CYGWINOPT) mongoose.c -lws2_32 \
  123. -shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
  124. $(CC) $(CYGWINOPT) -Ibuild mongoose.c main.c ./build/res.o \
  125. -lws2_32 -ladvapi32 -o $(PROG).exe
  126. tests:
  127. perl test/test.pl $(TEST)
  128. release: clean
  129. 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
  130. clean:
  131. cd examples && $(MAKE) clean
  132. rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
  133. $(PROG).exe *.dll *.lib build/res.o build/res.RES *.dSYM