leocad/Makefile

149 lines
3.5 KiB
Makefile
Raw Normal View History

2011-09-07 23:06:51 +02:00
### ALL CONFIGURATION SHOULD BE IN CONFIG.MK, NOT HERE
include config.mk
### Module directories
MODULES := $(OSDIR) common
2012-02-11 02:14:46 +01:00
### Look for include files in each of the modules
2011-09-07 23:06:51 +02:00
CPPFLAGS += $(patsubst %,-I%,$(MODULES)) $(OS)
CPPFLAGS += -g
2012-02-11 02:14:46 +01:00
### Extra libraries if required
2011-09-07 23:06:51 +02:00
LIBS :=
2012-02-11 02:14:46 +01:00
### Each module will add to this
2011-09-07 23:06:51 +02:00
SRC :=
BIN := bin/leocad
2012-02-11 02:14:46 +01:00
ifeq ($(findstring $(MAKECMDGOALS), help config-help config clean veryclean), )
2011-09-07 23:06:51 +02:00
-include $(OSDIR)/config.mk
2012-02-11 02:14:46 +01:00
endif
2011-09-07 23:06:51 +02:00
2012-02-11 02:14:46 +01:00
### Include the description for each module
2011-09-07 23:06:51 +02:00
include $(patsubst %,%/module.mk,$(MODULES))
2012-02-11 02:14:46 +01:00
### Determine the object files
2011-09-07 23:06:51 +02:00
OBJ := \
$(patsubst %.c,%.o,$(filter %.c,$(SRC))) \
$(patsubst %.cpp,%.o,$(filter %.cpp,$(SRC)))
2012-02-11 02:14:46 +01:00
### Link the program
2011-09-07 23:06:51 +02:00
.PHONY: all static
all: $(BIN)
static: bin/leocad.static
2012-02-11 02:14:46 +01:00
bin/leocad: $(OBJ) bin Makefile
@echo Linking $@
@$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
2011-09-07 23:06:51 +02:00
2012-02-11 02:14:46 +01:00
bin/leocad.static: $(OBJ) bin Makefile
2011-09-07 23:06:51 +02:00
$(CXX) -static -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
bin:
2012-02-11 02:14:46 +01:00
@mkdir bin
2011-09-07 23:06:51 +02:00
2012-02-11 02:14:46 +01:00
### Include the C/C++ include dependencies
ifeq ($(findstring $(MAKECMDGOALS), help config-help config clean veryclean), )
2011-09-07 23:06:51 +02:00
-include $(OBJ:.o=.d)
endif
2012-02-11 02:14:46 +01:00
### Calculate C/C++ include dependencies
%.d: %.cpp $(OSDIR)/config.h $(OSDIR)/config.mk
@$(CXX) -MM -MT '$(patsubst %.d,%.o, $@)' $(CXXFLAGS) $(CPPFLAGS) -w $< > $@
2011-09-07 23:06:51 +02:00
@[ -s $@ ] || rm -f $@
2012-02-11 02:14:46 +01:00
### Main compiler rule
%.o: %.cpp $(OSDIR)/config.h $(OSDIR)/config.mk
@echo $<
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o '$(patsubst %.cpp,%.o, $@)' $<
2011-09-07 23:06:51 +02:00
@[ -s $@ ] || rm -f $@
### Various cleaning functions
.PHONY: clean veryclean spotless all
clean:
find $(MODULES) -name \*.o | xargs rm -f
veryclean: clean
find $(MODULES) -name \*.d | xargs rm -f
rm -rf bin
rm -rf arch $(OSDIR)/config.mk $(OSDIR)/config.h
2012-02-11 02:14:46 +01:00
### Dependency stuff is done automatically, so these do nothing.
2011-09-07 23:06:51 +02:00
.PHONY: dep depend
### Help function
.PHONY: help
help:
@echo 'Possible Targets are:'
@echo ' help (this is it)'
@echo ' all'
@echo ' install'
@echo ' binary'
@echo ' source'
@echo ' (binary and source can be called as'
@echo ' a -zip or -tgz variants)'
@echo ' clean'
@echo ' veryclean'
@echo
### Rules to make various packaging
.PHONY: binary binary-tgz source-zip source-tgz source install
arch:
mkdir arch
install: $(BIN)
install -d $(DESTDIR)$(PREFIX)/bin
install -d $(DESTDIR)$(PREFIX)/share/man/man1
install -c -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin/
install -c -m 0644 docs/leocad.1 $(DESTDIR)$(PREFIX)/share/man/man1/
binary: binary-zip binary-tgz
binary-zip: arch/leocad-$(VERSION)-linux.zip
binary-tgz: arch/leocad-$(VERSION)-linux.tgz
source: source-tgz source-zip
source-tgz: arch/leocad-$(VERSION)-src.tgz
source-zip: arch/leocad-$(VERSION)-src.zip
### Create a directory with the files needed for a binary package
package-dir: arch all
mkdir leocad-$(VERSION)
cp bin/leocad leocad-$(VERSION)
cp CREDITS.txt leocad-$(VERSION)/CREDITS
cp README.txt leocad-$(VERSION)/README
cp docs/INSTALL.txt leocad-$(VERSION)/INSTALL
cp docs/LINUX.txt leocad-$(VERSION)/LINUX
cp docs/leocad.1 leocad-$(VERSION)
arch/leocad-$(VERSION)-linux.zip: package-dir
rm -f $@
zip -r $@ leocad-$(VERSION)
rm -rf leocad-$(VERSION)
arch/leocad-$(VERSION)-linux.tgz: package-dir
rm -f $@
tar -cvzf $@ leocad-$(VERSION)
rm -rf leocad-$(VERSION)
arch/leocad-$(VERSION)-src.tgz: arch veryclean
rm -f $@
( cd .. ; tar --exclude=leocad/arch/\* --exclude=CVS \
-cvzf leocad/$@ leocad )
arch/leocad-$(VERSION)-src.zip: arch veryclean
rm -f $@
( cd .. ; zip -r leocad/$@ leocad -x '*/arch/*' -x '*/CVS/*' -x '*~' -x '*/core' -x '*/.#*')