Allow use hostname instead of ip address
[tedtools.git] / Makefile.global
1
2 ECHO=echo
3
4 ifndef OS
5 OS=$(shell uname)
6 endif
7
8 CFLAGS=-Wall -pedantic -ansi -O2 -g -DASSERT_CORE -DHAVE_HSTRERROR 
9 ifeq ($(OS), FreeBSD)
10 CFLAGS+= -DHAVE_POLL_H
11 endif
12
13 ifeq ($(OS), Linux)
14 CFLAGS+= -DHAVE_SYS_POLL_H -D_GNU_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64
15 endif
16
17 CFLAGS+=$(EXTRAFLAGS)
18
19 CC=gcc
20 AR=ar
21 RANLIB=ranlib
22 LD=ld
23 LIB=-lm $(EXTRALIB)
24
25
26 INCLUDE=-I$(topbuilddir)/include -I. $(EXTRAINCLUDE) 
27 ARFLAGS=rcv
28 LDFLAGS=-r
29
30 ifdef SUBOBJ
31 SUBSYS=SUBSYS.o
32 endif 
33
34 ifdef SUBDIRS
35 SUBDIROBJS  := $(SUBDIRS:%=%/SUBSYS.o)
36 endif
37
38 .SUFFIXES: .o.c
39
40 .c.o:
41         $(CC) $(CFLAGS) $(INCLUDE) -c $<
42
43 all: $(SUBSYS) $(LIBRARY) $(PROGRAM)
44
45 define prog_dep
46  $(1): $$(PROGRAMOBJ_$(1))
47 endef
48
49 $(foreach prog,$(PROGRAM),$(eval $(call prog_dep,$(prog))))
50
51 ifdef PROGRAM
52 ifdef LIBRARY
53 $(PROGRAM): $(LIBRARY)
54 endif
55
56 $(PROGRAM): %: %.o 
57         $(CC) -o $@ $< $(PROGRAMOBJ_$(@)) $(LIBRARY) $(LIB) 
58 endif
59
60 ifdef LIBRARY
61 $(LIBRARY): $(LIBOBJ) $(SUBDIROBJS)
62         $(AR) $(ARFLAGS) $@ $(LIBOBJ) $(SUBDIROBJS) 
63         $(RANLIB) $@
64 endif
65
66 ifdef SUBOBJ
67 $(SUBSYS): $(SUBOBJ)
68         $(LD) $(LDFLAGS) -o $@ $(SUBOBJ)
69 endif
70
71 ifdef SUBDIRS
72 $(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ;
73
74 $(SUBDIRS:%=%-recursive):
75         $(MAKE) -C $(subst -recursive,,$@) -f Makefile OS=$(OS) SUBSYS.o
76 endif
77  
78 clean:
79 ifdef LIBOBJ
80         rm -rf $(LIBOBJ)
81 endif 
82 ifdef PROGRAM
83         rm -rf $(PROGRAM)
84         rm -rf $(foreach P, $(PROGRAM), $P.o $(PROGRAMOBJ_$(P)))
85         rm -rf *core core.*
86 endif
87 ifdef LIBRARY
88         rm -rf $(LIBRARY)
89 endif
90 ifdef SUBOBJ
91         rm -rf $(SUBOBJ) $(SUBSYS)
92 endif
93 ifdef SUBDIRS
94         for dir in $(SUBDIRS); do $(MAKE) -f Makefile -C $$dir OS=$(OS) clean || exit; done
95 endif