Skip to content

Instantly share code, notes, and snippets.

@pwl
Created March 7, 2010 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwl/324411 to your computer and use it in GitHub Desktop.
Save pwl/324411 to your computer and use it in GitHub Desktop.
# #
# Makefile #
# #
#finds all .c files and replaces the .c with .o
OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c))
#finds all directories in this folder
DIRS = $(patsubst %/,%,$(wildcard */))
# default: $(OBJECTS)
.PHONY: clean $(DIRS) #$(OBJECTS)
project: $(DIRS) $(OBJECTS)
@ar rs $(ARCHIVE) $(OBJECTS)
@rm -f $(OBJECTS)
# compiles all the .c files into .o files
$(OBJECTS): %.o: %.c %.h
@echo "\033[1m$<\033[0m"
@$(CC) $(FLAGS) $(INCLUDES) -c -o $@ $<
# $(OBJECTS): %.o: %.c %.h
# echo "$(CC) $(FLAGS) $(INCLUDES) -c -o $@ $<"
# $(CC) $(FLAGS) $(INCLUDES) -c -o $@ $<
# OBJECTS are temporarly made .PHONY
# recursively make all subdirectories
$(DIRS):
@echo "\033[1;36m$(CURDIR)/$@\033[0m"
@$(MAKE) --no-print-directory -eC $@ project
clean:
@rm -f *.o *.a
@for d in $(DIRS); do $(MAKE) -eC "$${d}" $@; done
# #
# Makefile #
# #
export SHELL = /bin/bash
export CC = cc
export WFLAGS = -ansi -pedantic -Wall \
-Wshadow \
-Wmissing-prototypes -Wstrict-prototypes \
-Wpointer-arith -Wcast-qual -Wcast-align \
-Wwrite-strings -Wnested-externs \
-fshort-enums -fno-common -Dinline=
export CFLAGS = $(WFLAGS)
export OFLAGS = -O2 # left empty for debuggin reasons
export GDBFLAGS = -ggdb
export FLAGS = $(CFLAGS) $(OFLAGS) $(GDBFLAGS)
export LIBS = -lm -lgsl -lgslcblas # -lfftw3
export ARCHIVE = $(PWD)/libyapdes.a
export MAKEFILES = $(PWD)/Makefile.common
DIRS = $(patsubst %/,%,$(wildcard */))
export INCLUDES = $(patsubst %/, -I $(PWD)/%, $(wildcard */))
.PHONY : clean $(DIRS) projekty
project: CLEAR_AR $(DIRS)
test: project test.o $(DIRS)
$(CC) $(FLAGS) $(LIBS) $(INCLUDES) test.o $(ARCHIVE) -o $@
test.o: test.c test.h
$(CC) $(FLAGS) $(INCLUDES) -c -o $@ $<
CLEAR_AR:
@rm -f libyapdes.a
@ar rs libyapdes.a
$(DIRS):
@echo -e "\033[1;36m$(CURDIR)/$@\033[0m"
@$(MAKE) --no-print-directory -eC $@ project
clean:
@rm -f *.o libyapdes.a
@for d in $(DIRS); do $(MAKE) -eC "$${d}" $@; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment