1#
2# Notes:
3#
4#   * Compilation Defines:
5#
6#     FAKE_STAT
7#         - Enables time faking also for files' timestamps.
8#
9#     NO_ATFILE
10#         - Disables support for the fstatat() group of functions
11#
12#     PTHREAD
13#         - Define this to enable multithreading support.
14#
15#     PTHREAD_SINGLETHREADED_TIME
16#         - Define this if you want to single-thread time() ... there ARE
17#           possibile caching side-effects in a multithreaded environment
18#           without this, but the performance impact may require you to
19#           try it unsynchronized.
20#
21# 	  FAKE_SLEEP
22# 	      - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
23#
24#   * Compilation addition: second libMT target added for building the pthread-
25#     enabled library as a separate library
26#
27#   * Compilation switch change: previous versions compiled using '-nostartfiles'
28#     This is no longer the case since there is a 'startup' constructor for the library
29#     which is used to activate the start-at times when specified. This also initializes
30#     the dynamic disabling of the FAKE_STAT calls.
31#
32# By default, libfaketime will be compiled for your system's default architecture.
33# To build for a different architecture, add -arch flags to CFLAGS and LDFLAGS.
34#
35# default to clang to support thread local variables
36CC ?= clang
37INSTALL ?= install
38
39PREFIX ?= /usr/local
40
41CFLAGS += -DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -DPREFIX='"'${PREFIX}'"'
42LIB_LDFLAGS += -dynamiclib -current_version 0.9.6 -compatibility_version 0.7
43
44SONAME = 1
45LIBS = libfaketime.${SONAME}.dylib
46BINS = faketime
47
48all: ${LIBS} ${BINS}
49
50libfaketime.${SONAME}.dylib: libfaketime.c
51	${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIB_LDFLAGS} -install_name ${PREFIX}/lib/faketime/$@ $<
52
53faketime: faketime.c
54	${CC} -o $@ ${CFLAGS} ${LDFLAGS} $<
55
56clean:
57	@rm -f ${OBJ} ${LIBS} ${BINS}
58
59distclean: clean
60	@echo
61
62install: ${LIBS} ${BINS}
63	@echo
64	@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
65	$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/"
66	$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/"
67	$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/bin"
68	$(INSTALL) -m0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
69
70uninstall:
71	for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done
72	rmdir "${DESTDIR}${PREFIX}/lib/faketime"
73	rm -f "${DESTDIR}${PREFIX}/bin/faketime"
74
75.PHONY: all clean distclean install uninstall
76