/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk

« back to all changes in this revision

Viewing changes to Makefile

  • Committer: edam
  • Date: 2009-03-05 13:40:53 UTC
  • Revision ID: edam@waxworlds.org-20090305134053-7afaeqithc87bwp2
Tags: 1.10
- combines sources in to one variable, SOURCES
- renamed switches to build static and shared lib to BUILDALIB and BUILDSOLIB
- fixed run goal
- added subdirs goal to phony list
- fix linking to use CXX, not CC

Show diffs side-by-side

added added

removed removed

1
 
#
2
 
# Target binary
3
 
#
4
 
TARGET          = simplecrypt
5
 
 
6
 
#
 
1
#                                          Edam's general-purpose makefile v1.10
 
2
#_______________________________________________________________________________
 
3
#                                                                S E T T I N G S
 
4
 
 
5
# Overridable options
 
6
# (better to specify these in environment/command line)
 
7
#export DEBUGMODE       := 1
 
8
#export STATICLIBS      := 1
 
9
 
 
10
# Target binary/library
 
11
#BUILDALIB      := 1
 
12
#BUILDSOLIB     := 1
 
13
TARGET          := tim.a
 
14
 
7
15
# All source files
8
 
#
9
 
CC_SRCS         = simplecrypt.cc
10
 
C_SRCS          = 
11
 
S_SRCS          = 
12
 
 
13
 
#
14
 
# Build flags
15
 
#
16
 
#CFLAGS=-g
17
 
#LDFLAGS=
18
 
 
19
 
 
20
 
#---------------------------------------------------------------------------
21
 
# Edam's makefile r1.02
22
 
 
23
 
# More variables...
24
 
DEPFILE         = Depends
25
 
SRCS            = $(C_SRCS) $(CC_SRCS) $(S_SRCS)
26
 
OBJS            = $(addsuffix .o,$(basename $(SRCS)))
27
 
 
28
 
# Main rule...
29
 
$(TARGET): $(OBJS)
30
 
        g++ -o $(TARGET) $(OBJS) $(LDFLAGS)
31
 
 
32
 
#---------------------------------------------------------------------------
33
 
 
34
 
.PHONY: all clean depend dep
35
 
 
36
 
all:    clean depend $(TARGET)
 
16
SOURCES         := tim.cc
 
17
 
 
18
# Libraries to link
 
19
LIBRARIES       := 
 
20
 
 
21
# Subdirectories to make
 
22
SUBDIRS         := 
 
23
 
 
24
# Software
 
25
AS              := nasm
 
26
CC              := gcc
 
27
CXX             := g++
 
28
 
 
29
# Flags
 
30
CPPFLAGS        := 
 
31
CFLAGS          := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
 
32
CXXFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
 
33
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2)
 
34
LDFLAGS         := -Wall $(if $(DEBUGMODE),,-s) $(if $(STATICLIBS), -static)
 
35
 
 
36
#_______________________________________________________________________________
 
37
 
 
38
DEPFILE         := depends.mk
 
39
OBJECTS         := $(addsuffix .o,$(basename $(SOURCES)))
 
40
LDLIBS          := $(addprefix -l,$(LIBRARIES))
 
41
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
 
42
TARGET          := $(TARGET)$(if $(BUILDALIB),.a,)$(if $(BUILDSOLIB),.so,)
 
43
 
 
44
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
 
45
 
 
46
all: subdirs target
 
47
 
 
48
subdirs: $(SUBDIRS)
 
49
 
 
50
target: $(TARGET)
37
51
 
38
52
clean:
39
 
        rm -f core $(DEPFILE) $(OBJS)
 
53
ifeq "$(MAKECMDGOALS)" "clean"
 
54
ifdef SUBDIRS
 
55
        @echo NOT RECURSING: Use \"make clean_all\" to clean subdirectoried as well...
 
56
endif
 
57
endif
 
58
        rm -f core $(DEPFILE) $(OBJECTS) $(TARGET)
40
59
        rm -f *~
41
60
 
42
 
depend dep:
43
 
        makedepend -f- -- $(CFLAGS) -- $(SRCS) > $(DEPFILE)
44
 
 
45
 
#---------------------------------------------------------------------------
46
 
#include $(DEPFILE)
 
61
clean_all: subdirs clean
 
62
 
 
63
ifndef BUILDALIB
 
64
ifndef BUILDSOLIB
 
65
run: target
 
66
        ./$(TARGET)
 
67
endif
 
68
endif
 
69
 
 
70
#depend dep:
 
71
#       makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
 
72
 
 
73
$(SUBDIRS):
 
74
        @$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
 
75
 
 
76
$(TARGET): $(OBJECTS)
 
77
ifdef BUILDALIB
 
78
        $(AR) rcs $(TARGET) $(OBJECTS)
 
79
else
 
80
        $(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
 
81
endif
 
82
 
 
83
#%.o:   %.c
 
84
#       $(CC) -c $(CPPFLAGS) $(CFLAGS)
 
85
#%.o:   %.cc
 
86
#       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
 
87
#%.o:   %.s
 
88
#       $(AS) $(ASFLAGS)
 
89
 
 
90
-include $(DEPFILE)
 
91
 
 
92
#_______________________________________________________________________________