# makefile by mza # # this makefile does the following: # builds an object file for each c/cpp file in src/ # builds a library file containing all the object files from code in src/lib/ # builds an executable for each c/cpp file in src/ that's not in src/lib/ src_list_c := $(shell find src/ ! -wholename "src/lib/*" -name "*.c") src_list_cpp := $(shell find src/ ! -wholename "src/lib/*" -name "*.cpp") #src_list := $(src_list_c) $(src_list_cpp) lib_src_list := $(shell find src/lib/ -name "*.cpp") obj_list_cpp := $(src_list_cpp:src/%.cpp=work/%.o) obj_list_c := $(src_list_c:src/%.c=work/%.o) lib_obj_list := $(lib_src_list:src/lib/%.cpp=work/%.o) obj_list := $(obj_list_c) $(obj_list_cpp) $(lib_obj_list) list_c := $(shell find src/ -maxdepth 1 -iname "*.c" -printf "%P ") bin_list_c := $(list_c:%.c=bin/%) list_cpp := $(shell find src/ -maxdepth 1 -iname "*.cpp" -printf "%P ") bin_list_cpp := $(list_cpp:%.cpp=bin/%) bin_list := $(bin_list_c) $(bin_list_cpp) library := lib/libmza.a # -D_FILE_OFFSET_BITS=64 is to allow for files greater than 2GiB COMPILE_OPTIONS := -D_FILE_OFFSET_BITS=64 -Isrc/lib default : @if [ ! -e src ]; then mkdir src; fi @if [ ! -e src/lib ]; then mkdir src/lib; fi @if [ ! -e work ]; then mkdir work; fi @if [ ! -e lib ]; then mkdir lib; fi @if [ ! -e bin ]; then mkdir bin; fi @$(MAKE) --no-print-directory all work/%.o : src/lib/%.cpp src/lib/%.h ; g++ -o $@ -c $< $(COMPILE_OPTIONS) work/%.o : src/%.c ; gcc -o $@ -c $< $(COMPILE_OPTIONS) work/%.o : src/%.cpp ; g++ -o $@ -c $< $(COMPILE_OPTIONS) $(library) : $(lib_obj_list) ; @# ar turns a set of object files into a static library: ar -cq $@ $(lib_obj_list) bin/% : work/%.o ; gcc -o $@ $^ clean : ; rm -rf work bin lib all : $(obj_list) $(library) $(bin_list) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # only need to specify explicit rules here if there is a dependency on code in the library: bin/rpn : work/rpn.o $(library) ; g++ -o $@ $^