Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7 from stouset/rewrite-makefile

Rewrite makefile
  • Loading branch information...
commit 3137753086868826f4a6b370ea5220fe5104a9d2 2 parents 9118daa + 56b92f9
@capicue authored
Showing with 46 additions and 27 deletions.
  1. +3 −0  .gitignore
  2. +43 −27 Makefile
  3. 0  {src → bin}/plot.py
View
3  .gitignore
@@ -0,0 +1,3 @@
+bin/*
+plot/*
+src/*.o
View
70 Makefile
@@ -1,29 +1,45 @@
-SHELL = /bin/sh
-CFLAGS=-Wall -Wextra -Werror -Os --std=c99
-
-all: prob1 prob2 prob3
-
-prob1: prob1.c plot
- cc $(CFLAGS) prob1.c -o prob1
- # ./prob1 0.1 | ./plot
- ./prob1 0.1 | ./plot -f "(1 + x**2)**2" -o plot_1_1 --markersize=20
- ./prob1 0.05 | ./plot -f "(1 + x**2)**2" -o plot_1_2 --markersize=20
- ./prob1 0.025 | ./plot -f "(1 + x**2)**2" -o plot_1_3 --markersize=20
-
-prob2: prob2.c plot
- cc $(CFLAGS) prob2.c -o prob2
- ./prob2 0 0.1 | ./plot -o plot_2_1 -f "(1 + x**2)**2" --markersize=20
- ./prob2 0 0.05 | ./plot -o plot_2_2 -f "(1 + x**2)**2" --markersize=20
- ./prob2 0 0.025 | ./plot -o plot_2_3 -f "(1 + x**2)**2" --markersize=20
- ./prob2 -5 0.1 | ./plot -o plot_2_4 -f "(1 + x**2)**2" --xmax=2 --ymin="-15" --ymax="25" --markersize=20
- ./prob2 -5 0.05 | ./plot -o plot_2_5 -f "(1 + x**2)**2" --xmax=2 --ymin="-15" --ymax="25" --markersize=20
- ./prob2 -5 0.025 | ./plot -o plot_2_6 -f "(1 + x**2)**2" --xmax=2 --ymin="-15" --ymax="25" --markersize=20
-
-prob3: prob3.c plot
- cc $(CFLAGS) prob3.c -o prob3
- ./prob3 -f | ./plot -o plot_3_1 --markersize=1 --aspectratio=1
- ./prob3 -b | ./plot -o plot_3_2 --markersize=1 --aspectratio=1
- ./prob3 -t | ./plot -o plot_3_3 --markersize=1 --aspectratio=1
+PROGS := prob1 prob2
+SRCDIR := src
+BINDIR := bin
+PLOTDIR := plot
+
+SRCS := $(addprefix $(SRCDIR)/, $(addsuffix .c, $(PROGS)))
+OBJS := $(patsubst %.c, %.o, $(SRCS))
+BINS := $(addprefix $(BINDIR)/, $(PROGS))
+PLOTS := $(PLOTDIR)/*
+
+CC := /usr/bin/clang
+LD := /usr/bin/clang
+PLOT := $(BINDIR)/plot.py
+CFLAGS := -std=c99 -Wall -Wextra -Werror -g
+LDFLAGS :=
+PLOTFLAGS := --markersize=20 -f "(1 + x**2)**2"
+
+all: $(BINS)
+
+plots: $(BINS) $(PLOT) $(PLOTDIR)
+ $(BINDIR)/prob1 0.1 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_1_1
+ $(BINDIR)/prob1 0.05 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_1_2
+ $(BINDIR)/prob1 0.025 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_1_3
+ $(BINDIR)/prob2 0 0.1 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_1
+ $(BINDIR)/prob2 0 0.05 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_2
+ $(BINDIR)/prob2 0 0.025 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_3
+ $(BINDIR)/prob2 -5 0.1 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_4 --xmax=2 --ymin="-15" --ymax="25"
+ $(BINDIR)/prob2 -5 0.05 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_5 --xmax=2 --ymin="-15" --ymax="25"
+ $(BINDIR)/prob2 -5 0.025 | $(PLOT) $(PLOTFLAGS) -o $(PLOTDIR)/plot_2_6 --xmax=2 --ymin="-15" --ymax="25"
+
+$(BINS): $(BINDIR)/%: $(SRCDIR)/%.o
+ $(LD) $(LDFLAGS) -o $@ $<
+
+$(OBJS): $(SRCDIR)/%.o: $(SRCDIR)/%.c
+ $(CC) -c $(CFLAGS) -o $@ $<
+
+$(PLOTDIR):
+ mkdir $(PLOTDIR)
clean:
- rm prob1 prob2 prob3 *.png
+ rm -f $(OBJS)
+ rm -f $(BINS)
+ rm -f $(PLOTS)
+
+.PHONY: all plots clean
View
0  src/plot.py → bin/plot.py
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.