aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
blob: bd98bf897ee979fa264513d7a0561d8403340899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 
# SETUP
#
# Points to the folder that contains pd's /src dir
PD_SRC = ../../../pd
# Points to the folder that contains pd's compiled /bin dir
PD_BIN = /Applications/Pd-extended.app/Contents/Resources
# Points to the folder to which you want to put the built file
OUTPUT = ~/Make/pd/tof



#
# FIND OS
#
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
  OS_NAME = linux
  EXTENSION = pd_linux
  DYLIB_EXTENSION = so
endif
ifeq ($(UNAME),Darwin)
  OS_NAME = darwin
  EXTENSION = pd_darwin
  DYLIB_EXTENSION = dylib
endif
ifeq (MINGW,$(findstring MINGW,$(UNAME)))
  OS_NAME = windows
  EXTENSION = dll
  DYLIB_EXTENSION = dll
endif
ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
  OS_NAME = windows
  EXTENSION = dll
  DYLIB_EXTENSION = dll
endif
# which CPU to compile for
UNAME_MACHINE := $(shell uname -m)
ifeq ($(UNAME_MACHINE),i386)
  ARCH = i386
endif
ifeq ($(UNAME_MACHINE),i686)
  ARCH = i386
endif
ifeq ($(UNAME_MACHINE),ppc)
  ARCH = powerpc
endif



# 
# COMPILE OPTIONS
#

CWD := $(shell pwd)


# turn on weak linking and dlopen support
export MACOSX_DEPLOYMENT_TARGET = 10.3

# DEFAULT TARGET # Find a way to list all c files target
ALL = $((patsubst %.c,%.o,$(wildcard *.c)))
default: $(ALL)

.SUFFIXES: .$(EXTENSION) .$(SHARED_LIB)


# this variable is to support old "win" directories, rather than "windows"
BUILDSRC_OS_NAME = $(OS_NAME)

CFLAGS = -DPD -I$(PD_SRC)/src -Wall -W $(DEBUG_CFLAGS)
LDFLAGS =  
LIBS = -lm

ifeq ($(OS_NAME),darwin)
# 10.4 Tiger
  FAT_FLAGS = -arch ppc -arch ppc64 -arch i386
# 10.5 Leopard
#  FAT_FLAGS = -arch ppc -arch ppc7400 -arch ppc64 -arch i386 -arch x86_64
  CFLAGS += -I/sw/include -DMACOSX -DUNIX -Dunix -DDL_OPEN -arch $(ARCH)
  LDFLAGS += -bundle -bundle_loader $(PD_BIN)/bin/pd -undefined dynamic_lookup \
		-L/sw/lib -weak_framework Carbon -arch $(ARCH)
  LIBS += -lc 
  DYLIB_LDFLAGS = -dynamiclib -undefined dynamic_lookup -read_only_relocs warning -L/sw/lib
  STRIP = strip -x
endif
ifeq ($(OS_NAME),linux)
  CFLAGS +=  -DUNIX -Dunix -DDL_OPEN -fPIC
  LDFLAGS += -Wl,--export-dynamic  -shared -fPIC
  LIBS += -lc
  DYLIB_LDFLAGS = $(LDFLAGS)
  STRIP = strip --strip-unneeded -R .note -R .comment
endif
ifeq ($(OS_NAME),windows)
  BUILDSRC_OS_NAME = win
  WINDOWS_HACKS = -D'O_NONBLOCK=1' -D'srand48(n)=srand((n))' \
    -D'drand48()=((double)rand()/RAND_MAX)' -D'bzero(p,n)=memset(p,0,n)'
# These don't seem to be needed:
#	-D'PROT_READ=1' \
#	-D'MAP_PRIVATE=2' \
#	-D'O_NDELAY=O_NONBLOCK'
  CFLAGS += -mms-bitfields -DMSW -DNT $(WINDOWS_HACKS)
  LDFLAGS += -s -shared
# all of these included libs are part of libc in UNIX platforms.  All except
# libregex are in DLLs, so they get stripped from the external's .dll binary
  LIBS += -L$(PD_SRC)/src -L$(PD_SRC)/bin -L$(PD_SRC)/obj -lpd \
    -lwsock32 -liphlpapi -lpthreadGC2 -lkernel32 -luser32 -lgdi32 -lregex
  DYLIB_LDFLAGS = -shared
  STRIP = strip --strip-unneeded -R .note -R .comment
endif

CXXFLAGS = $(CFLAGS)


### C files


.c:
	$(CC) $(OPT_CFLAGS) $(CFLAGS)  -o "$*.o" -c "$*.c"
	$(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o"  $(LIBS) 
	chmod a-x "$*.$(EXTENSION)"
	$(STRIP) $*.$(EXTENSION)
	rm -f -- $*.o
	mv $*.$(EXTENSION) $(OUTPUT)