GNUmakefile 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. ################################################################################
  2. .PHONY: clean
  3. PROGRAM_NAME ?= vlmcsd
  4. CLIENT_NAME ?= vlmcs
  5. MULTI_NAME ?= vlmcsdmulti
  6. OBJ_NAME ?= libkms-static.o
  7. A_NAME ?= libkms.a
  8. CONFIG ?= config.h
  9. COMPILER_LANGUAGE ?= c
  10. # crypto library to use for standard algos, could save ~1-2kb ;)
  11. # can be either 'openssl', 'polarssl' or anything other for internal impl
  12. CRYPTO ?= internal
  13. # use DNS_PARSER=internal if your OS doesn't supply the DNS parser routines
  14. DNS_PARSER ?= OS
  15. # You should supply your own version string here
  16. VLMCSD_VERSION ?= $(shell test -d .svn && echo svn`svnversion`)
  17. FEATURES ?= full
  18. VERBOSE ?= NO
  19. ################################################################################
  20. CC ?= gcc
  21. TARGETPLATFORM := $(shell LANG=en_US.UTF-8 $(CC) -v 2>&1 | grep '^Target: ' | cut -f 2 -d ' ')
  22. ifneq (,$(findstring darwin,$(TARGETPLATFORM)))
  23. DARWIN := 1
  24. UNIX := 1
  25. endif
  26. ifneq (,$(findstring android,$(TARGETPLATFORM)))
  27. ANDROID := 1
  28. UNIX := 1
  29. ELF := 1
  30. endif
  31. ifneq (,$(findstring minix,$(TARGETPLATFORM)))
  32. MINIX := 1
  33. UNIX := 1
  34. ELF := 1
  35. endif
  36. ifneq (,$(findstring mingw,$(TARGETPLATFORM)))
  37. MINGW := 1
  38. WIN := 1
  39. PE := 1
  40. endif
  41. ifneq (,$(findstring cygwin,$(TARGETPLATFORM)))
  42. CYGWIN := 1
  43. WIN := 1
  44. PE := 1
  45. endif
  46. ifneq (,$(findstring cygnus,$(TARGETPLATFORM)))
  47. CYGWIN := 1
  48. WIN := 1
  49. PE := 1
  50. endif
  51. ifneq (,$(findstring freebsd,$(TARGETPLATFORM)))
  52. FREEBSD := 1
  53. UNIX := 1
  54. BSD := 1
  55. ELF := 1
  56. endif
  57. ifneq (,$(findstring netbsd,$(TARGETPLATFORM)))
  58. NETBSD := 1
  59. UNIX := 1
  60. BSD := 1
  61. ELF := 1
  62. endif
  63. ifneq (,$(findstring openbsd,$(TARGETPLATFORM)))
  64. OPENBSD := 1
  65. UNIX := 1
  66. BSD := 1
  67. ELF := 1
  68. endif
  69. ifneq (,$(findstring solaris,$(TARGETPLATFORM)))
  70. SOLARIS := 1
  71. UNIX := 1
  72. ELF := 1
  73. endif
  74. ifneq (,$(findstring linux,$(TARGETPLATFORM)))
  75. LINUX := 1
  76. UNIX := 1
  77. ELF := 1
  78. endif
  79. ifneq (,$(findstring gnu,$(TARGETPLATFORM)))
  80. ifeq (,$(findstring linux,$(TARGETPLATFORM)))
  81. UNIX := 1
  82. HURD := 1
  83. ELF := 1
  84. endif
  85. endif
  86. ifeq ($(CYGWIN),1)
  87. DLL_NAME ?= cygkms.dll
  88. else ifeq ($(WIN),1)
  89. DLL_NAME ?= libkms.dll
  90. else ifeq ($(DARWIN),1)
  91. DLL_NAME ?= libkms.dylib
  92. else
  93. DLL_NAME ?= libkms.so
  94. endif
  95. BASECFLAGS = -DVLMCSD_COMPILER=\"$(notdir $(CC))\" -DVLMCSD_PLATFORM=\"$(TARGETPLATFORM)\" -DCONFIG=\"$(CONFIG)\" -DBUILD_TIME=$(shell date '+%s') -g -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections
  96. BASELDFLAGS =
  97. STRIPFLAGS =
  98. CLIENTLDFLAGS =
  99. SERVERLDFLAGS =
  100. ifndef SAFE_MODE
  101. BASECFLAGS += -fvisibility=hidden -pipe -fno-common -fno-exceptions -fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fmerge-all-constants
  102. ifeq ($(ELF),1)
  103. BASELDFLAGS += -Wl,-z,norelro
  104. endif
  105. ifneq (,$(findstring gcc,$(notdir $(CC))))
  106. BASECFLAGS += -flto
  107. endif
  108. endif
  109. ifeq ($(NOLIBS),1)
  110. NOLRESOLV=1
  111. NOLPTHREAD=1
  112. endif
  113. ifneq ($(NOLIBS),1)
  114. ifeq ($(MINGW),1)
  115. BASELDFLAGS += -lws2_32 -liphlpapi
  116. endif
  117. endif
  118. ifneq ($(NO_DNS),1)
  119. ifneq ($(ANDROID),1)
  120. ifneq ($(NOLRESOLV),1)
  121. ifeq ($(MINGW),1)
  122. CLIENTLDFLAGS += -ldnsapi
  123. endif
  124. ifeq ($(LINUX),1)
  125. CLIENTLDFLAGS += -lresolv
  126. endif
  127. ifeq ($(HURD),1)
  128. CLIENTLDFLAGS += -lresolv
  129. endif
  130. ifeq ($(DARWIN),1)
  131. CLIENTLDFLAGS += -lresolv
  132. endif
  133. ifeq ($(CYGWIN),1)
  134. DNS_PARSER := internal
  135. CLIENTLDFLAGS += -lresolv
  136. endif
  137. ifeq ($(OPENBSD),1)
  138. DNS_PARSER := internal
  139. endif
  140. ifeq ($(SOLARIS),1)
  141. CLIENTLDFLAGS += -lresolv
  142. endif
  143. endif
  144. endif
  145. else
  146. BASECFLAGS += -DNO_DNS
  147. endif
  148. ifneq ($(CAT),2)
  149. BASECFLAGS += "-Wall"
  150. endif
  151. ifeq ($(DARWIN), 1)
  152. STRIPFLAGS += -Wl,-S -Wl,-x
  153. BASECFLAGS += -Wno-deprecated-declarations
  154. else ifeq ($(shell uname), SunOS)
  155. STRIPFLAGS += -s
  156. ifeq ($(notdir $(LD_ALTEXEC)),gld)
  157. BASELDFLAGS += -Wl,--gc-sections
  158. endif
  159. BASELDFLAGS += -lsocket
  160. else
  161. ifneq ($(CC),tcc)
  162. BASELDFLAGS += -Wl,--gc-sections
  163. endif
  164. STRIPFLAGS += -s
  165. endif
  166. LIBRARY_CFLAGS = -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_EXTENDED_PRODUCT_LIST -DNO_BASIC_PRODUCT_LIST -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT
  167. ifeq ($(FEATURES), embedded)
  168. BASECFLAGS += -DNO_HELP -DNO_USER_SWITCH -DNO_BASIC_PRODUCT_LIST -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_VERBOSE_LOG -DNO_VERSION_INFORMATION
  169. else ifeq ($(FEATURES), autostart)
  170. BASECFLAGS += -DNO_HELP -DNO_VERSION_INFORMATION
  171. else ifeq ($(FEATURES), minimum)
  172. BASECFLAGS += -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_EXTENDED_PRODUCT_LIST -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT
  173. else ifeq ($(FEATURES), most)
  174. BASECFLAGS += -DNO_SIGHUP -DNO_PID_FILE -DNO_LIMIT
  175. else ifeq ($(FEATURES), inetd)
  176. BASECFLAGS += -DNO_SIGHUP -DNO_SOCKETS -DNO_PID_FILE -DNO_LIMIT -DNO_VERSION_INFORMATION
  177. else ifeq ($(FEATURES), fixedepids)
  178. BASECFLAGS += -DNO_SIGHUP -DNO_CL_PIDS -DNO_RANDOM_EPID -DNO_INI_FILE
  179. endif
  180. ifdef INI
  181. BASECFLAGS += -DINI_FILE=\"$(INI)\"
  182. endif
  183. ifeq ($(NO_GETIFADDRS), 1)
  184. BASECFLAGS += -DNO_GETIFADDRS
  185. endif
  186. ifeq ($(THREADS), 1)
  187. BASECFLAGS += -DUSE_THREADS
  188. endif
  189. ifeq ($(CHILD_HANDLER), 1)
  190. BASECFLAGS += -DCHILD_HANDLER
  191. endif
  192. ifeq ($(NO_TIMEOUT), 1)
  193. BASECFLAGS += -DNO_TIMEOUT
  194. endif
  195. ifdef WINDOWS
  196. BASECFLAGS += -DEPID_WINDOWS=\"$(WINDOWS)\"
  197. endif
  198. ifdef OFFICE2010
  199. BASECFLAGS += -DEPID_OFFICE2010=\"$(OFFICE2010)\"
  200. endif
  201. ifdef OFFICE2013
  202. BASECFLAGS += -DEPID_OFFICE2013=\"$(OFFICE2013)\"
  203. endif
  204. ifdef OFFICE2016
  205. BASECFLAGS += -DEPID_OFFICE2016=\"$(OFFICE2016)\"
  206. endif
  207. ifdef HWID
  208. BASECFLAGS += -DHWID=$(HWID)
  209. endif
  210. ifdef TERMINAL_WIDTH
  211. BASECFLAGS += -DTERMINAL_FIXED_WIDTH=$(TERMINAL_WIDTH) -DDISPLAY_WIDTH=\"$(TERMINAL_WIDTH)\"
  212. endif
  213. ifeq ($(NOPROCFS), 1)
  214. BASECFLAGS += -DNO_PROCFS
  215. endif
  216. ifeq ($(AUXV), 1)
  217. BASECFLAGS += -DUSE_AUXV
  218. endif
  219. ifneq ($(ANDROID), 1)
  220. ifneq ($(MINIX), 1)
  221. ifneq ($(NOLPTHREAD), 1)
  222. ifeq ($(THREADS), 1)
  223. SERVERLDFLAGS += -lpthread
  224. endif
  225. ifeq (,$(findstring NO_LIMIT,$(CFLAGS) $(BASECFLAGS)))
  226. SERVERLDFLAGS += -lpthread
  227. endif
  228. endif
  229. endif
  230. endif
  231. $(MULTI_NAME): BASECFLAGS += -DMULTI_CALL_BINARY=1
  232. all: $(CLIENT_NAME) $(PROGRAM_NAME)
  233. #ifdef CAT
  234. allmulti: $(CLIENT_NAME) $(PROGRAM_NAME) $(MULTI_NAME)
  235. #endif
  236. ifneq ($(strip $(VLMCSD_VERSION)),)
  237. BASECFLAGS += -DVERSION=\"$(VLMCSD_VERSION),\ built\ $(shell date -u '+%Y-%m-%d %H:%M:%S' | sed -e 's/ /\\ /g')\ UTC\"
  238. endif
  239. ifdef CAT
  240. BASECFLAGS += -DONE_FILE
  241. endif
  242. SRCS = crypto.c kms.c endian.c output.c shared_globals.c helpers.c
  243. HEADERS = $(CONFIG) types.h rpc.h vlmcsd.h endian.h crypto.h kms.h network.h output.h shared_globals.h vlmcs.h helpers.h
  244. DEPS = $(MULTI_SRCS:.c=.d)
  245. VLMCSD_SRCS = vlmcsd.c $(SRCS)
  246. VLMCSD_OBJS = $(VLMCSD_SRCS:.c=.o)
  247. VLMCS_SRCS = vlmcs.c $(SRCS)
  248. VLMCS_OBJS = $(VLMCS_SRCS:.c=.o)
  249. MULTI_SRCS = vlmcsd.c vlmcs.c vlmcsdmulti.c $(SRCS)
  250. MULTI_OBJS = $(SRCS:.c=.o) vlmcsd-m.o vlmcs-m.o vlmcsdmulti-m.o
  251. DLL_SRCS = libkms.c vlmcs.c $(SRCS)
  252. DLL_OBJS = $(DLL_SRCS:.c=-l.o)
  253. PDFDOCS = vlmcs.1.pdf vlmcsd.7.pdf vlmcsd.8.pdf vlmcsdmulti.1.pdf vlmcsd.ini.5.pdf vlmcsd-floppy.7.pdf
  254. HTMLDOCS = $(PDFDOCS:.pdf=.html)
  255. UNIXDOCS = $(PDFDOCS:.pdf=.unix.txt)
  256. DOSDOCS = $(PDFDOCS:.pdf=.dos.txt)
  257. ifneq ($(NO_DNS),1)
  258. VLMCS_SRCS += dns_srv.c
  259. MULTI_SRCS += dns_srv.c
  260. MULTI_OBJS += dns_srv.o
  261. ifeq ($(DNS_PARSER),internal)
  262. ifneq ($(MINGW),1)
  263. VLMCS_SRCS += ns_parse.c ns_name.c
  264. MULTI_SRCS += ns_parse.c ns_name.c
  265. MULTI_OBJS += ns_parse.o ns_name.o
  266. BASECFLAGS += "-DDNS_PARSER_INTERNAL"
  267. endif
  268. endif
  269. endif
  270. ifeq ($(MSRPC),1)
  271. VLMCSD_SRCS += msrpc-server.c
  272. VLMCS_SRCS += msrpc-client.c
  273. MULTI_SRCS += msrpc-server.c msrpc-client.c
  274. MULTI_OBJS += msrpc-server-m.o msrpc-client-m.o
  275. DLL_SRCS += msrpc-server.c
  276. BASECFLAGS += -DUSE_MSRPC -Wno-unknown-pragmas
  277. BASELDFLAGS += -lrpcrt4
  278. else
  279. SRCS += network.c rpc.c
  280. endif
  281. ifeq ($(GETIFADDRS),musl)
  282. ifneq ($(NO_GETIFADDRS),1)
  283. BASECFLAGS += -DGETIFADDRS_MUSL
  284. VLMCSD_SRCS += getifaddrs-musl.c
  285. MULTI_SRCS += getifaddrs-musl.c
  286. VLMCS_SRCS += getifaddrs-musl.c
  287. DLL_SRCS += getifaddrs-musl.c
  288. MULTI_OBJS += getifaddrs-musl.o
  289. endif
  290. endif
  291. ifeq ($(ANDROID),1)
  292. ifneq ($(NO_GETIFADDRS),1)
  293. VLMCSD_SRCS += ifaddrs-android.c
  294. MULTI_SRCS += ifaddrs-android.c
  295. DLL_SRCS += ifaddrs-android.c
  296. MULTI_OBJS += ifaddrs-android.o
  297. endif
  298. endif
  299. ifeq "$(WIN)" "1"
  300. VLMCSD_SRCS += ntservice.c
  301. MULTI_SRCS += ntservice.c
  302. MULTI_OBJS += ntservice.o
  303. endif
  304. ifeq ($(CRYPTO), openssl_with_aes)
  305. BASECFLAGS += -D_CRYPTO_OPENSSL -D_USE_AES_FROM_OPENSSL
  306. BASELDFLAGS += -lcrypto
  307. SRCS += crypto_openssl.c
  308. else ifeq ($(CRYPTO), openssl_with_aes_soft)
  309. BASECFLAGS += -D_CRYPTO_OPENSSL -D_USE_AES_FROM_OPENSSL -D_OPENSSL_SOFTWARE
  310. BASELDFLAGS += -lcrypto
  311. SRCS += crypto_openssl.c
  312. else ifeq ($(CRYPTO), openssl)
  313. BASECFLAGS += -D_CRYPTO_OPENSSL
  314. BASELDFLAGS += -lcrypto
  315. SRCS += crypto_openssl.c
  316. else ifeq ($(CRYPTO), polarssl)
  317. BASECFLAGS += -D_CRYPTO_POLARSSL
  318. BASELDFLAGS += -lpolarssl
  319. else ifeq ($(CRYPTO), windows)
  320. BASECFLAGS += -D_CRYPTO_WINDOWS
  321. SRCS += crypto_windows.c
  322. else
  323. BASECFLAGS += -D_CRYPTO_INTERNAL
  324. SRCS += crypto_internal.c
  325. endif
  326. ifneq ($(STRIP),0)
  327. BASELDFLAGS += $(STRIPFLAGS)
  328. endif
  329. ifeq ($(OPENSSL_HMAC),0)
  330. BASECFLAGS += -D_OPENSSL_NO_HMAC
  331. endif
  332. ifeq ($(DEPENDENCIES),2)
  333. BASECFLAGS += -MMD
  334. endif
  335. ifeq ($(VERBOSE),3)
  336. COMPILER := $(shell printf "%-40s" $(notdir $(CC)))
  337. ARCHIVER := $(shell printf "%-40s" $(notdir $(AR)))
  338. endif
  339. ARCMD := AR
  340. ifdef CAT
  341. LDCMD := CC/LD
  342. else
  343. LDCMD := LD
  344. endif
  345. -include $(MULTI_SRCS:.c=.d)
  346. %.o: %.c
  347. ifeq ($(VERBOSE),1)
  348. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -c $<
  349. ifeq ($(DEPENDENCIES),1)
  350. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -MM -MF $*.d $<
  351. endif
  352. else
  353. @echo "$(COMPILER) CC $@ <- $<"
  354. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -c $<
  355. ifeq ($(DEPENDENCIES),1)
  356. @echo "$(COMPILER) DEP $*.d <- $<"
  357. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -MM -MF $*.d $<
  358. endif
  359. endif
  360. %-m.o: %.c
  361. ifeq ($(VERBOSE),1)
  362. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -o $@ -c $<
  363. ifeq ($(DEPENDENCIES),1)
  364. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -MM -MF $*.d $<
  365. endif
  366. else
  367. @echo "$(COMPILER) CC $@ <- $<"
  368. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -o $@ -c $<
  369. ifeq ($(DEPENDENCIES),1)
  370. @echo "$(COMPILER) DEP $*.d <- $<"
  371. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -MM -MF $*.d $<
  372. endif
  373. endif
  374. %-l.o: %.c
  375. ifeq ($(VERBOSE),1)
  376. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) -fvisibility=hidden -c -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC -o $@ -c $<
  377. ifeq ($(DEPENDENCIES),1)
  378. $(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) $(SERVERLDFLAGS) -fvisibility=hidden -c -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC -MM -MF $*.d $<
  379. endif
  380. else
  381. @echo "$(COMPILER) CC $@ <- $<"
  382. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) $(SERVERLDFLAGS) -fvisibility=hidden -c -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC -o $@ -c $<
  383. ifeq ($(DEPENDENCIES),1)
  384. @echo "$(COMPILER) DEP $*.d <- $<"
  385. @$(CC) -x$(COMPILER_LANGUAGE) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(PLATFORMFLAGS) $(SERVERLDFLAGS) -fvisibility=hidden -c -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC -MM -MF $*.d $<
  386. endif
  387. endif
  388. ifdef CAT
  389. BUILDCOMMAND = cat $^ | $(CC) -x$(COMPILER_LANGUAGE) -o $@ -
  390. VLMCSD_PREREQUISITES = $(VLMCSD_SRCS)
  391. VLMCS_PREREQUISITES = $(VLMCS_SRCS)
  392. MULTI_PREREQUISITES = $(MULTI_SRCS)
  393. DLL_PREREQUISITES = $(DLL_SRCS)
  394. OBJ_PREREQUISITES = $(DLL_SRCS)
  395. else
  396. BUILDCOMMAND = $(CC) -o $@ $^
  397. VLMCSD_PREREQUISITES = $(VLMCSD_OBJS)
  398. VLMCS_PREREQUISITES = $(VLMCS_OBJS)
  399. MULTI_PREREQUISITES = $(MULTI_OBJS)
  400. DLL_PREREQUISITES = $(DLL_OBJS)
  401. OBJ_PREREQUISITES = $(DLL_OBJS)
  402. endif
  403. ifeq ($(VERBOSE),1)
  404. BUILDCOMMANDPREFIX = +
  405. else
  406. BUILDCOMMANDPREFIX = +@
  407. endif
  408. INFOCOMMAND = +@echo "$(COMPILER) $(LDCMD) $@ <- $^"
  409. ARINFOCOMMAND = +@echo "$(ARCHIVER) $(ARCMD) $@ <. $^"
  410. VLMCSD_COMMAND = $(BUILDCOMMANDPREFIX)$(BUILDCOMMAND) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(BASELDFLAGS) $(LDFLAGS) $(SERVERLDFLAGS)
  411. VLMCS_COMMAND = $(BUILDCOMMANDPREFIX)$(BUILDCOMMAND) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(BASELDFLAGS) $(LDFLAGS) $(CLIENTLDFLAGS)
  412. MULTI_COMMAND = $(BUILDCOMMANDPREFIX)$(BUILDCOMMAND) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(BASELDFLAGS) $(LDFLAGS) $(CLIENTLDFLAGS) $(SERVERLDFLAGS)
  413. DLL_COMMAND = $(BUILDCOMMANDPREFIX)$(BUILDCOMMAND) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(BASELDFLAGS) $(LDFLAGS) $(SERVERLDFLAGS) -fvisibility=hidden -shared -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC
  414. OBJ_COMMAND = $(BUILDCOMMANDPREFIX)$(BUILDCOMMAND) $(PLATFORMFLAGS) $(BASECFLAGS) $(CFLAGS) $(BASELDFLAGS) $(LDFLAGS) $(SERVERLDFLAGS) -fvisibility=hidden -c -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC
  415. $(PROGRAM_NAME): $(VLMCSD_PREREQUISITES)
  416. ifneq ($(VERBOSE),1)
  417. $(INFOCOMMAND)
  418. endif
  419. $(VLMCSD_COMMAND)
  420. $(CLIENT_NAME): $(VLMCS_PREREQUISITES)
  421. ifneq ($(VERBOSE),1)
  422. $(INFOCOMMAND)
  423. endif
  424. $(VLMCS_COMMAND)
  425. $(MULTI_NAME): $(MULTI_PREREQUISITES)
  426. ifneq ($(VERBOSE),1)
  427. $(INFOCOMMAND)
  428. endif
  429. $(MULTI_COMMAND)
  430. $(DLL_NAME): $(DLL_PREREQUISITES)
  431. ifneq ($(VERBOSE),1)
  432. $(INFOCOMMAND)
  433. endif
  434. $(DLL_COMMAND)
  435. ifndef CAT
  436. $(OBJ_NAME):
  437. +@echo Cannot make $@ without CAT defined. Please create $(A_NAME)
  438. else
  439. $(OBJ_NAME): $(OBJ_PREREQUISITES)
  440. ifneq ($(VERBOSE),1)
  441. $(INFOCOMMAND)
  442. endif
  443. $(OBJ_COMMAND)
  444. endif
  445. ifdef CAT
  446. $(A_NAME): $(OBJ_NAME)
  447. else
  448. $(A_NAME): BASECFLAGS += -fvisibility=hidden -DIS_LIBRARY=1 $(LIBRARY_CFLAGS) -UNO_SOCKETS -UUSE_MSRPC
  449. $(A_NAME): $(DLL_OBJS)
  450. endif
  451. ifneq ($(VERBOSE),1)
  452. $(ARINFOCOMMAND)
  453. endif
  454. +@rm -f $@
  455. $(BUILDCOMMANDPREFIX)$(AR) rcs $@ $^
  456. %.pdf : %
  457. ifeq ($(shell uname), Darwin)
  458. groff -Tps -mandoc -c $< | pstopdf -i -o $@
  459. else
  460. groff -Tpdf -mandoc -c $< > $@
  461. endif
  462. %.html : %
  463. groff -Thtml -mandoc -c $< > $@
  464. %.unix.txt : %
  465. groff -P -c -Tutf8 -mandoc -c $< | col -bx > $@
  466. %.dos.txt : %.unix.txt
  467. # unix2dos -n $< $@
  468. # sed -e 's/$$/\r/' $< > $@
  469. awk 'sub("$$", "\r")' $< > $@
  470. pdfdocs : $(PDFDOCS)
  471. dosdocs : $(DOSDOCS)
  472. unixdocs : $(UNIXDOCS)
  473. htmldocs : $(HTMLDOCS)
  474. alldocs : $(UNIXDOCS) $(HTMLDOCS) $(PDFDOCS) $(DOSDOCS)
  475. clean:
  476. rm -f *.o *.d *_all.c libkms_all_*.c $(PROGRAM_NAME) $(MULTI_NAME) $(DLL_NAME) $(CLIENT_NAME) $(PDFDOCS) $(DOSDOCS) $(UNIXDOCS) $(HTMLDOCS) $(OBJ_NAME) $(A_NAME) *.a
  477. dnsclean:
  478. rm -f dns_srv.o
  479. help:
  480. @echo "Type"
  481. @echo " ${MAKE} - to build $(PROGRAM_NAME) and $(CLIENT_NAME)"
  482. @echo " ${MAKE} clean - to remove $(PROGRAM_NAME) and $(CLIENT_NAME)"
  483. @echo " ${MAKE} help - to see this help"
  484. @echo " ${MAKE} pdfdocs - Create PDF versions of the documentation (Requires groff with PDF support)."
  485. @echo " ${MAKE} htmldocs - Create HTML versions of the documentation."
  486. @echo " ${MAKE} unixdocs - Create Unix TXT versions of the documentation."
  487. @echo " ${MAKE} dosdocs - Create DOS/Windows TXT versions of the documentation."
  488. @echo " ${MAKE} alldocs - Create all versions of the documentation."
  489. @echo " ${MAKE} -j <x> - Use <x> parallel tasks (SMP support) when compiling $(PROGRAM_NAME) and $(CLIENT_NAME)"
  490. @echo ""
  491. @echo " ${MAKE} $(PROGRAM_NAME) - to build the server only."
  492. @echo " ${MAKE} $(CLIENT_NAME) - to build the client only."
  493. @echo " ${MAKE} $(MULTI_NAME) - to build $(PROGRAM_NAME) and $(CLIENT_NAME) in a single multi-call binary"
  494. @echo " ${MAKE} $(DLL_NAME) - to build the shared library $(DLL_NAME)"
  495. @echo " ${MAKE} $(A_NAME) - to build the static library $(A_NAME)"
  496. @echo ""
  497. @echo "Options"
  498. @echo " CONFIG=<x> Compile <x> as instead of config.h."
  499. @echo " INI=<x> Compile $(PROGRAM_NAME) with default ini file <x>"
  500. @echo " PROGRAM_NAME=<x> Use <x> as output file name for the KMS server. Defaults to vlmcsd."
  501. @echo " CLIENT_NAME=<x> Use <x> as output file name for the KMS client. Defaults to vlmcs."
  502. @echo " MULTI_NAME=<x> Use <x> as output file name for the multi-call binary. Defaults to vlmcsdmulti."
  503. @echo " DEPENDENCIES=1 Create dependency files."
  504. @echo " CRYPTO=openssl Use openssl for SHA256/HMAC calculations."
  505. @echo " CRYPTO=openssl_with_aes EXPERIMENTAL: Use openssl for SHA256/HMAC and AES calculations (hardware, e.g. AES-NI on x86)."
  506. @echo " CRYPTO=openssl_with_aes_soft EXPERIMENTAL: Use openssl for SHA256/HMAC and AES calculations (software)."
  507. @echo " CRYPTO=polarssl Use polarssl instead of internal crypto code for SHA256/HMAC calculations."
  508. @echo " CRYPTO=windows Use Windows CryptoAPI instead of internal crypto code for SHA256/HMAC calculations."
  509. @echo " MSRPC=1 Use Microsoft RPC instead of vlmcsd's internal RPC. Only works with Windows and Cygwin targets."
  510. @echo " CC=<x> Use compiler <x>. Supported compilers are gcc, icc, tcc and clang. Others may or may not work."
  511. @echo " AR=<x> Use <x> instead of ar to build $(A_NAME). Set to gcc-ar if you want to use gcc's LTO feature."
  512. @echo " COMPILER_LANGUAGE=<x> May be c or c++."
  513. @echo " TERMINAL_WIDTH=<x> Assume a fixed terminal width of <x> columns. Use in case of problems only."
  514. @echo " VLMCSD_VERSION=<x> Sets <x> as your version identifier. Defaults to \"private build\"."
  515. @echo " CFLAGS=<x> Pass <x> as additional arguments to the compiler."
  516. @echo " LDFLAGS=<x> Pass <x> as additional arguments to the linker."
  517. @echo " PLATFORMFLAGS=<x> Pass <x> as additional arguments to the compiler and the linker."
  518. @echo " BASECFLAGS=<x> Pass only <x> as arguments to the compiler (advanced users only)."
  519. @echo " BASELDFLAGS=<x> Pass only <x> as arguments to the linker (advanced users only)."
  520. @echo " STRIP=0 Don't strip debug information from $(PROGRAM_NAME) and $(CLIENT_NAME) (for developers)."
  521. @echo " VERBOSE=1 Be verbose when making targets."
  522. @echo " VERBOSE=3 Show name of compiler."
  523. @echo " THREADS=1 Use threads instead of fork(). Automatically set for native Windows. Recommended for Cygwin."
  524. @echo " WINDOWS=<x> Use <x> as the default ePID for Windows (when using $(PROGRAM_NAME) with -r 0)."
  525. @echo " OFFICE2010=<x> Use <x> as the default ePID for Office2010 (when using $(PROGRAM_NAME) with -r 0)."
  526. @echo " OFFICE2013=<x> Use <x> as the default ePID for Office2013 (when using $(PROGRAM_NAME) with -r 0)."
  527. @echo " OFFICE2016=<x> Use <x> as the default ePID for Office2016 (when using $(PROGRAM_NAME) with -r 0)."
  528. @echo " HWID=<x> Use <x> as the default HWID (when it can't be found in an ini file)."
  529. @echo " FEATURES=full Compile $(PROGRAM_NAME) with all features (default)."
  530. @echo " FEATURES=most Compile $(PROGRAM_NAME) without rarely used features."
  531. @echo " FEATURES=embedded Compile $(PROGRAM_NAME) with typical features for embedded systems."
  532. @echo " FEATURES=autostart Removes features typically not needed if you place $(PROGRAM_NAME) in an autostart script."
  533. @echo " FEATURES=inetd Compile $(PROGRAM_NAME) for running through an internet superserver only."
  534. @echo " FEATURES=minimum Compiles only basic features of $(PROGRAM_NAME)."
  535. @echo " FEATURES=fixedepids $(PROGRAM_NAME) only uses bultin internal ePIDs."
  536. @echo ""
  537. @echo "Useful CFLAGS to save memory when running $(PROGRAM_NAME) on very small embedded devices (finer control than FEATURES=)"
  538. @echo " -DNO_EXTENDED_PRODUCT_LIST Don't compile the detailed product list."
  539. @echo " -DNO_BASIC_PRODUCT_LIST Don't compile the basic product list."
  540. @echo " -DNO_VERBOSE_LOG Don't support verbose logging. Removes -v option."
  541. @echo " -DNO_LOG Don't add support for logging. Implies -DNO_VERBOSE_LOG -DNO_EXTENDED_PRODUCT_LIST and -DNO_BASIC_PRODUCT_LIST."
  542. @echo " -DNO_RANDOM_EPID Don't support random ePIDs."
  543. @echo " -DNO_INI_FILE Don't support reading ePIDs/HWIDs from a file."
  544. @echo " -DNO_PID_FILE Don't support writing a PID file. Removes -p option."
  545. @echo " -DNO_USER_SWITCH Don't support changing uid/gid after program start. Removes -u and -g options."
  546. @echo " -DNO_HELP Don't support command line help."
  547. @echo " -DNO_CUSTOM_INTERVALS Don't support custom intervals for retry and refresh activation. Removes -A and -R options."
  548. @echo " -DNO_FREEBIND Don't support binding to foreign IP addresses. Removes -F0 and -F1 options. Only affects FreeBSD and Linux."
  549. @echo " -DSIMPLE_SOCKETS Compile $(PROGRAM_NAME) with basic socket support only. Removes -L option."
  550. @echo " -DNO_SOCKETS Don't support standalone operation. Requires an internet superserver to start $(PROGRAM_NAME)."
  551. @echo " -DNO_CL_PIDS Don't support specifying ePIDs and HwId from the command line in $(PROGRAM_NAME)."
  552. @echo " -DNO_LIMIT Don't support limiting concurrent clients in $(PROGRAM_NAME)."
  553. @echo " -DNO_SIGHUP Don't support SIGHUP handling in $(PROGRAM_NAME)."
  554. @echo " -DNO_VERSION_INFORMATION Don't support displaying version information in $(PROGRAM_NAME) and $(CLIENT_NAME). Removes -V option."
  555. @echo " -DNO_PRIVATE_IP_DETECT Don't support protection against clients with public IP addresses in $(PROGRAM_NAME)"
  556. @echo ""
  557. @echo "Troubleshooting options"
  558. @echo " CAT=1 Combine all sources in a single in-memory file and compile directly to target."
  559. @echo " NOPROCFS=1 Don't rely on a properly mounted proc filesystem in /proc."
  560. @echo " AUXV=1 Use /proc/self/auxv (requires Linux with glibc >= 2.16 or musl.)"
  561. @echo " NOLPTHREAD=1 Disable detection if -lpthread is required (for use with Android NDK)."
  562. @echo " NOLRESOLV=1 Disable detection if -lresolv is required (for use with Android NDK)."
  563. @echo " NOLIBS=1 Do not attempt to autodetect any library dependencies."
  564. @echo " OPENSSL_HMAC=0 Compile for openssl versions that don't have HMAC support (required on some embedded devices)."
  565. @echo " NO_TIMEOUT=1 Do not set timeouts for sockets (for systems that don't support it)."
  566. @echo " CHILD_HANDLER=1 Install a handler for SIGCHLD (for systems that don't support SA_NOCLDWAIT)."
  567. @echo " NO_DNS=1 Compile $(CLIENT_NAME) without support for detecting KMS servers via DNS."
  568. @echo " NO_GETIFADDRS=1 Compile $(PROGRAM_NAME) without using getifaddrs()."
  569. @echo " GETIFADDRS=musl Compile $(PROGRAM_NAME) with its own implementation of getifaddrs() based on musl."
  570. @echo " DNS_PARSER=internal Use $(CLIENT_NAME) internal DNS parsing routines. No effect on MingW (native Windows)."
  571. @echo ""
  572. @echo "Other useful CFLAGS"
  573. @echo " -DSUPPORT_WINE Add code that the Windows version of $(PROGRAM_NAME) runs on Wine if MSRPC=1"
  574. @echo " -D_PEDANTIC Report rare error/warning conditions instead of silently ignoring them."
  575. @echo " -DINCLUDE_BETAS Include SKU / activation IDs for obsolete beta/preview products."
  576. @echo " -DFD_SETSIZE=<x> Allow <x> -L statements in $(PROGRAM_NAME) (default: 64 on Windows, 1024 on most Unixes)."
  577. @echo " -flto Use link time optimization. Not supported by old compilers (gcc < 4.7). Use whenever supported."
  578. @echo " -flto=jobserver Utilize all CPUs during link time optimization. Requires ${MAKE} -j <cpus>"
  579. @echo " -fno-stack-protector No stack checking. Smaller binaries."
  580. @echo " -pipe Use pipes instead of temporary files (faster compilation, extends the life of your SSD)."