Skip to content

Instantly share code, notes, and snippets.

@ylogx
Last active August 29, 2015 14:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ylogx/d3b6fdfd83338e74a74a to your computer and use it in GitHub Desktop.
A makefile to compile all source code in a given folder
#########################################################################
#
# Makefile - This Makefile compiles all c files in given folder
# Copyright (c) 2014-2015 Shubham Chaudhary <me@shubhamchaudhary.in>
#
#########################################################################
#SPECIFIED_SRC_FILE = $(foreach d,$(SPECIFIED_SRC_DIRS),$(wildcard $(addprefix $(d)/*,*.c)))
#CC = gcc
#all:
# $(CC) -o .out lelemon.c -Wall
#SRCS=$(wildcard *.c)
#OBJS=(SRCS:.c=.o)
#all: $(OBJS)
CC = gcc
#CFLAGS = -g -O2 -std=gnu99 -static -Wall -Wextra -Isrc -rdynamic -fomit-frame-pointer
CFLAGS = -g -O2 -std=gnu99 -Wall -Wextra -Isrc -rdynamic -fomit-frame-pointer
#Tell make to make one .out file for each .cpp file found in the current directory
all: $(patsubst %.c, %.out, $(wildcard *.c))
#Rule how to create arbitary .out files.
#First state what is needed for them e.g. additional headers, .cpp files in an include folder...
#Then the command to create the .out file, probably you want to add further options to the g++ call.
%.out: %.c Makefile
-$(CC) $(CFLAGS) $< -o $@ -lm
# $(CC) $(CFLAGS) $< -o $@
clean:
rm *.out
rm -rf *.out.dSYM/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment