Thursday, September 13, 2007

Re: [BLUG] C/C++

#!/usr/bin/env make
# This should be called Makefile or makefile
# This simple makefile was released anonymously in to the public domain.
# Note: This isn't expected to work with GNU Make < 3.79 or other non-GNU makes

## Your list of sources
## *.c - C source code
## *.cpp / *.cxx / *.cc / *.c++ / *.C - C++ source code
SOURCES:=test.c

## The name of the executible
TARGET:=test

## Used to compile your C sources
CFLAGS:= -Wall
## Used to compile your C++ sources
CXXFLAGS:= -Wall
## Used to specify C preprocessor flags
# CPPFLAGS:= -DMY_VALUE="defined"
CPPFLAGS:=

## Used for the final link for the executible
# LDFLAGS:= -lm
LDFLAGS:=

# Any additional files you want to remove can go here
CLEANFILES:=

### Some customization flags

## How are capitalized extensions handled?
# Indicates whether the capitalized letter is 'normal' (C++, etc.),
# or the 'same' as the uncapitalized version.
CAPMODE:=normal

## The default target is what is run when no target is specified.
# Historically 'all' is the default target. In our case, 'all' is
# mapped to this DEFAULT_TARGET. Sane settings for this would be
# 'help' or 'build'.
DEFAULT_TARGET:=help

### Over-ride some settings provided by Make.

# We want to use GCC where possible
CC:=gcc
CXX:=gcc
# x86 Linux systems prefer gcc to be used as the linker
LD:=gcc

### End of user-servicable parts

# Now, do not let targets mess with our pseudo-targets
ifneq ($(filter-out /%,$(TARGET)),)
TARGET:=$(addprefix ./,$(TARGET))
endif

DEFAULT_TARGET:=$(strip $(DEFAULT_TARGET))
ifeq ($(DEFAULT_TARGET),)
DEFAULT_TARGET:=build
endif

all: $(DEFAULT_TARGET)
.PHONY: all build
build: $(TARGET)

.PHONY: help
help:
@echo "The following targets are available:"
@echo " help: this help message."
@echo " build: build the TARGET: $(TARGET)"
@echo " clean: clean the directory"
@echo " tar.gz: create a .tar.gz from current directory"
@echo " tar.bz2: create a .tar.bz2 from current directory"

OBJECTS:=$(addsuffix .o,$(basename $(SOURCES)))
CLEANFILES := $(wildcard $(addsuffix .d,$(basename $(SOURCES))) $(filter-out $(filter %.o, $(SOURCES)),$(OBJECTS)) $(CLEANFILES) $(TARGET))
.PHONY: clean
clean:
ifneq ($(CLEANFILES),)
$(RM) $(CLEANFILES)
endif

$(OBJECTS): $(filter-out %.d, $(MAKEFILE_LIST))

ifeq ($(notdir $(CC)),gcc)
# -MD or -MDD should provides us the .d dep files on demand
ifeq ($(filter -M%,$(CPPFLAGS)),)
CPPFLAGS:=$(CPPFLAGS) -MD
endif
endif # ... gcc

.PHONY: tar.gz tar.bz2

TAR_DIR=$(notdir $(shell pwd))
TAR_BASE=$(TAR_DIR)_$(shell date +'%Y-%m-%d_%H-%M').tar

tar.gz:
tar -zcvf ../$(strip $(TAR_BASE)).gz -C .. $(TAR_DIR)

tar.bz2:
tar -jcvf ../$(strip $(TAR_BASE)).bz2 -C .. $(TAR_DIR)

# Please note: We leave the dependancies mostly up to the built-ins

$(TARGET): $(OBJECTS)

ifeq ($(CAPMODE),same)
# Normally we let GCC auto-determine the type of source code. In this case
# we force the matter with "-x".
# Note: This is based on GNU Make 3.81 built-in logic. See make -p for more
%.o: %.C
$(COMPILE.c) -x c $(OUTPUT_OPTION) $<

endif

# -MD creates per-file dependancy files which we can include
# If you're not using GCC, then the dependancies will never be right unless
# you alter the makefile logic.
ifneq ($(filter clean, $(MAKECMDGOALS)),clean)
-include $(addsuffix .d,$(basename $(SOURCES)))
endif

# end of Makefile

On Wed, Sep 12, 2007 at 09:24:39PM -0400, Pawsitive Results wrote:
> What tool/tools would you suggest I start with, to follow along on the
> Linux side? I suspect I'll learn better, if I'm more able to mentally
> separate the task from the tools (if that makes sense).

Both Emacs and Vim have good syntax highlighting and overall development
support. Most people will be aware of the Emacs support, though the VIM
support is probably a little less well known. (Vim has a :make command,
which will work nicely if you have a Makefile.)

Speaking of Makefiles, they can be a bit intimidating. For starters, you
can use the attached simple makefile. You should check out the GNU Make
info documents for details.

Cheers,
Steven Black

2 comments:

Anonymous said...

Hello

Can I link to this post please?

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]free casino games[/url] coincide the latest [url=http://www.casinolasvegass.com/]casino games[/url] manumitted no consign reward at the chief [url=http://www.baywatchcasino.com/]www.baywatchcasino.com
[/url].